> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyone.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /v1/responses — OpenAI Responses API

> 使用 OpenAI Responses API 格式发送请求，支持内置工具和多轮对话。

`/v1/responses` 端点实现了 OpenAI 的 Responses API 格式——一种比 Chat Completions 更新的替代方案，专为多轮上下文管理设计。你无需每次请求都发送完整对话历史，只需通过 ID 引用上一个响应，让 API 自动管理上下文。Anyone 将这些请求转发到支持 Responses 格式的上游渠道；并非所有模型和渠道都支持此端点，使用前请确认你的渠道支持。

## 端点

| 方法     | 路径                      | 说明           |
| ------ | ----------------------- | ------------ |
| `POST` | `/v1/responses`         | 创建模型响应       |
| `POST` | `/v1/responses/compact` | 创建响应并压缩对话上下文 |

## 认证

```
Authorization: Bearer YOUR_TOKEN
```

## 与 Chat Completions 的区别

Chat Completions 格式（`/v1/chat/completions`）要求每次请求发送完整对话历史。Responses 格式在服务端管理上下文：你发送 `previous_response_id`，API 自动检索之前的上下文。`/v1/responses/compact` 变体在处理前还会压缩对话历史，为长对话节省 token 用量。

<Note>
  并非所有上游渠道都支持 Responses 格式。如果收到 `503` 错误，说明该模型的渠道不支持此端点。请改用 `/v1/chat/completions`。
</Note>

## 请求参数

<ParamField body="model" type="string" required>
  要使用的模型标识符。Anyone 将请求路由到该模型对应的上游渠道。
</ParamField>

<ParamField body="input" type="string | object[]" required>
  模型的输入。可以是字符串或带 `type` 字段的结构化输入部分数组（`input_text`、`input_image`、`input_file`）。
</ParamField>

<ParamField body="instructions" type="string | object">
  系统级指令，等同于 Chat Completions 中的 `system` 消息。
</ParamField>

<ParamField body="previous_response_id" type="string">
  之前响应的 ID。设置后模型使用该响应的上下文作为对话历史，无需重新发送完整消息列表。
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  设为 `true` 时，响应以 SSE 流式返回。
</ParamField>

<ParamField body="stream_options" type="object">
  仅在 `stream` 为 `true` 时生效的选项。

  <Expandable title="stream_options 属性">
    <ParamField body="stream_options.include_usage" type="boolean" default="false">
      设为 `true` 时，最后一个 SSE 块中包含 `usage` 字段（token 用量统计）。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="temperature" type="number">
  采样温度，范围 `0` 到 `2`。
</ParamField>

<ParamField body="top_p" type="number">
  核采样概率质量，取值 `0` 到 `1`。
</ParamField>

<ParamField body="max_output_tokens" type="integer">
  响应中模型可生成的最大 token 数量。
</ParamField>

<ParamField body="reasoning" type="object">
  控制支持推理的模型的推理行为。

  <Expandable title="reasoning 属性">
    <ParamField body="reasoning.effort" type="string">
      推理强度：`"low"`、`"medium"` 或 `"high"`。
    </ParamField>

    <ParamField body="reasoning.summary" type="string">
      是否在响应中包含推理摘要。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tools" type="object[]">
  模型可用的工具。支持函数工具和 MCP 风格的工具配置。
</ParamField>

<ParamField body="tool_choice" type="string | object" default="auto">
  控制模型如何选择工具。`"none"`、`"auto"`、`"required"` 或指定函数对象。
</ParamField>

<ParamField body="truncation" type="string | object">
  控制模型如何处理超出上下文窗口的内容。传 `"auto"` 由模型决定。
</ParamField>

<ParamField body="context_management" type="object">
  高级上下文管理选项，包括 `/v1/responses/compact` 端点的压缩策略设置。
</ParamField>

<ParamField body="metadata" type="object">
  附加到响应的键值元数据。值必须为字符串，最多 16 对。
</ParamField>

<ParamField body="top_logprobs" type="integer">
  在每个位置返回最可能的 token 数量及其对数概率。取值 `0` 到 `20`。
</ParamField>

<ParamField body="max_tool_calls" type="integer">
  模型在单次响应中可发起的最大 tool calling 次数。
</ParamField>

## 示例

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.anyone.ai/v1/responses \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-5.4",
      "input": "Summarize the concept of entropy in thermodynamics.",
      "instructions": "You are a physics professor. Keep explanations concise."
    }'
  ```

  ```python Python (openai SDK) theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_TOKEN",
      base_url="https://api.anyone.ai/v1",
  )

  response = client.responses.create(
      model="gpt-5.4",
      input="Summarize the concept of entropy in thermodynamics.",
      instructions="You are a physics professor. Keep explanations concise.",
  )

  print(response.output_text)
  ```

  ```javascript JavaScript (openai SDK) theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: "YOUR_TOKEN",
    baseURL: "https://api.anyone.ai/v1",
  });

  const response = await client.responses.create({
    model: "gpt-5.4",
    input: "Summarize the concept of entropy in thermodynamics.",
    instructions: "You are a physics professor. Keep explanations concise.",
  });

  console.log(response.output_text);
  ```
</CodeGroup>

**使用 `previous_response_id` 的多轮对话：**

```bash cURL theme={null}
# 第一轮
curl https://api.anyone.ai/v1/responses \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "What is the speed of light?"
  }'

# 第二轮——通过 ID 引用第一个响应
curl https://api.anyone.ai/v1/responses \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "How does that relate to Einstein'\''s theory of relativity?",
    "previous_response_id": "resp_abc123"
  }'
```

**对话压缩：**

```bash cURL theme={null}
curl https://api.anyone.ai/v1/responses/compact \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Continue our discussion.",
    "previous_response_id": "resp_abc123"
  }'
```

`/v1/responses/compact` 端点在生成下一个响应前压缩之前的对话上下文，为长多轮会话节省 token 用量。
