创建聊天对话
post/v1/chat/completions
根据对话历史创建模型响应。支持流式和非流式响应。
兼容 OpenAI Chat Completions API。
鉴权
把 OLETOKEN 的 API Key 作为 Bearer Token 放进 Authorization 请求头。密钥在控制台的「API 密钥」页创建。
Authorization: Bearer $OLETOKEN_API_KEY请求体
Content-Type:application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 模型 ID | |
| messages | Message[] | 对话消息列表 | |
| role | stringsystemuserassistanttooldeveloper | 消息角色 | |
| content | string | MessageContent[] | 消息内容 | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | 图片 URL 或 base64 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | Base64 编码的音频数据 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | 发送者名称 |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | 工具调用 ID(用于 tool 角色消息) |
| reasoning_content | string | — | 推理内容 |
| temperature | number0–2default: 1 | — | 采样温度 |
| top_p | number0–1default: 1 | — | 核采样参数 |
| n | integer≥ 1default: 1 | — | 生成数量 |
| stream | booleandefault: false | — | 是否流式响应 |
| stream_options | object | — | — |
| include_usage | boolean | — | — |
| stop | string | string[] | — | 停止序列 |
| max_tokens | integer | — | 最大生成 Token 数 |
| max_completion_tokens | integer | — | 最大补全 Token 数 |
| presence_penalty | number-2–2default: 0 | — | — |
| frequency_penalty | number-2–2default: 0 | — | — |
| logit_bias | object | — | — |
| user | string | — | — |
| tools | Tool[] | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| description | string | — | — |
| parameters | object | — | JSON Schema 格式的参数定义 |
| tool_choice | string | objectnoneautorequired | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| response_format | ResponseFormat | — | — |
| type | stringtextjson_objectjson_schema | — | — |
| json_schema | object | — | JSON Schema 定义 |
| seed | integer | — | — |
| reasoning_effort | stringlowmediumhigh | — | 推理强度 (用于支持推理的模型) |
| modalities | string[] | — | — |
| audio | object | — | — |
| voice | string | — | — |
| format | string | — | — |
响应
200成功创建响应
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | string | — | — |
| object | string | — | — |
| created | integer | — | — |
| model | string | — | — |
| choices | object[] | — | — |
| index | integer | — | — |
| message | Message | — | — |
| role | stringsystemuserassistanttooldeveloper | 消息角色 | |
| content | string | MessageContent[] | 消息内容 | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | 图片 URL 或 base64 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | Base64 编码的音频数据 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | 发送者名称 |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | 工具调用 ID(用于 tool 角色消息) |
| reasoning_content | string | — | 推理内容 |
| finish_reason | stringstoplengthtool_callscontent_filter | — | — |
| usage | Usage | — | — |
| prompt_tokens | integer | — | 提示词 Token 数 |
| completion_tokens | integer | — | 补全 Token 数 |
| total_tokens | integer | — | 总 Token 数 |
| prompt_tokens_details | object | — | — |
| cached_tokens | integer | — | — |
| text_tokens | integer | — | — |
| audio_tokens | integer | — | — |
| image_tokens | integer | — | — |
| completion_tokens_details | object | — | — |
| text_tokens | integer | — | — |
| audio_tokens | integer | — | — |
| reasoning_tokens | integer | — | — |
| system_fingerprint | string | — | — |
400请求参数错误
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| error | object | — | — |
| message | string | — | 错误信息 |
| type | string | — | 错误类型 |
| param | string | null | — | 相关参数 |
| code | string | null | — | 错误代码 |
429请求频率限制
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| error | object | — | — |
| message | string | — | 错误信息 |
| type | string | — | 错误类型 |
| param | string | null | — | 相关参数 |
| code | string | null | — | 错误代码 |
请求示例
curl -X POST 'https://api.oletoken.ai/v1/chat/completions' \
-H "Authorization: Bearer $OLETOKEN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4",
"messages": []
}'
