Appearance
Chat Completions
POST /v1/chat/completions
这是 OpenAI 兼容对话接口。OpenAI SDK、ChatBox、Cherry Studio、Cursor、Continue、Cline 等工具一般都走这个接口。
Base URL
text
https://portdan.com/v1API Key 原样使用,不加后缀。
非流式请求
bash
curl https://portdan.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{"role": "system", "content": "你是一个简洁的助手。"},
{"role": "user", "content": "用一句话介绍 Portdan。"}
],
"temperature": 0.7
}'响应示例
json
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1710000000,
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Portdan 是一个 Sub2 AI 模型网关。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 18,
"total_tokens": 38
}
}流式输出
bash
curl https://portdan.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"stream": true,
"messages": [
{"role": "user", "content": "请写 3 条 API 安全建议。"}
]
}'流式响应使用 Server-Sent Events。客户端需要逐段读取 data: 内容,遇到 [DONE] 结束。
常用参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名,以 /models 返回值为准 |
messages | array | 是 | 对话消息数组 |
temperature | number | 否 | 随机性,常见范围 0 到 2 |
top_p | number | 否 | nucleus sampling 参数 |
stream | boolean | 否 | 是否启用流式输出 |
max_tokens | number | 否 | 最大生成 token 数 |
tools | array | 否 | 工具调用定义,需模型支持 |
response_format | object | 否 | 结构化输出,需模型支持 |
工具调用示例
json
{
"model": "gpt-5.5",
"messages": [
{"role": "user", "content": "查询上海今天气温"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}
]
}WARNING
工具调用、视觉输入、JSON mode、长上下文等能力取决于具体模型和分组配置。接口兼容不等于所有模型能力完全一致。
和 Claude / Gemini 的区别
- Claude Code / Anthropic Messages 请看 Anthropic Messages。
- Gemini CLI / Google SDK 请看 Gemini v1beta。
- 不要通过 Key 后缀把 OpenAI Chat Completions 强行切到 Claude 或 Gemini。
