API 参考

Chat Completions

POST/v1/chat/completions

主力端点:目录里所有对话模型的多轮对话、流式、工具调用、视觉与 JSON 模式都走这里。

#请求参数

  • modelstring必填

    来自 /v1/models 的模型 ID。网关据此解析上游厂商。

  • messagesarray必填

    对话轮次:{role: system|user|assistant|tool, content}。content 可以是字符串,也可以是多模态分段数组。

  • streamboolean可选

    为 true 时流式返回 SSE 增量,以 data: [DONE] 收尾。

  • temperaturenumber可选

    范围 0 到 2,留空使用模型默认值。

  • max_tokensinteger可选

    生成 token 上限;同时限定预留额度的估算。

  • toolsarray可选

    模型可调用的函数声明——见工具调用指南。

  • tool_choicestring | object可选

    "auto"、"none",或指定某个函数。

  • response_formatobject可选

    {"type":"json_object"} 或 json_schema 包装,在支持的模型上启用结构化输出。

  • top_pnumber可选

    核采样;temperature 和 top_p 二选一。

  • stopstring | array可选

    最多 4 个停止序列,命中即截断生成。

#相关错误码

  • 400 invalid_request_error请求体格式错误,或该模型不支持某个参数。
  • 401Bearer 令牌无效或缺失。这条路径不带 error.code,请按状态码判断。
  • 402 insufficient_user_quota钱包余额不足以覆盖预扣估算。
  • 429密钥级限流。响应体为空,按 Retry-After 等待。若 429 带有 insufficient_user_quota,那是每日消费上限,不是限流。
  • 503 model_not_found模型名不存在,或当前没有健康渠道可以服务它。

完整错误码表 →

#请求示例

curl https://www.aisplice.store/v1/chat/completions \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [{"role": "user", "content": "Say hello."}]
  }'

#响应

response.json
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "gpt-5.6-luna",
  "choices": [{
    "index": 0,
    "message": {"role": "assistant", "content": "Hello!"},
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 9, "completion_tokens": 3, "total_tokens": 12}
}

还是没解决?

把请求 ID 或报错信息发给我们,我们来查。