Skip to content

GPT 模型接口文档 ​

兼容 OpenAI Chat Completions 与 Responses 接口,支持 GPT 系列模型的普通消息、流式输出、工具调用、有状态对话与图像生成。模型列表请到官网模型广场查询。

Base URL:https://api.agentpivot.ai/


登录平台 ​


接口概览 ​

方法路径说明
POST/v1/chat/completions消息接口(普通 / 流式 / 工具调用)
POST/v1/responses新一代响应接口(有状态 / 内置工具 / 结构化输出)
GET/v1/responses/{id}获取响应详情
DELETE/v1/responses/{id}删除响应
GET/v1/responses/{id}/input_items列出输入项
POST/v1/responses/{id}/cancel取消响应
POST/v1/images/generations图像生成
POST/v1/images/edits图像编辑 / 图生图

鉴权 ​

二选一:

Header说明
x-api-key: <API_KEY>使用 API Key
Authorization: Bearer <token>使用 JWT 或 Bearer Token

一、POST /v1/chat/completions ​

请求参数 ​

字段类型必填说明
modelstring是模型标识,如 gpt-5.4、gpt-4o
messagesarray是对话消息列表
max_tokensnumber否回复最大 token 数
temperaturenumber否采样温度 0~2,默认 1 5.5之后取消
top_pnumber否核采样 0~1,默认 1
streamboolean否true 时返回 SSE 流
toolsarray否工具定义,触发工具调用
tool_choicestring/object否auto、none、required

行为说明:

  • stream=true 返回 SSE,以 data: [DONE] 结束
  • tools 非空时可能返回 tool_calls,需将工具结果作为 role: tool 消息回传
  • 其余为普通 JSON 响应

响应示例 ​

json
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "model": "gpt-5.4",
  "choices": [{
    "index": 0,
    "message": {"role": "assistant", "content": "I'm doing well!"},
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 12, "completion_tokens": 10, "total_tokens": 22}
}

工具调用响应中 finish_reason: "tool_calls",message.tool_calls 包含函数名与参数。

请求示例 ​

1. 普通消息 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/chat/completions" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello, how are you?"}
    ],
    "max_tokens": 1024,
    "temperature": 0.7
  }'

2. 流式 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/chat/completions" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello"}],
    "stream": true
  }'

3. 工具调用 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/chat/completions" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "今天北京天气怎么样?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "获取指定城市的当前天气",
        "parameters": {
          "type": "object",
          "properties": {"location": {"type": "string"}},
          "required": ["location"]
        }
      }
    }],
    "tool_choice": "auto"
  }'

4. 图像生成 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/images/generations" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "画一只在草地上奔跑的金毛犬",
    "size": "1024x1024"
  }'

5. 在线图生图 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/images/edits" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "images": [{"image_url": "https://images.unsplash.com/photo-1506744038136-46273834b3fb"}],
    "prompt": "Change the sky to black"
  }'

6. 本地图生图 ​

bash
curl https://api.agentpivot.ai/v1/images/edits \
  -H "x-api-key: $API_KEY" \
  -F "model=gpt-image-2" \
  -F "image=@1.png" \
  -F "prompt=将天空改为蓝色"

二、POST /v1/responses ​

新一代响应接口,相比 /v1/chat/completions 提供有状态对话、内置工具、结构化输出等增强能力,推荐用于复杂 Agent 应用。

核心特性 ​

  • ✅ 有状态对话(previous_response_id)
  • ✅ 内置工具(Web 搜索 / 文件搜索 / 代码解释器)
  • ✅ 多模态输入(文本 / 图像 / 文件)
  • ✅ 结构化输出(JSON Schema)
  • ✅ 流式响应(细粒度 SSE 事件)
  • ✅ 自定义函数调用

请求参数 ​

字段类型必填说明
modelstring是模型标识
inputstring / array是输入内容
instructionsstring否系统指令
previous_response_idstring否上一次响应 ID,用于多轮
toolsarray否可用工具列表
tool_choicestring / object否auto / none / required
temperaturenumber否0~2
top_pnumber否0~1
max_output_tokensinteger否最大输出 token
streamboolean否是否启用 SSE 流
storeboolean否是否存储(默认 true)
textobject否输出格式(如 JSON Schema)
reasoningobject否推理配置(o1 系列)
metadataobject否自定义元数据

响应结构 ​

json
{
  "id": "resp_abc123",
  "object": "response",
  "status": "completed",
  "model": "gpt-4o",
  "output": [{
    "type": "message",
    "role": "assistant",
    "content": [{"type": "output_text", "text": "回复内容"}]
  }],
  "output_text": "回复内容",
  "usage": {"input_tokens": 20, "output_tokens": 50, "total_tokens": 70},
  "previous_response_id": null
}
  • status:completed / in_progress / failed / incomplete
  • output_text:便捷字段,直接获取文本

流式事件类型 ​

事件说明
response.created响应创建
response.output_text.delta文本增量
response.output_text.done文本完成
response.function_call_arguments.delta函数参数增量
response.completed响应完成
response.failed / error错误

请求示例 ​

1. 基础调用 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "你好,介绍一下你自己"
  }'

2. 带系统指令 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "instructions": "你是一个专业的技术顾问,回答简洁准确",
    "input": "什么是 REST API?"
  }'

3. 多轮对话(previous_response_id) ​

bash
# 第一轮
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4o", "input": "我叫小明"}'

# 第二轮
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "我叫什么名字?",
    "previous_response_id": "resp_abc123"
  }'

4. 流式响应 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "gpt-4o",
    "input": "讲一个长故事",
    "stream": true
  }'

5. 自定义函数调用 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "北京今天天气怎么样?",
    "tools": [{
      "type": "function",
      "name": "get_weather",
      "description": "获取指定城市的天气信息",
      "parameters": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
      }
    }],
    "tool_choice": "auto"
  }'

回传函数执行结果:

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "previous_response_id": "resp_abc123",
    "input": [{
      "type": "function_call_output",
      "call_id": "call_xyz789",
      "output": "{\"temperature\": 22, \"condition\": \"晴\"}"
    }]
  }'

6. 内置工具 ​

bash
# Web 搜索
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "今天有什么科技新闻?",
    "tools": [{"type": "web_search"}]
  }'

# 文件搜索
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "总结这份文档",
    "tools": [{"type": "file_search", "vector_store_ids": ["vs_abc123"]}]
  }'

# 代码解释器
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "计算 1 到 100 的素数之和",
    "tools": [{"type": "code_interpreter", "container": {"type": "auto"}}]
  }'

7. 结构化输出(JSON Schema) ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "提取信息:张三,25岁,工程师,住在上海",
    "text": {
      "format": {
        "type": "json_schema",
        "name": "person_info",
        "schema": {
          "type": "object",
          "properties": {
            "name": {"type": "string"},
            "age": {"type": "integer"},
            "occupation": {"type": "string"},
            "city": {"type": "string"}
          },
          "required": ["name", "age", "occupation", "city"],
          "additionalProperties": false
        },
        "strict": true
      }
    }
  }'

8. 多模态 - 图像输入 ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": [{
      "role": "user",
      "content": [
        {"type": "input_text", "text": "这张图里有什么?"},
        {"type": "input_image", "image_url": "https://example.com/image.jpg"}
      ]
    }]
  }'

9. 推理模型(o1) ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "o1",
    "input": "证明勾股定理",
    "reasoning": {"effort": "high"}
  }'

effort:low / medium / high

10. 隐私模式(不存储) ​

bash
curl -X POST "https://api.agentpivot.ai/v1/responses" \
  -H "x-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "敏感问题",
    "store": false
  }'

响应管理 ​

bash
# 获取响应详情
curl -X GET "https://api.agentpivot.ai/v1/responses/resp_abc123" \
  -H "x-api-key: $API_KEY"

# 删除响应
curl -X DELETE "https://api.agentpivot.ai/v1/responses/resp_abc123" \
  -H "x-api-key: $API_KEY"

# 列出输入项
curl -X GET "https://api.agentpivot.ai/v1/responses/resp_abc123/input_items" \
  -H "x-api-key: $API_KEY"

# 取消进行中的响应
curl -X POST "https://api.agentpivot.ai/v1/responses/resp_abc123/cancel" \
  -H "x-api-key: $API_KEY"