Chat Completions
OpenAI 风格的多轮对话端点,是绝大多数 SDK 与工具(OpenAI SDK、Cursor、Cline、Continue、Aider、自建应用)的默认选择。
POST https://api.ttttt.ai/v1/chat/completions
Authorization: Bearer owo-...
Content-Type: application/json协议字段、行为完全对齐 OpenAI 官方 Chat Completions 规范。本页只列与 ttttt.ai 相关的差异点;详细字段参考官方文档即可。
最小请求
curl https://api.ttttt.ai/v1/chat/completions \
-H "Authorization: Bearer owo-..." \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "用一句话解释黑洞。"}
]
}'关键请求字段
| 字段 | 类型 | 说明 |
|---|---|---|
model | string | 必填。模型 ID,例如 gpt-5.5 / gpt-5.4。完整清单见 模型 与 模型清单 |
messages | array | 必填。多轮对话历史,每条 {role, content} |
stream | boolean | 是否使用 SSE 流式;默认 false。详见 流式响应 |
temperature | number | 0–2,控制随机性 |
top_p | number | 0–1,nucleus sampling |
max_tokens | integer | 最大输出 token;不传则用模型默认 |
tools | array | Function calling / tool use 定义 |
tool_choice | string / object | 工具选择策略 |
response_format | object | 例如 { "type": "json_object" } 强制 JSON |
seed | integer | 复现性辅助(不保证 100% 一致) |
metadata | object | 透传到上游,便于追踪 |
ttttt.ai 不限制额外字段——任何 OpenAI 上游接受的参数(包括预览功能)都会原样转发。如果新参数生效,平台会随之更新文档。
响应
{
"id": "chatcmpl-018ff3a2",
"object": "chat.completion",
"created": 1718640000,
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "黑洞是引力强到连光也逃不掉的天体。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 17,
"total_tokens": 41,
"prompt_tokens_details": {
"cached_tokens": 0
}
}
}计费用到的字段
ttttt.ai 网关按下面三个字段入账:
usage.prompt_tokens— 计 inputusage.completion_tokens— 计 outputusage.prompt_tokens_details.cached_tokens— 计 cache_read
详见 计费模型 → 缓存计费。
Function Calling / Tools
完整透传。示例:
{
"model": "gpt-5.5",
"messages": [
{ "role": "user", "content": "上海今天多少度?" }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}响应里如果模型决定调用工具,会回 choices[0].message.tool_calls,按官方协议处理后再 follow-up 请求即可。
视觉输入(多模态)
支持视觉的模型按 OpenAI 多模态协议传图:
{
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "这张图里是什么?" },
{
"type": "image_url",
"image_url": { "url": "data:image/png;base64,..." }
}
]
}
]
}image_url.url 支持:
data:URI(base64 内嵌)https://远程 URL(上游需要能访问到)
每张图按 imagePerImage 单独计价(详见 计费模型)。
流式
{ "model": "gpt-5.5", "messages": [...], "stream": true }返回 text/event-stream,每个 chunk 是一段 data: {json}\n\n,最后一行是 data: [DONE]\n\n。
SDK 通常已经封装好;自己解析见 流式响应。
错误
返回 4xx / 5xx 时,body 是统一错误信封:
{
"error": {
"message": "model 'gpt-x' not found",
"type": "not_found",
"code": 404
}
}详见 错误码与重试。
与 Anthropic Messages 的差异
| 维度 | Chat Completions | Messages (Anthropic) |
|---|---|---|
| 端点 | /v1/chat/completions | /v1/messages |
| 鉴权 Header | Authorization: Bearer | x-api-key |
| 顶层字段 | messages[] | messages[] + system 字符串 |
| 流式格式 | data: {choices: [{delta: ...}]} | event: content_block_delta\ndata: {...} |
| Tool 调用结构 | tool_calls[] | content[{type: "tool_use"}] |
如果你的上游模型是 Claude 系列,建议直接用 Messages 接口——少一层翻译开销,也能用上 Claude 特有字段(system、stop_sequences、etc.)。
Last updated on