Chat Completions
OpenAI 兼容的聊天补全端点。所有支持 chat format 的模型(GPT、Claude、Gemini 等)都走这里。
请求
POST /v1/chat/completions
请求体
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
model | string | ✓ | 模型 ID,例如 gpt-4o、claude-sonnet-4-6 |
messages | array | ✓ | 对话历史,每条有 role 和 content |
stream | boolean | ✗ | 是否流式返回,默认 false |
temperature | number | ✗ | 0-2,越高越有创造性 |
max_tokens | integer | ✗ | 最大输出 token 数 |
tools | array | ✗ | Function calling 工具定义 |
示例
curl https://api.picklyone.com/v1/chat/completions \
-H "Authorization: Bearer pk_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{ "role": "system", "content": "你是一个友好的助手" },
{ "role": "user", "content": "北京今天天气怎么样?" }
],
"temperature": 0.7
}'
响应
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "我没法实时查天气..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 42,
"total_tokens": 67
}
}
流式响应
加上 "stream": true,返回会变成 SSE 格式,每个 chunk 是一个 JSON delta。
更多细节参考 OpenAI Chat Completions 官方文档。