玄枢API

Chat Completions API

OpenAI Chat Completions 兼容请求与流式响应。

最后验证日期:

连接与鉴权

统一 OpenAI 兼容 Base URL: https://www.xuanshuapi.com/v1

OpenAI 兼容接口使用 Authorization: Bearer <YOUR_API_KEY>;Claude Messages 也支持 x-api-key: <YOUR_API_KEY>;Gemini v1beta 使用 x-goog-api-key: <YOUR_API_KEY>。

Chat Completions API

POST /v1/chat/completions 接受兼容消息结构;stream=true 时使用 SSE。

并非每个模型都支持相同参数,请先查询 Models。

请求体与调用

Chat Completions 使用 messages 数组,可设置 temperature,并通过 stream 启用 SSE。

curl https://www.xuanshuapi.com/v1/chat/completions \
  -H "Authorization: Bearer <YOUR_API_KEY>" -H "content-type: application/json" \
  -d '{"model":"<MODEL_FROM_MODELS>","messages":[{"role":"user","content":"Reply with OK"}],"temperature":0,"stream":false}'

响应与流式行为

非流式文本位于 choices[0].message.content;流式增量位于 choices[0].delta.content。

HTTP 200
{"object":"chat.completion","choices":[{"message":{"role":"assistant","content":"OK"},"finish_reason":"stop"}],"usage":{"prompt_tokens":12,"completion_tokens":1}}

关键参数

参数说明
model从 /v1/models 选择。
messages对话角色与内容。
temperature仅在目标模型支持时使用。
stream启用 SSE。

典型故障

400 检查模型是否支持参数;401/403 检查凭证和模型权限;429/5xx 使用有限退避。

HTTP 400  # model does not support a parameter
HTTP 401/403  # key or model access
HTTP 429/5xx  # bounded retry candidate

下一步

可用模型、倍率、配额及部分高级能力动态依赖当前 Key 与控制台配置。