Skip to Content
WikiAPI 文档对话补全

创建对话请求(OpenAI)

为给定的对话创建模型响应。

端点

POST https://gateway.mytokengate.com/v1/chat/completions

请求示例

curl --request POST \ --url https://gateway.mytokengate.com/v1/chat/completions \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "gpt-4o", "messages": [ { "role": "user", "content": "中国大模型行业2025年将会迎来哪些机遇和挑战?" } ] }'

认证

所有请求需要在 Authorization 头中包含 Bearer token:

Authorization: Bearer YOUR_API_KEY

请求参数

参数类型必填说明
modelstring模型名称,详见模型列表
messagesarray对话消息列表
max_tokensinteger最大生成 token 数,需确保输入+输出不超过模型上下文窗口
streamboolean是否流式输出,true 时以 Server-Sent Events 返回,以 data: [DONE] 结束
temperaturefloat控制随机性,范围 0-2,默认值因模型而异
top_pfloat核采样参数,默认 0.7
top_kfloatTop-k 采样参数
frequency_penaltyfloat重复惩罚,范围 -2.0 到 2.0
stopstring 或 array最多 4 个停止序列,生成遇到这些序列时会停止
ninteger返回的完成数量,默认 1
response_formatobject指定输出格式,如 { "type": "json_object" }
toolsarray工具列表,最多 128 个函数

响应

{ "id": "chatcmpl-xxx", "choices": [ { "message": { "role": "assistant", "content": "响应内容...", "tool_calls": [ { "id": "call_xxx", "type": "function", "function": { "name": "function_name", "arguments": "{\"arg\": \"value\"}" } } ] }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 123, "completion_tokens": 456, "total_tokens": 579 }, "created": 1234567890, "model": "gpt-4o", "object": "chat.completion" }

错误码

状态码说明
400请求参数无效
401API Key 无效或缺失
404模型不存在
429触发限流
503/504服务暂时不可用
Last updated on