跳转到主要内容
Responses API 是 OpenAI 更新的有状态对话 API。TokenLab 将此格式作为兼容模型的高级可选路径提供支持;除非你明确需要 Responses 特定行为,否则请将 POST /v1/chat/completions 作为默认的兼容 OpenAI 路由。

请求体

model
string
必填
要使用的模型 ID。可用选项请参见 Models
input
array
必填
由对话组成的输入项列表。每个项可以是:
  • message: 带有角色和内容的对话消息
  • function_call: 一个函数调用请求
  • function_call_output: 来自函数调用的输出
对于多模态输入,message.content 可以是普通字符串,也可以是内容块数组。对于支持图像的模型(例如 GPT-5.4 变体),请将图像作为 input_image 块传递,而不是将 URL 或 Base64 字符串直接嵌入普通文本中。示例内容块:
  • { "type": "input_text", "text": "Describe this image" }
  • { "type": "input_image", "image_url": "https://example.com/image.jpg" }
  • { "type": "input_image", "image_url": "data:image/png;base64,..." }
instructions
string
提供给模型的系统指令(等同于 system 消息)。
max_output_tokens
integer
生成的最大 token 数量。
temperature
number
默认值:"1"
采样温度,范围在 0 到 2 之间。
tools
array
模型可能调用的工具列表。对于使用默认图片工具模型,或显式设置 model: "gpt-image-2" 的 hosted image_generation 工具,TokenLab 会在转发请求前移除不支持的 input_fidelity,因为 GPT Image 2 已经以高保真处理图片输入。请不要对这个工具传入 background: "transparent";TokenLab 不会静默移除它,因为这会改变输出语义。
stream
boolean
默认值:"false"
如果为 true,则返回事件流。
previous_response_id
string
用于从某个先前响应继续对话的响应 ID。
store
boolean
默认值:"true"
是否存储响应以便后续检索。
metadata
object
附加到响应以用于跟踪的元数据。
text
object
文本生成的配置选项。text.format 的行为取决于所选模型和路由路径;并不保证在每个模型上都一致。
parallel_tool_calls
boolean
默认值:"true"
是否允许并行进行多个工具调用。
top_p
number
Nucleus 采样参数(0-1)。
reasoning
object
针对具备推理能力的模型(例如 GPT-5 系列变体)的推理配置。
  • effort (string): 推理努力级别(low, medium, high

响应

id
string
响应的唯一标识符。
object
string
始终为 response
created
integer
响应创建时的 Unix 时间戳。
output
array
模型生成的输出项列表。
usage
object
token 使用统计。
curl -X POST "https://api.tokenlab.sh/v1/responses" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": [
      {"type": "message", "role": "user", "content": "Hello!"}
    ],
    "max_output_tokens": 1000
  }'
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.tokenlab.sh/v1"
)

response = client.responses.create(
    model="gpt-4o",
    input=[
        {"type": "message", "role": "user", "content": "Hello!"}
    ],
    max_output_tokens=1000
)

print(response.output)
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'sk-your-api-key',
  baseURL: 'https://api.tokenlab.sh/v1'
});

const response = await client.responses.create({
  model: 'gpt-4o',
  input: [
    { type: 'message', role: 'user', content: 'Hello!' }
  ],
  max_output_tokens: 1000
});

console.log(response.output);
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    payload := map[string]interface{}{
        "model": "gpt-4o",
        "input": []map[string]interface{}{
            {"type": "message", "role": "user", "content": "Hello!"},
        },
        "max_output_tokens": 1000,
    }
    body, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", "https://api.tokenlab.sh/v1/responses", bytes.NewBuffer(body))
    req.Header.Set("Authorization", "Bearer sk-your-api-key")
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    var result map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&result)
    fmt.Println(result["output"])
}
<?php
$ch = curl_init('https://api.tokenlab.sh/v1/responses');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer sk-your-api-key'
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'model' => 'gpt-4o',
        'input' => [
            ['type' => 'message', 'role' => 'user', 'content' => 'Hello!']
        ],
        'max_output_tokens' => 1000
    ])
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
print_r($data['output']);
视觉输入示例
通过将图像放入 message.content 中作为 input_image 块来使用支持图像的模型。image_url 值可以是公开 URL 或 Base64 数据 URL。
{
  "model": "gpt-5.4",
  "input": [
    {
      "type": "message",
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "Please describe this image."
        },
        {
          "type": "input_image",
          "image_url": "https://example.com/demo.jpg"
        }
      ]
    }
  ]
}
{
  "model": "gpt-5.4",
  "input": [
    {
      "type": "message",
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "Please describe this image."
        },
        {
          "type": "input_image",
          "image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ..."
        }
      ]
    }
  ]
}
{
  "id": "resp_abc123",
  "object": "response",
  "created": 1706000000,
  "model": "gpt-4o",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {"type": "text", "text": "Hello! How can I help you today?"}
      ]
    }
  ],
  "usage": {
    "input_tokens": 10,
    "output_tokens": 12,
    "total_tokens": 22
  }
}