跳转到主要内容
POST
/
api
/
v1
/
responses
curl --request POST \
  --url https://api.crun.ai/api/v1/responses \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-5.4",
  "instructions": "You are a concise product copywriter.",
  "input": "Write a one-sentence launch caption for a noise-canceling headset.",
  "temperature": 0.7
}
'
{
  "id": "resp_abc123",
  "object": "response",
  "created_at": 1772294400,
  "status": "completed",
  "model": "gpt-5.4",
  "output": [
    {
      "id": "msg_abc123",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Launch focus anywhere with a headset that quiets distractions and keeps calls crisp."
        }
      ]
    }
  ],
  "output_text": "Launch focus anywhere with a headset that quiets distractions and keeps calls crisp.",
  "usage": {
    "input_tokens": 18,
    "output_tokens": 14,
    "total_tokens": 32
  }
}

API 地址

POST https://api.crun.ai/api/v1/responses
Responses API 是 OpenAI 更新的模型接口,适用于文本与图像输入、文本输出、有状态追问、结构化输出和工具调用工作流。 该接口遵循 OpenAI Responses 的请求和响应格式。 您可以直接搭配官方 OpenAI SDK,或其他 OpenAI 兼容客户端使用。

身份验证

您可以使用以下任一方式进行身份验证:
  • Authorization: Bearer YOUR_API_KEY
  • X-API-KEY: YOUR_API_KEY

何时使用 Responses

适合使用 /responses 的场景:
  • 希望使用顶层 instructions,而不是 system message。
  • 需要字符串或 message-like items 列表形式的灵活 input
  • 上游模型支持存储响应时,希望通过 previous_response_id 做有状态追问。
  • 希望通过 text.format 获取结构化输出。
  • 希望使用工具就绪的 response items,以及 tools / tool_choice 字段。
如果您需要现有聊天集成中的经典 messages -> choices[] -> message 结构,请使用 /chat/completions

基本文本生成

curl -X POST "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "instructions": "You are a concise product copywriter.",
    "input": "Write a one-sentence launch caption for a noise-canceling headset.",
    "temperature": 0.7
  }'

Message 风格输入

input 也可以传入 message-like items 列表,便于从 Chat Completions 迁移。
curl -X POST "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Explain prompt caching in two short bullet points."
      }
    ]
  }'

图片输入

当所选模型支持视觉能力时,可以在 content 数组中使用 type: "input_image" 传入图片。图片可以是公开 URL、Base64 data URL。
curl -X POST "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "Describe this image in one paragraph."
          },
          {
            "type": "input_image",
            "image_url": "https://example.com/product-photo.jpg"
          }
        ]
      }
    ]
  }'

文件输入

对于 PDF 和其他上游模型支持的已上传文件,请先上传文件,再作为 input_file content part 传入。
curl -X POST "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "what is in this file?"
          },
          {
            "type": "input_file",
            "file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf"
          }
        ]
      }
    ]
  }'

有状态追问

当上游模型支持存储响应时,可以设置 store=true,并在下一次请求中传入 previous_response_id,无需重新发送全部上下文。
curl -X POST "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Give me three naming ideas for a developer newsletter.",
    "store": true
  }'

curl -X POST "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Make the names more playful.",
    "previous_response_id": "resp_abc123",
    "store": true
  }'

结构化输出

Responses 使用 text.format 配置结构化输出。这与 Chat Completions 的 response_format 不同。
curl -X POST "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Extract a task from: Maya should send the launch brief by Friday.",
    "text": {
      "format": {
        "type": "json_schema",
        "name": "task",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {
            "owner": { "type": "string" },
            "task": { "type": "string" },
            "due": { "type": "string" }
          },
          "required": ["owner", "task", "due"],
          "additionalProperties": false
        }
      }
    }
  }'

工具就绪请求

OpenAI Responses API 支持内置工具和函数式工具。CRUN 会接受兼容的 toolstool_choice 字段,并在所选上游模型支持时透传。
request body
{
  "model": "gpt-5.4",
  "input": "Search my connected knowledge base and summarize our refund policy.",
  "tools": [
    {
      "type": "file_search",
      "vector_store_ids": ["vs_123"]
    }
  ],
  "tool_choice": "auto"
}

流式输出

设置 stream=true 后,可以从 /responses 接收 Server-Sent Events。每个事件包含一行 event:,以及紧随其后的 JSON data: 载荷。
curl -N "https://api.crun.ai/api/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "instructions": "You are a concise assistant.",
    "input": "Write a three-step checklist for reviewing an API integration.",
    "stream": true
  }'

响应示例

{
  "id": "resp_abc123",
  "object": "response",
  "created_at": 1772294400,
  "status": "completed",
  "model": "gpt-5.4",
  "output": [
    {
      "id": "msg_abc123",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Launch focus anywhere with a headset that quiets distractions and keeps calls crisp."
        }
      ]
    }
  ],
  "output_text": "Launch focus anywhere with a headset that quiets distractions and keeps calls crisp.",
  "usage": {
    "input_tokens": 18,
    "output_tokens": 14,
    "total_tokens": 32
  }
}

注意事项

  • max_output_tokens 会受所选模型的输出 token 上限约束。
  • 其他 OpenAI 兼容字段也会被接受,并在上游模型支持时透传。
  • 图片输入使用 input_image content parts。文件输入使用带有上传 file_urlinput_file content parts。
  • 结构化输出使用 text.format;Chat Completions 使用 response_format
  • 工具可用性取决于所选模型和上游服务商。
  • 未知模型 ID 会返回 OpenAI 风格的错误体,其中 code"model_not_found"

相关资源

LLM 快速开始

了解 base URL、身份验证方式以及官方 SDK 的接入模式。

Chat Completions API

为现有聊天客户端使用经典 messages 与 choices API。

价格

前往价格页面,比较不同模型的计费规则。

授权

Authorization
string
header
必填

将您的 CRUN API Key 作为 Bearer token,用于 OpenAI 兼容 SDK。

请求体

application/json

OpenAI 兼容 Responses 请求。其他兼容字段会被接受,并在上游模型支持时透传。

model
string
必填

GET /api/v1/models 返回的公开模型 ID。

Required string length: 1 - 128
示例:

"gpt-5.4"

input

模型输入。可以是字符串,也可以是 response input items 列表;支持文本、图片和文件 content parts,具体能力取决于所选模型和上游服务。

示例:

"Write a one-sentence launch caption for a noise-canceling headset."

instructions

发送给模型的系统或开发者指令。

示例:

"You are a concise product copywriter."

stream
boolean
默认值:false

是否返回 Server-Sent Events 流。

示例:

false

store
boolean

上游服务支持时,是否存储响应以便进行有状态追问。

示例:

true

previous_response_id
string

上游服务支持时,用于继续对话的上一轮已存储响应 ID。

示例:

"resp_abc123"

metadata
object

开发者自定义元数据。

max_output_tokens
integer

最大输出 token 数,会受所选模型限制。

必填范围: x >= 1
示例:

512

temperature
number

采样温度。

必填范围: 0 <= x <= 2
示例:

0.7

top_p
number

核采样参数。

必填范围: 0 <= x <= 1
示例:

1

user
string

用于观测的终端用户标识。

示例:

"user_123"

prompt_cache_key
string

上游服务支持时传入的提示词缓存键。

prompt_cache_retention
enum<string>

上游服务支持时的提示词缓存保留策略。

可用选项:
in-memory,
24h
reasoning
object

推理模型配置。

示例:
{ "effort": "medium" }
text
object

文本输出配置。Responses API 使用 text.format 配置结构化输出。

示例:
{ "format": { "type": "json_object" } }
tools
object[]

OpenAI 兼容 Responses 格式的工具定义。

tool_choice

工具选择策略。

示例:

"auto"

parallel_tool_calls
boolean

上游服务支持时,是否允许并行工具调用。

示例:

true

truncation
string

上游服务支持时的上下文截断策略。

示例:

"auto"

响应

成功响应。stream=false 时返回 JSON,stream=true 时返回 SSE。

id
string
示例:

"resp_abc123"

object
string
示例:

"response"

created_at
integer

Unix 秒级时间戳。

示例:

1772294400

status
string
示例:

"completed"

model
string

客户端请求的公开模型 ID。

示例:

"gpt-5.4"

output
object[]
output_text
string

上游服务提供时返回的便捷文本字段。

示例:

"Launch focus anywhere with a headset that quiets distractions and keeps calls crisp."

usage
object