# OpenAI Response Format (Responses)

> Official docs: [Create a model response (API reference)](https://developers.openai.com/api/reference/resources/responses/methods/create) · [Streaming events](https://developers.openai.com/api/reference/resources/responses/streaming-events) · [Migrate to Responses](https://developers.openai.com/api/docs/guides/migrate-to-responses)

## 📝 Introduction

The Responses API is the interface OpenAI recommends for all new projects (Chat Completions remains supported). A single endpoint covers text, image, and file input; text or JSON output; function calling; built-in tools (web search, file search, code interpreter, and more); reasoning controls; and multi-turn conversations. Coding agents such as Codex CLI use this endpoint too and can connect to BeeRoute directly.

- **Base URL**: `https://beeroute.ai/v1`; this page covers `POST https://beeroute.ai/v1/responses`
- **Authentication**: header `Authorization: Bearer $API_KEY`; keys look like `sk-xxx` and are created on the [API keys page](https://beeroute.ai/keys)
- **Models and prices**: see the [pricing page](https://beeroute.ai/modellist/)

Before running the curl examples on this page, set your key in the terminal:

```bash
export API_KEY=sk-xxx
```

?> OpenAI models (such as `gpt-5.6-terra` and `gpt-5.6-sol`) support this endpoint natively. Other models (such as `claude-sonnet-5-5` and `glm-5.3`) can also be called in Responses format through BeeRoute format conversion, but OpenAI built-in tools (`web_search`, `file_search`, `code_interpreter`, `image_generation`, `computer`, remote `mcp`, and so on) only work when the upstream is OpenAI.

!> Features that depend on upstream storage, such as `previous_response_id`, `store`, and `conversation`, depend on the upstream channel that actually serves the request and are not available for every model. The most reliable way to hold a multi-turn conversation is to resend the full history on every request (see the example below).

## 💡 Request Examples

The response examples below only illustrate the structure. Some fields are omitted, and IDs and token counts are placeholders; the actual API output is authoritative.

### Basic Text ✅

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": "Tell me a three-sentence bedtime story about a unicorn."
  }'
```

**Example response:**

```json
{
  "id": "resp_68a1f2c3d4e5f6a7b8c9d0e1f2a3b4c5",
  "object": "response",
  "created_at": 1795766400,
  "status": "completed",
  "completed_at": 1795766403,
  "error": null,
  "incomplete_details": null,
  "instructions": null,
  "max_output_tokens": null,
  "model": "gpt-5.6-terra",
  "output": [
    {
      "type": "reasoning",
      "id": "rs_68a1f2c41a2b3c4d5e6f7a8b9c0d1e2f",
      "summary": [],
      "encrypted_content": "gAAAAABo...(truncated)"
    },
    {
      "type": "message",
      "id": "msg_68a1f2c55b6c7d8e9f0a1b2c3d4e5f6a",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Under a silver moon, a little unicorn named Luna found a lake that reflected every star in the sky. When she dipped her horn into the water, a glowing path appeared that led up into the night. She made a wish for every child still dreaming, then followed her sparkling hoofprints home to bed.",
          "annotations": [],
          "logprobs": []
        }
      ]
    }
  ],
  "parallel_tool_calls": true,
  "previous_response_id": null,
  "reasoning": {
    "effort": "medium",
    "summary": null
  },
  "store": true,
  "temperature": 1.0,
  "text": {
    "format": {
      "type": "text"
    },
    "verbosity": "medium"
  },
  "tool_choice": "auto",
  "tools": [],
  "top_p": 1.0,
  "truncation": "disabled",
  "usage": {
    "input_tokens": 21,
    "input_tokens_details": {
      "cached_tokens": 0,
      "cache_write_tokens": 0
    },
    "output_tokens": 156,
    "output_tokens_details": {
      "reasoning_tokens": 64
    },
    "total_tokens": 177
  },
  "user": null,
  "metadata": {}
}
```

?> Do not assume `output[0]` is the answer: reasoning models usually return a `reasoning` item before the `message` item. Iterate over `output` and read `output_text` from the item whose `type` is `message`.

### System Instructions (instructions) ✅

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "instructions": "You are a concise technical assistant. Keep every answer under 50 words.",
    "input": "What is idempotency in HTTP?"
  }'
```

`instructions` works like a system (developer) message inserted at the start of the context. The response has the same structure as the basic text example. When used with `previous_response_id`, the previous turn's `instructions` are not carried over, so pass them again on every request.

### Image Input ✅

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": [
      {
        "role": "user",
        "content": [
          {"type": "input_text", "text": "Describe what is in this image."},
          {
            "type": "input_image",
            "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
            "detail": "auto"
          }
        ]
      }
    ]
  }'
```

`image_url` can be a public URL or a base64 data URL (for example `data:image/png;base64,...`). BeeRoute does not provide a Files upload endpoint, so `file_id` can only reference files that already exist in the upstream account; use `image_url` in most cases.

### Streaming ✅

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": "Hello!",
    "stream": true
  }'
```

**Example stream** (SSE; the `response` objects are trimmed for readability, and lines starting with `:` are SSE comments):

```text
event: response.created
data: {"type":"response.created","sequence_number":0,"response":{"id":"resp_68a1f3d0e1f2a3b4c5d6e7f8a9b0c1d2","object":"response","created_at":1795766400,"status":"in_progress","model":"gpt-5.6-terra","output":[],"usage":null}}

event: response.in_progress
data: {"type":"response.in_progress","sequence_number":1,"response":{"id":"resp_68a1f3d0e1f2a3b4c5d6e7f8a9b0c1d2","object":"response","created_at":1795766400,"status":"in_progress","model":"gpt-5.6-terra","output":[],"usage":null}}

event: response.output_item.added
data: {"type":"response.output_item.added","sequence_number":2,"output_index":0,"item":{"id":"rs_68a1f3d11a2b3c4d5e6f7a8b9c0d1e2f","type":"reasoning","summary":[]}}

event: response.output_item.done
data: {"type":"response.output_item.done","sequence_number":3,"output_index":0,"item":{"id":"rs_68a1f3d11a2b3c4d5e6f7a8b9c0d1e2f","type":"reasoning","summary":[],"encrypted_content":"gAAAAABo..."}}

event: response.output_item.added
data: {"type":"response.output_item.added","sequence_number":4,"output_index":1,"item":{"id":"msg_68a1f3d25b6c7d8e9f0a1b2c3d4e5f6a","type":"message","status":"in_progress","role":"assistant","content":[]}}

event: response.content_part.added
data: {"type":"response.content_part.added","sequence_number":5,"item_id":"msg_68a1f3d25b6c7d8e9f0a1b2c3d4e5f6a","output_index":1,"content_index":0,"part":{"type":"output_text","text":"","annotations":[],"logprobs":[]}}

event: response.output_text.delta
data: {"type":"response.output_text.delta","sequence_number":6,"item_id":"msg_68a1f3d25b6c7d8e9f0a1b2c3d4e5f6a","output_index":1,"content_index":0,"delta":"Hello!","logprobs":[]}

: intermediate delta events omitted

event: response.output_text.done
data: {"type":"response.output_text.done","sequence_number":9,"item_id":"msg_68a1f3d25b6c7d8e9f0a1b2c3d4e5f6a","output_index":1,"content_index":0,"text":"Hello! How can I help you today?","logprobs":[]}

event: response.content_part.done
data: {"type":"response.content_part.done","sequence_number":10,"item_id":"msg_68a1f3d25b6c7d8e9f0a1b2c3d4e5f6a","output_index":1,"content_index":0,"part":{"type":"output_text","text":"Hello! How can I help you today?","annotations":[],"logprobs":[]}}

event: response.output_item.done
data: {"type":"response.output_item.done","sequence_number":11,"output_index":1,"item":{"id":"msg_68a1f3d25b6c7d8e9f0a1b2c3d4e5f6a","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Hello! How can I help you today?","annotations":[],"logprobs":[]}]}}

event: response.completed
data: {"type":"response.completed","sequence_number":12,"response":{"id":"resp_68a1f3d0e1f2a3b4c5d6e7f8a9b0c1d2","object":"response","created_at":1795766400,"status":"completed","model":"gpt-5.6-terra","output":[{"id":"rs_68a1f3d11a2b3c4d5e6f7a8b9c0d1e2f","type":"reasoning","summary":[],"encrypted_content":"gAAAAABo..."},{"id":"msg_68a1f3d25b6c7d8e9f0a1b2c3d4e5f6a","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Hello! How can I help you today?","annotations":[],"logprobs":[]}]}],"usage":{"input_tokens":12,"input_tokens_details":{"cached_tokens":0,"cache_write_tokens":0},"output_tokens":28,"output_tokens_details":{"reasoning_tokens":16},"total_tokens":40}}}
```

Every event carries an increasing `sequence_number`. The stream ends with a `response.completed` event (or `response.incomplete` / `response.failed`). See "Streaming Events" below for the full list.

### Function Calling ✅

**Step 1:** Declare the tool; the model returns a `function_call`.

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": "What is the weather like in Shanghai today?",
    "tools": [
      {
        "type": "function",
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {"type": "string", "description": "City name, e.g. Shanghai"},
            "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
          },
          "required": ["city", "unit"],
          "additionalProperties": false
        },
        "strict": true
      }
    ],
    "tool_choice": "auto"
  }'
```

**Example response (excerpt):**

```json
{
  "id": "resp_68a1f4e0a1b2c3d4e5f6a7b8c9d0e1f2",
  "object": "response",
  "status": "completed",
  "model": "gpt-5.6-terra",
  "output": [
    {
      "type": "reasoning",
      "id": "rs_68a1f4e11a2b3c4d5e6f7a8b9c0d1e2f",
      "summary": [],
      "encrypted_content": "gAAAAABo...(truncated)"
    },
    {
      "type": "function_call",
      "id": "fc_68a1f4e25b6c7d8e9f0a1b2c3d4e5f6a",
      "call_id": "call_Q8xH2kLm3nP4",
      "name": "get_weather",
      "arguments": "{\"city\":\"Shanghai\",\"unit\":\"celsius\"}",
      "status": "completed"
    }
  ]
}
```

**Step 2:** Run the function in your code, then send the call and its result back in `input` (the `call_id` of `function_call_output` must match the one the model returned):

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": [
      {"role": "user", "content": "What is the weather like in Shanghai today?"},
      {
        "type": "function_call",
        "call_id": "call_Q8xH2kLm3nP4",
        "name": "get_weather",
        "arguments": "{\"city\":\"Shanghai\",\"unit\":\"celsius\"}"
      },
      {
        "type": "function_call_output",
        "call_id": "call_Q8xH2kLm3nP4",
        "output": "{\"temperature\":18,\"condition\":\"cloudy\"}"
      }
    ],
    "tools": [
      {
        "type": "function", "name": "get_weather", "description": "Get the current weather for a city", "strict": true,
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string", "description": "City name, e.g. Shanghai"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}},
          "required": ["city", "unit"], "additionalProperties": false
        }
      }
    ]
  }'
```

The model then returns the final answer based on the function result (a `message` item).

?> The officially recommended approach is to append **every item** from the step 1 `output` (including the `reasoning` item and its `encrypted_content`) to `input` unchanged, which preserves the reasoning context. For brevity, the example only sends back the `function_call` without its `id`; if you send back items that carry an `id`, include the `reasoning` item that precedes them as well. A single response may contain several `function_call` items, and each one needs its own `function_call_output`.

### Structured Output ✅

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": "Extract the event: Alice and Bob will review the release plan in meeting room 3 at 3 PM on Friday.",
    "text": {
      "format": {
        "type": "json_schema",
        "name": "calendar_event",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {
            "title": {"type": "string"},
            "time": {"type": "string"},
            "participants": {"type": "array", "items": {"type": "string"}}
          },
          "required": ["title", "time", "participants"],
          "additionalProperties": false
        }
      }
    }
  }'
```

**Example response (the `message` item in `output`):**

```json
{
  "type": "message",
  "id": "msg_68a1f5a05b6c7d8e9f0a1b2c3d4e5f6a",
  "status": "completed",
  "role": "assistant",
  "content": [
    {
      "type": "output_text",
      "text": "{\"title\":\"Release plan review\",\"time\":\"Friday 15:00\",\"participants\":[\"Alice\",\"Bob\"]}",
      "annotations": [],
      "logprobs": []
    }
  ]
}
```

`output_text.text` is a JSON string that matches the schema; parse it yourself. If the model refuses for safety reasons, `content` contains a `refusal` part instead of JSON.

### Reasoning ✅

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": "A three-digit number has digits that sum to 14. The hundreds digit is 2 more than the units digit, and the tens digit is twice the units digit. What is the number?",
    "reasoning": {
      "effort": "high",
      "summary": "auto"
    }
  }'
```

**Example response (excerpt):**

```json
{
  "id": "resp_68a1f6b0a1b2c3d4e5f6a7b8c9d0e1f2",
  "object": "response",
  "status": "completed",
  "model": "gpt-5.6-terra",
  "output": [
    {
      "type": "reasoning",
      "id": "rs_68a1f6b11a2b3c4d5e6f7a8b9c0d1e2f",
      "summary": [
        {
          "type": "summary_text",
          "text": "**Setting up the equations**\n\nLet the units digit be x, so the hundreds digit is x+2 and the tens digit is 2x. From (x+2)+2x+x=14 we get x=3, so the digits are 5, 6 and 3."
        }
      ],
      "encrypted_content": "gAAAAABo...(truncated)"
    },
    {
      "type": "message",
      "id": "msg_68a1f6b25b6c7d8e9f0a1b2c3d4e5f6a",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "The number is 563. Check: 5+6+3=14, 5 is 2 more than 3, and 6 is twice 3.",
          "annotations": [],
          "logprobs": []
        }
      ]
    }
  ],
  "reasoning": {
    "effort": "high",
    "summary": "auto"
  },
  "usage": {
    "input_tokens": 52,
    "input_tokens_details": {
      "cached_tokens": 0,
      "cache_write_tokens": 0
    },
    "output_tokens": 612,
    "output_tokens_details": {
      "reasoning_tokens": 548
    },
    "total_tokens": 664
  }
}
```

The supported `reasoning.effort` values and the default depend on the model. Reasoning summaries are only returned when `reasoning.summary` is set. `output_tokens` already includes `reasoning_tokens`, and reasoning tokens are billed as output.

### Web Search ✅

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": "According to the official OpenAI docs, what is the default value of the store parameter in the Responses API? Cite your source.",
    "tools": [
      {
        "type": "web_search",
        "filters": {"allowed_domains": ["developers.openai.com"]},
        "search_context_size": "medium",
        "user_location": {"type": "approximate", "country": "US", "timezone": "America/Los_Angeles"}
      }
    ],
    "include": ["web_search_call.action.sources"]
  }'
```

**Example response (excerpt):**

```json
{
  "id": "resp_68a1f7c0a1b2c3d4e5f6a7b8c9d0e1f2",
  "object": "response",
  "status": "completed",
  "model": "gpt-5.6-terra",
  "output": [
    {
      "type": "web_search_call",
      "id": "ws_68a1f7c11a2b3c4d5e6f7a8b9c0d1e2f",
      "status": "completed",
      "action": {
        "type": "search",
        "query": "OpenAI Responses API store parameter default",
        "sources": [
          {
            "type": "url",
            "url": "https://developers.openai.com/api/reference/resources/responses/methods/create"
          }
        ]
      }
    },
    {
      "type": "message",
      "id": "msg_68a1f7c25b6c7d8e9f0a1b2c3d4e5f6a",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "According to the OpenAI API reference, the `store` parameter defaults to true: generated responses are stored for later retrieval via the API, and the data is kept for at least 30 days (subject to data retention exceptions).",
          "annotations": [
            {
              "type": "url_citation",
              "start_index": 0,
              "end_index": 224,
              "url": "https://developers.openai.com/api/reference/resources/responses/methods/create",
              "title": "Create a model response | OpenAI API Reference"
            }
          ],
          "logprobs": []
        }
      ]
    }
  ]
}
```

!> Built-in tools such as web search are executed by OpenAI and only work when the upstream is OpenAI. Built-in tool calls may be charged per call on top of tokens; see the [pricing page](https://beeroute.ai/modellist/). New integrations should use the GA tool `{"type": "web_search"}`; the older `web_search_preview` does not support `filters`.

### Multi-turn Conversations ✅

**Option 1 (recommended): resend the full history every time.** This does not depend on upstream storage and works with every model:

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "input": [
      {"role": "user", "content": "Suggest a name for my orange cat."},
      {"role": "assistant", "content": "How about Pumpkin or Marmalade?"},
      {"role": "user", "content": "Give me a few shorter names."}
    ]
  }'
```

With reasoning models, append every item from the previous `output` (`reasoning`, `message`, and so on) to `input` unchanged instead of resending only the text; for `gpt-5.3-codex` and later models, keep the `phase` field on assistant messages you send back. When a conversation gets long, compact the context with `context_management` or `POST /v1/responses/compact`.

**Option 2: use `previous_response_id`.** Send only the new turn and let the upstream continue from the stored previous response:

```bash
curl https://beeroute.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-5.6-terra",
    "previous_response_id": "resp_68a1f2c3d4e5f6a7b8c9d0e1f2a3b4c5",
    "input": "Give me a few shorter names."
  }'
```

!> `previous_response_id` depends on upstream storage: the previous turn must be an OpenAI response created with `store` set to `true`, and the same upstream must be able to find it, otherwise the request fails. Models served through format conversion (non-OpenAI models) usually do not support it. Even with `previous_response_id`, the input tokens of all earlier turns in the chain are still billed as input tokens. It cannot be combined with `conversation`.

## 📮 Request

### Endpoint

```text
POST https://beeroute.ai/v1/responses
```

Creates a model response. BeeRoute also provides:

| Endpoint | Description |
|------|------|
| `POST /v1/responses/compact` | Stateless compaction of a long conversation: send the full context (`model`, `input`, `instructions`, and so on) and get back an object whose `object` is `response.compaction`; pass its `output` unchanged as the `input` of your next `/v1/responses` request. Streaming is not supported. See the [official compact reference](https://developers.openai.com/api/reference/resources/responses/methods/compact) for parameters. |

BeeRoute does not provide the retrieve, delete, or cancel endpoints for responses (`GET`/`DELETE /v1/responses/{id}`, `/cancel`, `/input_items`, `/input_tokens`).

### Authentication

```text
Authorization: Bearer $API_KEY
```

### Request Body Parameters

The commonly used parameters are listed below. For every field and the latest definitions, see the [official API reference](https://developers.openai.com/api/reference/resources/responses/methods/create).

#### Basic Parameters

| Parameter | Type | Description |
|------|------|------|
| `model` | string | **Required on BeeRoute.** Model ID, such as `gpt-5.6-terra`. It is optional in the OpenAI spec (it can come from `prompt`), but BeeRoute needs it to route the request and bill it. |
| `input` | string or array | Model input. A string is equivalent to one text message with the `user` role; an array is a list of input items (see "Input Item Types"). Optional in the spec (context can also come from `prompt`, `conversation`, or `previous_response_id`). |
| `instructions` | string or null | A system (developer) message inserted at the start of the context. When used with `previous_response_id`, the previous turn's instructions are not carried over. |
| `stream` | boolean or null | Default `false`. When `true`, the response is streamed as SSE. |
| `stream_options` | object or null | Set only when `stream: true`. Its `include_obfuscation` field is filtered by BeeRoute by default, so the upstream default applies. |
| `max_output_tokens` | integer or null | Upper bound on the tokens generated for the response, including visible output and reasoning tokens. Minimum 16. |
| `temperature` | number or null | Sampling temperature, 0–2, default 1. Adjust this or `top_p`, but not both. |
| `top_p` | number or null | Nucleus sampling, 0–1, default 1. |
| `top_logprobs` | integer or null | 0–20, the number of most likely tokens (with log probabilities) to return at each token position. |
| `metadata` | object or null | Up to 16 key-value pairs; keys up to 64 characters, values up to 512 characters. |
| `include` | array or null | Additional data to return; see the table below. |
| `text` | object | Text output configuration (`format`, `verbosity`); see below. |
| `reasoning` | object or null | Reasoning configuration (`effort`, `summary`, and more); see below. |
| `tools` | array | Tools the model may call; see "Tools Overview". |
| `tool_choice` | string or object | How the model selects tools; see below. |
| `parallel_tool_calls` | boolean or null | Whether the model may run tool calls in parallel. Default `true`. |
| `max_tool_calls` | integer or null | Maximum total number of built-in tool calls in one response (across all built-in tools); further calls by the model are ignored. |
| `prompt` | object or null | Reference to a prompt template: `id`, `variables`, `version`. Templates belong to the upstream OpenAI account and usually cannot be used through BeeRoute. |

#### State, Caching, and Safety Parameters

| Parameter | Type | Description |
|------|------|------|
| `store` | boolean or null | Whether the upstream stores the response for later retrieval. Default `true` (kept for at least 30 days, with exceptions). BeeRoute forwards it unchanged by default. |
| `previous_response_id` | string or null | ID of the previous response, used to chain multi-turn conversations. Cannot be used together with `conversation`. ⚠️ Depends on upstream storage and is not available for every model. |
| `conversation` | string or object or null | The conversation this response belongs to (a conversation ID or `{"id": "..."}`). Items from the conversation are prepended to this request's input, and this turn's input and output are added to the conversation when it completes. ⚠️ Conversations are created with the OpenAI Conversations API, which BeeRoute does not provide, so this is generally unavailable. |
| `context_management` | array or null | Server-side context compaction, for example `[{"type": "compaction", "compact_threshold": 200000}]` (`compact_threshold` minimum 1000). When the rendered token count crosses the threshold, the upstream compacts the context and the output includes an encrypted `compaction` item. |
| `prompt_cache_key` | string or null | Prompt cache bucketing key that improves cache hit rates; replaces the caching role of the `user` field. |
| `prompt_cache_options` | object | Prompt caching options (`gpt-5.6` and later models): `mode` (`implicit` by default, or `explicit`), `ttl` (`30m` by default, or `12h`), `prewarm`, `comparison_response_id`. |
| `moderation` | object or null | Runs moderation on input and output: `model` (such as `omni-moderation-latest`), with `policy.input.mode` / `policy.output.mode` set to `score` or `block`. |
| `safety_identifier` | string or null | A stable ID for your end user (up to 128 characters; hashing is recommended), used to detect policy violations. BeeRoute does not forward it upstream by default. |
| `service_tier` | string or null | OpenAI values: `auto`, `default`, `flex`, `scale`, `priority`, `fast`, `ultrafast`. BeeRoute filters this parameter by default, so it normally has no effect. |

#### Deprecated Parameters

| Parameter | Description |
|------|------|
| `user` | Being replaced by `safety_identifier` and `prompt_cache_key`; use `prompt_cache_key` for caching optimizations. |
| `truncation` | `auto` or `disabled` (default). `auto`: if the input exceeds the context window, items are dropped from the **beginning** of the conversation; `disabled`: the request fails with a 400 error. The spec marks it as deprecated; for long conversations use `context_management` or `/v1/responses/compact` instead. |
| `prompt_cache_retention` | `in_memory` or `24h`. Deprecated; use `prompt_cache_options.ttl`. |
| `reasoning.generate_summary` | Deprecated; use `reasoning.summary`. BeeRoute does not forward this field. |
| `reasoning.encrypted_content` in `include` | Reasoning items now include `encrypted_content` by default. The value is still accepted but no longer required. |

#### Parameters BeeRoute Does Not Forward

`background`, `background_options`, `access_programs`, and `image` (request-level image options) are currently not forwarded upstream and are ignored if sent. As a result, background mode (and the related `queued` status and cancellation) is not available on BeeRoute.

#### include Values

| Value | Description |
|------|------|
| `web_search_call.action.sources` | Include the sources used by web search calls |
| `web_search_call.results` | Include the results of web search calls |
| `code_interpreter_call.outputs` | Include the outputs of Python code run by the code interpreter |
| `computer_call_output.output.image_url` | Include image URLs from computer call outputs |
| `file_search_call.results` | Include the search results of file search calls |
| `message.input_image.image_url` | Include image URLs from input messages |
| `message.output_text.logprobs` | Include logprobs with assistant messages |
| `reasoning.encrypted_content` | Include encrypted reasoning content in reasoning items (now returned by default) |

#### reasoning Object

| Field | Description |
|------|------|
| `effort` | Reasoning effort: `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. Supported values and the default depend on the model (the `gpt-5.6` family defaults to `medium`); some models return 400 for unsupported values. |
| `summary` | Reasoning summary: `auto`, `concise`, `detailed`. When set, the summary appears in the `summary` of the `reasoning` output item; when omitted, no summary is returned. |
| `mode` | Execution mode: `standard` (default) or `pro`; supported by the GPT-5.6 and GPT-6 families. |
| `context` | Whether reasoning from earlier turns is rendered to the model on later turns: `auto`, `current_turn`, `all_turns`. The `gpt-5.6` family defaults to `all_turns`; earlier models default to `current_turn`. |

#### text Object

| Field | Description |
|------|------|
| `format` | Output format, default `{"type": "text"}`. Set `json_schema` to enable Structured Outputs. `{"type": "json_object"}` is the older JSON mode: you must explicitly ask for JSON in the prompt, and it is not recommended for models that support `json_schema`. |
| `verbosity` | Response verbosity: `low`, `medium` (default), `high`. |

Fields when `format` is `json_schema`:

| Field | Required | Description |
|------|------|------|
| `type` | Yes | Always `json_schema` |
| `name` | Yes | Format name; only a-z, A-Z, 0-9, underscores, and dashes, up to 64 characters |
| `schema` | Yes | The JSON Schema the output must follow |
| `description` | No | What the format is for, which helps the model decide how to respond |
| `strict` | No | Default `false`. When `true`, the output strictly follows the schema (only a subset of JSON Schema is supported). Recommended |

#### tool_choice

| Value | Description |
|------|------|
| `"auto"` | The model decides whether to reply with a message or call tools |
| `"none"` | The model calls no tools and replies with a message |
| `"required"` | The model must call one or more tools |
| `{"type": "function", "name": "get_weather"}` | Force a call to a specific function |
| `{"type": "custom", "name": "..."}` | Force a call to a specific custom tool |
| `{"type": "mcp", "server_label": "...", "name": "..."}` | Force a call to a tool on a specific MCP server (`name` is optional) |
| `{"type": "allowed_tools", "mode": "auto", "tools": [...]}` | Restrict the available tools to the subset listed in `tools`; `mode` is `auto` or `required` |
| `{"type": "file_search"}` and other built-in tool types | Force a built-in tool; `type` can be `file_search`, `web_search_preview`, `web_search_preview_2025_03_11`, `computer`, `computer_use_preview`, `computer_use`, `code_interpreter`, `image_generation` |
| `{"type": "apply_patch"}` or `{"type": "shell"}` | Force a call to the apply_patch or shell tool |

### Input Item Types

When `input` is an array, each item can be a message, an output item from a previous turn, or a tool result.

**Message** (`type` can be omitted and defaults to `message`):

| Field | Description |
|------|------|
| `role` | `user`, `assistant`, `system`, or `developer`. `developer`/`system` instructions take precedence over `user` |
| `content` | A string, or an array of content parts (see below) |
| `phase` | Assistant messages only: `commentary` (intermediate) or `final_answer`. Keep it when sending messages back to `gpt-5.3-codex` and later models |

**Content types**:

| Type | Fields |
|------|------|
| `input_text` | `text`: the text content |
| `input_image` | `image_url` (public URL or base64 data URL), `file_id`, `detail` (`low`, `high`, `auto` by default, `original`) |
| `input_file` | `file_data` (base64 data URL, such as `data:application/pdf;base64,...`), `file_url`, `file_id`, `filename`, `detail` (`auto` by default, `low`, `high`) |

Each content part can also carry `prompt_cache_breakpoint` (`{"mode": "explicit", "ttl": "30m"}`) to explicitly mark a reusable prompt prefix. BeeRoute does not provide a Files endpoint, so `file_id` can only reference files that already exist in the upstream account.

**Other input items**:

| Type | Purpose |
|------|------|
| `message` (assistant output) | A message the model produced in a previous turn, sent back unchanged |
| `reasoning` | A reasoning item from a previous turn (with `encrypted_content`); sending it back preserves the reasoning context |
| `function_call` | A function call the model made in a previous turn |
| `function_call_output` | The function result: `call_id` plus `output` (a string, or an array of `input_text`/`input_image`/`input_file`) |
| `custom_tool_call` / `custom_tool_call_output` | A custom tool call and its result |
| `computer_call_output` | The screenshot sent back after running a computer action |
| `mcp_approval_response` | The answer to an MCP approval request |
| `shell_call_output` / `local_shell_call_output` / `apply_patch_call_output` | Results sent back after the client runs shell or apply_patch operations (used by coding agents) |
| `compaction` | An encrypted compacted-context item, sent back unchanged |
| `compaction_trigger` | Requests compaction of the current context; must be the last input item |
| `item_reference` | References a stored item by ID (depends on upstream storage) |

### Tools Overview

| Type | Description | On BeeRoute |
|------|------|------|
| `function` | A function in your own code. The model returns a `function_call`; you run it and send back a `function_call_output` | Any model that supports tool calling |
| `custom` | A custom tool with free-form text input (the format can be constrained with a grammar); the model returns a `custom_tool_call` | OpenAI models |
| `web_search` (or `web_search_2025_08_26`) | Web search (GA) | OpenAI upstream only |
| `web_search_preview` | The older preview search tool; use `web_search` for new integrations | OpenAI upstream only |
| `file_search` | Searches files in vector stores; requires `vector_store_ids` | OpenAI upstream only, and the vector stores must exist in the upstream account |
| `code_interpreter` | Runs Python code in a container | OpenAI upstream only |
| `image_generation` | Generates or edits images with GPT Image models | OpenAI upstream only |
| `mcp` | Adds tools from remote MCP servers or connectors | OpenAI upstream only |
| `computer` | Computer use (GA; the older version is `computer_use_preview`). The model returns a `computer_call`; your environment runs the action and sends back a screenshot | OpenAI upstream only |
| `shell` / `local_shell` / `apply_patch` | Run shell commands and edit files with diffs; used by coding agents such as Codex | OpenAI models |
| `tool_search` / `namespace` | Defer loading of large tool sets (with `defer_loading`) and group tools under namespaces | OpenAI models (`tool_search` requires `gpt-5.4` or later) |

**function tool fields**:

| Field | Description |
|------|------|
| `type` | Always `function` |
| `name` | The function name |
| `description` | What the function does; the model uses it to decide whether to call the function |
| `parameters` | A JSON Schema describing the parameters |
| `strict` | `true`: arguments strictly follow the schema; every object must set `additionalProperties: false` and list all properties in `required` (express optional fields with a type that includes `null`). Omitted: Responses tries to normalize the schema into strict mode and falls back to non-strict when it cannot (the tool then shows `strict: false` in the response). `false`: non-strict, best-effort |
| `defer_loading` | Whether the function is deferred (used with `tool_search`) |

**web_search tool fields**:

| Field | Description |
|------|------|
| `type` | `web_search` or `web_search_2025_08_26` |
| `filters.allowed_domains` | Domains the search may use (subdomains included); all domains are allowed when omitted |
| `search_context_size` | How much context the search uses: `low`, `medium` (default), `high` |
| `user_location` | Approximate location: `type` (`approximate`), `city`, `country` (two-letter ISO code), `region`, `timezone` (IANA). When omitted or null it defaults to the United States; send just `{"type": "approximate"}` to avoid that fallback |
| `external_web_access` | Default `true`; when `false`, only offline/cached content is used and no new pages are fetched |

## 📥 Response

### Response Object

| Field | Description |
|------|------|
| `id` | Response ID, starting with `resp_` |
| `object` | Always `response` |
| `created_at` | Creation time (Unix seconds) |
| `completed_at` | Completion time (Unix seconds); may be null |
| `status` | Response status; see the table below |
| `model` | The model used to generate the response |
| `output` | Array of output items; see "Output Items" |
| `usage` | Token usage; see "usage" |
| `error` | An error object (`code`, `message`) when generation fails; otherwise null |
| `incomplete_details` | Why the response is incomplete (`reason`); otherwise null |
| `service_tier` | The service tier actually used |
| `tool_usage` | Usage reported by built-in tools (`image_gen`, `web_search`); may be omitted |
| `instructions`, `max_output_tokens`, `max_tool_calls`, `temperature`, `top_p`, `top_logprobs`, `parallel_tool_calls`, `tool_choice`, `tools`, `text`, `reasoning`, `truncation`, `metadata`, `store`, `previous_response_id`, `conversation`, `prompt`, `prompt_cache_key`, `safety_identifier`, `user` | Echo the parameters that took effect for this request |

?> `response.output_text` in the official Python / JavaScript SDKs is an SDK convenience property that joins all `output_text` parts; the raw HTTP response does not necessarily contain it. When calling over HTTP, iterate over `output`.

### status

| Value | Description |
|------|------|
| `completed` | Generation finished |
| `in_progress` | Generation is in progress (seen during streaming) |
| `incomplete` | Generation did not finish; see `incomplete_details.reason` |
| `failed` | Generation failed; see `error` |
| `queued` | Queued (background mode, not provided by BeeRoute) |
| `cancelled` | Cancelled (background mode, not provided by BeeRoute) |

`incomplete_details.reason` can be `max_output_tokens` (the `max_output_tokens` limit was reached), `content_filter` (content was filtered), `max_messages`, or `steered` (stopped after steering in WebSocket mode).

### Output Items

| `type` | Description |
|------|------|
| `message` | The model reply: `id`, `role` (`assistant`), `status`, `content`, and possibly `phase` |
| `reasoning` | Reasoning item: `id`, `summary` (array of `summary_text`), `encrypted_content` (returned by default; when streaming, use the complete value from `response.output_item.done`), optional `content` (`reasoning_text`) |
| `function_call` | Function call: `id`, `call_id`, `name`, `arguments` (JSON string), `status` |
| `custom_tool_call` | Custom tool call: `call_id`, `name`, `input` |
| `web_search_call` | Web search: `status`, `action` (`search`, `open_page`, or `find_in_page`) |
| `file_search_call` | File search: `queries`, `status`, `results` |
| `code_interpreter_call` | Code interpreter execution record |
| `image_generation_call` | Image generation result (`result` is a base64 image) |
| `computer_call` | A computer action for you to run |
| `mcp_call` / `mcp_list_tools` / `mcp_approval_request` | MCP tool call, tool list, and approval request |
| `shell_call` / `local_shell_call` / `apply_patch_call` | Shell or patch operations for the client to run |
| `tool_search_call` / `tool_search_output` | The tool search process |
| `compaction` | Encrypted compacted context |

Each part in `message.content` is either `output_text` (`text`, `annotations`, `logprobs`) or `refusal` (`refusal`: the refusal explanation).

**annotation types**:

| Type | Fields |
|------|------|
| `url_citation` | `url`, `title`, `start_index`, `end_index` (character positions of the citation in the text) |
| `file_citation` | `file_id`, `filename`, `index` (the position in the output text where the citation is inserted) |
| `container_file_citation` | `container_id`, `file_id`, `filename`, `start_index`, `end_index` |
| `file_path` | `file_id`, `index` |

### usage

| Field | Description |
|------|------|
| `input_tokens` | Number of input tokens |
| `input_tokens_details.cached_tokens` | Input tokens served from the prompt cache |
| `input_tokens_details.cache_write_tokens` | Input tokens written to the cache |
| `input_tokens_details.cache_write_tokens_details` | Optional breakdown by cache lifetime: `ttl_30m_tokens`, `ttl_12h_tokens` |
| `output_tokens` | Number of output tokens (reasoning tokens included) |
| `output_tokens_details.reasoning_tokens` | Number of reasoning tokens |
| `total_tokens` | Total number of tokens |

For non-OpenAI models served through format conversion, the detail fields may be 0 or missing.

### Streaming Events

With `stream: true` the response is returned as SSE. Each event has an `event:` line and a `data:` line, and every `data` payload contains a `type` and an increasing `sequence_number`. The main events are listed below; see the [official streaming events reference](https://developers.openai.com/api/reference/resources/responses/streaming-events) for the full list.

| Event | Description |
|------|------|
| `response.created` | The response was created |
| `response.in_progress` | The response is being generated |
| `response.output_item.added` / `response.output_item.done` | An output item was added / finished (`item`, `output_index`) |
| `response.content_part.added` / `response.content_part.done` | A content part was added / finished |
| `response.output_text.delta` | Text delta (`delta`, `logprobs`) |
| `response.output_text.done` | Text finished (`text`, `logprobs`) |
| `response.output_text.annotation.added` | A citation annotation was added |
| `response.refusal.delta` / `response.refusal.done` | Refusal text delta / finished |
| `response.function_call_arguments.delta` / `response.function_call_arguments.done` | Function argument delta / finished (`arguments`) |
| `response.reasoning_summary_part.added` / `response.reasoning_summary_part.done` | A reasoning summary part was added / finished |
| `response.reasoning_summary_text.delta` / `response.reasoning_summary_text.done` | Reasoning summary text delta / finished |
| `response.web_search_call.in_progress` / `.searching` / `.completed` | Web search progress |
| `response.completed` | The response finished; `response` contains the full `output` and `usage` |
| `response.incomplete` | The response ended incomplete |
| `response.failed` | The response failed |
| `error` | An error occurred (`code`, `message`, `param`) |

Delta events such as text deltas may carry an `obfuscation` field (upstream stream-obfuscation padding); clients can ignore it.

## ⚠️ Errors

Errors raised by the BeeRoute gateway itself (invalid key, insufficient balance, no available channel, and so on) use an OpenAI-style error body with `type` set to `new_api_error`. The `message` ends with a request ID; include it when contacting support:

```json
{
  "error": {
    "code": "",
    "message": "Invalid token (request id: 20261127080000123456789a1b2c3d4Xy7Kp2Qm)",
    "type": "new_api_error"
  }
}
```

| HTTP status | Common causes |
|------|------|
| 400 | Malformed request, for example a missing `model` |
| 401 | Invalid API key, or the key is disabled, expired, or out of key quota |
| 403 | Insufficient account balance (`code` is `insufficient_user_quota`), or the key cannot use this model / group |
| 429 | Too many requests (gateway or upstream rate limit) |
| 503 | No available channel for this model in the current group (`code` is `model_not_found`) |
| 5xx | Upstream service error |

Errors returned by the upstream are passed through in OpenAI error format (`message`, `type`, `param`, `code`). If a request is accepted but generation fails, the response `status` is `failed` and the reason is in `error.code` and `error.message`; streaming requests receive a `response.failed` or `error` event instead.
