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

# Sub2API Responses API 接口说明

> 了解如何通过 Sub2API 使用 OpenAI Responses API 格式，以及它与 Chat Completions API 的区别。

Sub2API 提供对 OpenAI Responses API 格式的完整支持。Responses API 是 OpenAI 推出的新一代有状态(stateful) API，与 Chat Completions API 相比，它内置了多轮对话上下文管理，更适用于需要持续对话状态的应用场景。

## 接口端点

**POST** `https://sub2api.ruilinlu.com/v1/responses`

<Note>
  TODO: 请在后台确认实际配置后填写正确的端点路径。
</Note>

## 最小请求示例

```json theme={null}
{
  "model": "gpt-4o",
  "input": "Hello!"
}
```

## 请求格式

Responses API 使用 `input` 字段代替 Chat Completions 中的 `messages` 字段，支持字符串或结构化输入:

<Tabs>
  <Tab title="字符串输入">
    ```json theme={null}
    {
      "model": "gpt-4o",
      "input": "请写一篇关于人工智能的短文"
    }
    ```
  </Tab>

  <Tab title="结构化输入">
    ```json theme={null}
    {
      "model": "gpt-4o",
      "input": [
        {
          "role": "user",
          "content": "请写一篇关于人工智能的短文"
        }
      ]
    }
    ```
  </Tab>
</Tabs>

## 响应结构

```json theme={null}
{
  "id": "resp_xxx",
  "object": "response",
  "created": 1712345678,
  "model": "gpt-4o",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "人工智能(AI)是计算机科学的一个重要分支..."
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 15,
    "output_tokens": 200,
    "total_tokens": 215
  }
}
```

## 代码示例

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://sub2api.ruilinlu.com/v1/responses \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -d '{
      "model": "gpt-4o",
      "input": "Hello!"
    }'
  ```

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

  client = OpenAI(
      base_url="https://sub2api.ruilinlu.com/v1",
      api_key="YOUR_API_KEY"
  )

  response = client.responses.create(
      model="gpt-4o",
      input="Hello!"
  )

  print(response.output[0].content[0].text)
  ```
</CodeGroup>

## Responses API 与 Chat Completions API 的区别

| 特性     | Responses API  | Chat Completions API |
| ------ | -------------- | -------------------- |
| 对话状态管理 | 内置有状态(自动维护)    | 无状态(需手动传递 messages)  |
| 输入字段   | `input`        | `messages`           |
| 输出字段   | `output`       | `choices`            |
| 使用场景   | 多轮对话工具调用、Agent | 单次问答、简单对话            |

## 重要提示

<Warning>
  如果您的客户端或应用仅支持 Chat Completions 格式，请使用 [Chat Completions API](/api/chat-completions) 代替。不是所有的第三方工具都已升级到支持 Responses API。
</Warning>

## 相关接口

* [Chat Completions API](/api/chat-completions) - 传统的 OpenAI 兼容聊天接口
* [Models - Claude](/models/claude) - 可用的 Claude 模型列表
* [Models - Gemini](/models/gemini) - 可用的 Gemini 模型列表
