对话 / 文本

OpenAI 协议(GPT)

OpenAI Chat Completions / Responses 兼容。用于 GPT 系列,以及 DeepSeek、GLM 等模型。

接口地址

用途方法路径
对话(REST + SSE)POST/v1/chat/completions
Codex(Responses)POST/v1/responses
模型列表GET/v1/models

认证

Authorization: Bearer <API_KEY>
Content-Type: application/json

支持的模型

gpt-*(如 gpt-4o)、deepseek-*、glm-*(如 glm-5.2)等。具体以 GET /v1/models 为准。

请求参数

参数类型必填说明
modelstring必填模型名,如 gpt-4o
messagesarray必填对话消息(role/content)
streambooleantrue 走 SSE;建议带 stream_options.include_usage=true 以拿到 usage
temperature / top_pnumber采样控制
max_tokens / max_completion_tokensinteger最大输出
tools / tool_choice工具调用

流式请求(SSE)

加 "stream": true 与 "stream_options": {"include_usage": true},用 curl -N 接收 SSE。事件 data: {chunk},末尾 data: [DONE];usage 在含 usage 的最终 chunk。

请求示例

非流式

curl -X POST "https://api.cqtai.com/v1/chat/completions" \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role":"user","content":"你好,介绍一下你自己"}]
  }'

流式(SSE,带 usage)

curl -N -X POST "https://api.cqtai.com/v1/chat/completions" \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "stream": true,
    "stream_options": {"include_usage": true},
    "messages": [{"role":"user","content":"写一首关于夏天的短诗"}]
  }'

响应示例

{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "model": "gpt-4o",
  "choices": [
    { "index": 0, "message": { "role": "assistant", "content": "你好!……" }, "finish_reason": "stop" }
  ],
  "usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 }
}

计费与积分

按 Token 计费:输入 token × 输入单价 + 输出 token × 输出单价(缓存创建 ×1.25、缓存读取 ×0.1),再乘以你的费率。count_tokens 仅预估、不计费。单价见「介绍」页模型列表。