Appearance
Chat Completion(对话补全)
接口:POST /v1/chat/completions
💡 核心原则:本平台所有文本模型(GPT、Claude、Gemini、DeepSeek、Qwen 等)均通过统一的 OpenAI Chat Completion 格式调用。你只需更换
model字段即可切换不同模型,无需适配各家原生 API 格式。
统一调用示例
无论调用哪个模型,请求格式完全一致:
json
{
"model": "gpt-4o", // ← 只需更换这里
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你好"}
]
}切换模型时只需改 model 字段:
json
{"model": "claude-3-5-sonnet-20241022"} // Claude
{"model": "gemini-2.0-flash"} // Gemini
{"model": "deepseek-chat"} // DeepSeek
{"model": "qwen-max"} // Qwen所有模型返回的响应格式也完全一致,均为 OpenAI Chat Completion 响应结构。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✅ | 模型名称,通过 GET /v1/models 查询可用模型 |
messages | array | ✅ | 消息列表,见下方 Message 结构 |
temperature | float | ❌ | 采样温度,0~2,默认 1。越高越随机 |
top_p | float | ❌ | 核采样概率,0~1,默认 1 |
max_tokens | uint | ❌ | 生成的最大 Token 数(旧版参数) |
max_completion_tokens | uint | ❌ | 生成的最大 Token 数(新版参数,优先级高于 max_tokens) |
stream | bool | ❌ | 是否流式返回,默认 false |
stream_options | object | ❌ | 流式选项,{"include_usage": true} 可在流式末尾返回用量统计 |
stop | string/array | ❌ | 生成停止标记 |
n | int | ❌ | 生成几条回复,默认 1 |
frequency_penalty | float | ❌ | 频率惩罚,-2~2,默认 0 |
presence_penalty | float | ❌ | 存在惩罚,-2~2,默认 0 |
response_format | object | ❌ | 输出格式约束,如 {"type": "json_object"} |
seed | float | ❌ | 随机种子,用于可重复输出 |
tools | array | ❌ | 工具调用定义 |
tool_choice | string/object | ❌ | 工具调用策略:none/auto/required/指定工具 |
reasoning_effort | string | ❌ | 推理力度:low/medium/high(适用于推理模型) |
user | string | ❌ | 用户标识 |
⚠️ 不同模型对参数的支持范围可能不同。例如 Claude 不支持
frequency_penalty,部分推理模型不支持temperature。平台会自动忽略目标模型不支持的参数,你无需手动剔除。
Message 结构
json
{
"role": "system | user | assistant | tool",
"content": "文本内容 或 多模态内容数组"
}多模态 content(支持图片/音频/视频)
json
{
"role": "user",
"content": [
{"type": "text", "text": "这张图片里有什么?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg", "detail": "high"}},
{"type": "input_audio", "input_audio": {"data": "base64编码音频", "format": "wav"}},
{"type": "video_url", "video_url": {"url": "https://example.com/video.mp4"}}
]
}非流式响应
json
{
"id": "chatcmpl-xxxx",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我是 AI 助手……"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 50,
"total_tokens": 70
}
}流式响应(SSE)
每个 chunk 格式:
data: {"id":"chatcmpl-xxxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"好"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]若请求设置了 stream_options.include_usage: true,最后一个 chunk 会包含 usage 统计。
Tool Call 示例
json
{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "北京今天天气怎么样?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定城市的天气",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "城市名"}
},
"required": ["city"]
}
}
}
]
}进阶:原生格式接口
如果你已有基于 Claude 或 Gemini 原生 SDK 的代码,平台也支持直接透传原生格式请求,无需改写代码。
Claude 原生格式
接口:POST /v1/messages
请求需附带 Claude 特定 Header,系统会自动识别并走 Claude 适配器:
x-api-key: sk-xxxxxxxxxx
anthropic-version: 2023-06-01json
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "你好"}
]
}Gemini 原生格式
接口:POST /v1beta/models/{model}:{action}
常见 action:generateContent、streamGenerateContent、embedContent
认证方式:
- URL 参数:
?key=sk-xxxxxxxxxx - Header:
x-goog-api-key: sk-xxxxxxxxxx