Gateway Protocols多标准协议兼容
OpenAIAnthropicGeminiOpenRouter
Chat / Responses / Messages / Claude MessagesPOST /v1/chat/completions
对话 Chat API
OpenAI Chat Completions 兼容接口,请求体按 model + messages 形态提交;支持同步 JSON 与 SSE 流式返回。
接口信息
输入参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | Portal 发布的模型编码;对应火山引擎方舟文档中的 Model ID / Endpoint ID 概念,由 Gateway 负责映射到上游。 |
messages | object[] | 是 | 消息列表;不同模型支持文本、图片、视频、音频等不同模态。 |
messages[].role | string | 是 | system / user / assistant / tool;按所选模型和上游能力透传。 |
messages[].content | string | object[] | 是 | 消息内容。纯文本可传 string;多模态按内容块数组传入。 |
messages[].content[].type | string | 多模态时 | 内容块类型,例如 text、image_url、input_audio、video_url、file。 |
messages[].content[].text | string | 文本块 | 文本内容。 |
messages[].content[].image_url | object | 图片块 | 图片 URL 或 Base64,以及 detail、image_pixel_limit 等上游支持字段。 |
stream | boolean | null | 否 | 是否启用 SSE 流式返回。false 时一次性返回 JSON;true 时按 data: chunk 返回,并以 data: [DONE] 结束。 |
stream_options.include_usage | boolean | null | 否 | 流式响应中是否额外返回整次请求的 token 用量统计。 |
thinking | object | 否 | 火山引擎方舟扩展:控制支持模型的深度思考模式,例如 { "type": "enabled" }。 |
temperature | number | null | 否 | 采样温度。 |
top_p | number | null | 否 | 核采样概率阈值;通常建议只调整 temperature 或 top_p 之一。 |
max_tokens | integer | null | 否 | 最大输出 token 数。 |
max_completion_tokens | integer | null | 否 | 部分模型支持的最大生成 token 数;不要与 max_tokens 同时设置。 |
stop | string | string[] | null | 否 | 停止词,最多 4 个字符串。 |
frequency_penalty / presence_penalty | number | null | 否 | 重复惩罚与话题惩罚。 |
tools / tool_choice | object[] / string / object | 否 | 函数调用工具定义与工具选择策略;是否生效取决于模型能力。 |
response_format | object | 否 | 输出格式控制,例如 { "type": "json_object" } 或 json_schema。 |
service_tier | string | null | 否 | 火山引擎方舟服务等级字段;Gateway 会按线路能力透传。 |
输出参数
| 参数 | 类型 | 返回 | 说明 |
|---|---|---|---|
id | string | 是 | 响应 ID。 |
object | string | 是 | 通常为 chat.completion。 |
created | integer | 否 | 上游创建时间戳。 |
model | string | 否 | 实际响应的模型编码。 |
service_tier | string | 否 | 上游返回的服务等级。 |
choices | object[] | 是 | 模型输出候选。 |
choices[].index | integer | 是 | 候选下标。 |
choices[].message.role | string | 非流式 | 通常为 assistant。 |
choices[].message.content | string | null | 非流式 | 助手最终回复文本。 |
choices[].message.reasoning_content | string | null | 推理模型 | 推理模型可能返回的思考内容字段。 |
choices[].delta | object | 流式 | 流式响应 chunk 中的增量内容,可能包含 content、reasoning_content、tool_calls 等。 |
choices[].finish_reason | string | null | 否 | 停止原因,例如 stop、length、tool_calls。 |
choices[].logprobs | object | null | 否 | 开启 logprobs 时的 token 概率信息。 |
usage.prompt_tokens | integer | 否 | 输入 token 数。 |
usage.completion_tokens | integer | 否 | 输出 token 数。 |
usage.total_tokens | integer | 否 | 总 token 数。 |
usage.prompt_tokens_details | object | 否 | 缓存、音频等输入 token 明细。 |
usage.completion_tokens_details | object | 否 | 推理 token 等输出 token 明细。 |
补充说明
- 4SToken 对外标准入口为 POST /v1/chat/completions;如存量火山兼容接入仍使用 /api/v3/chat/completions,可继续按线路能力兼容。
- 请求中的 model 请填写模型列表页展示的 modelCode,Gateway 会按线路映射到上游 Model ID / Endpoint ID。
- stream=true 时响应 Content-Type 为 text/event-stream,每个 chunk 以 data: 开头,末尾为 data: [DONE];如需 usage,请传 stream_options.include_usage=true。
- 多模态内容块、thinking、service_tier、reasoning_content、logprobs 等字段会按上游能力透传;不支持的模型可能忽略或返回参数错误。
错误代码
| HTTP 状态码 | 错误 | 说明 |
|---|---|---|
400 | Bad Request | 参数格式错误、模型不支持该字段或模型未配置 chat.completions 线路。 |
401 | Unauthorized | Client Key 无效或未提供。 |
402 | Payment Required | Client Key 配额或消费限额超限。 |
在线调试
user message对话用户消息 content
curl -X POST 'https://api.4stoken.cn/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
--data-raw '{"model":"your-model-code","messages":[{"role":"system","content":"你是人工智能助手"},{"role":"user","content":"Hello"}],"max_tokens":1024,"stream":false}'
# 4SToken 对外标准入口:POST /v1/chat/completions
# model 填 Portal 模型列表展示的 modelCode,Gateway 会映射到上游 Model ID / Endpoint ID在线调试会向 Gateway 发起真实请求并可能产生费用。请确认参数无误后再点击。

