# Responses

Generate text from messages and inline images, run tools in your client, or continue a response you choose to save. Responses are stateless by default.

`POST /v1/responses`

`GET /v1/responses/{response_id}`

`DELETE /v1/responses/{response_id}`

`GET /v1/codex/models`

## Send input

For a single turn, send a string input. For stateless continuation, send the complete message and tool-call history. If max_output_tokens is omitted, uRouter uses up to 8,192 tokens within the selected model's limits.

- Accepted fields are model, input, instructions, max_output_tokens, temperature, top_p, presence_penalty, frequency_penalty, stream, tools, tool_choice, parallel_tool_calls, store, previous_response_id, reasoning, include, prompt_cache_key, client_metadata and text.
- The gateway accepts reasoning.summary set to auto or none, and include containing only reasoning.encrypted_content or an empty array. These settings are compatibility hints. prompt_cache_key accepts up to 256 characters. client_metadata accepts up to 16 entries with string values, 128-character keys and 1,024-character values. These hints do not enable storage, return reasoning content, or change billing.
- For vision-capable models, add input_image blocks to a user message with an inline base64 PNG, JPEG or WebP data URL in image_url. Use detail auto, low or high. Each request accepts up to 16 images and 12 MiB of encoded image data. File IDs and remote URLs are unsupported.
- Read output items by type. Preserve assistant phase values commentary and final_answer when replaying messages. phase may also be null or omitted. Assistant output_text blocks can include an empty logprobs array, which the gateway discards when replaying history.

### cURL

```text
curl --fail-with-body "https://urouter.net/gateway/v1/responses" \
  -H "Authorization: Bearer $UROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "YOUR_MODEL_ID",
  "input": "Explain DNS in one sentence.",
  "max_output_tokens": 256
}'
```

## Store a response for continuation

Responses are stateless by default. Set store to true to retain a completed or incomplete response and its continuation history for 24 hours from request acceptance. Failed responses are not saved for continuation.

- To continue a saved response, set previous_response_id to its returned resp_ ID and send the new input, including the outputs of any pending tool calls. Top-level instructions apply to the request that supplies them. Set store to true again if you want to retain the new response too.
- Set UROUTER_RESPONSE_ID to the ID from a stored response. GET /v1/responses/{response_id} reads the saved response. DELETE on that path removes it and returns deleted: true. Both operations use an API key authorized for the same account and model scope. A missing, deleted, expired, or inaccessible response returns 404.
- Reading a saved response or using it as a parent does not renew its expiry. Each continuation runs and bills as a new request. Deleting a saved response does not delete its billing record.
- Storage limits include 2 MiB per saved response and history, 16 MiB across active saved responses, and 64 active responses per account. Up to 256 records, including deletions, count within the retention window. If storage is unavailable after inference, check the original request before retrying.

### Store a response

```text
curl --fail-with-body "https://urouter.net/gateway/v1/responses" \
  -H "Authorization: Bearer $UROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"model":"YOUR_MODEL_ID","input":"Explain DNS in one sentence.","store":true}'
```

### Continue a saved response

```text
curl --fail-with-body "https://urouter.net/gateway/v1/responses" \
  -H "Authorization: Bearer $UROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"model":"YOUR_MODEL_ID","input":"Give a short example.","previous_response_id":"'"$UROUTER_RESPONSE_ID"'"}'
```

### Read a saved response

```text
curl --fail-with-body "https://urouter.net/gateway/v1/responses/$UROUTER_RESPONSE_ID" \
  -H "Authorization: Bearer $UROUTER_API_KEY"
```

### Delete a saved response

```text
curl --fail-with-body -X DELETE "https://urouter.net/gateway/v1/responses/$UROUTER_RESPONSE_ID" \
  -H "Authorization: Bearer $UROUTER_API_KEY"
```

## Run tools in your client

The model can request function calls with JSON arguments or custom tool calls with plain-text input. Your client executes the declared tool and returns its result. Hosted tools and programmatic tool calling are unsupported.

- Declare a function with type: function, name and optional description, parameters and strict. A namespace can group multiple function or custom tools. A function_call supplies call_id, name, arguments and namespace when applicable.
- Declare a custom tool with type: custom, name and optional description. If you set format, it must be { "type": "text" }. A custom_tool_call supplies call_id, name and raw input, bounded to 64 KiB of UTF-8 text and 256 KiB after JSON encoding. Grammar formats are unsupported.
- Return function_call_output or custom_tool_call_output with the matching call_id and a string or input_text blocks. If the output item includes status, use completed. In stateless requests, include the earlier conversation and call items. When continuing a saved response, send the new results without replaying the saved history.
- Use tool_choice with a function or custom tool address to choose one declared tool. To allow several, use type: allowed_tools with mode: auto or required and a nonempty tools list of unique addresses. Include each tool's type, name, and namespace if declared in one.

### Require a custom tool from an allowed subset

```text
curl --fail-with-body "https://urouter.net/gateway/v1/responses" \
  -H "Authorization: Bearer $UROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "YOUR_MODEL_ID",
  "input": "Look up domain name system in the glossary.",
  "tools": [{"type":"custom","name":"lookup_glossary","description":"Look up the plain-text term in a glossary.","format":{"type":"text"}}],
  "tool_choice": {"type":"allowed_tools","mode":"required","tools":[{"type":"custom","name":"lookup_glossary"}]}
}'
```

## Choose an output format

Set text.format with a type of text, json_object or json_schema. Plain text is the default. JSON modes require a model that supports the selected format.

- For json_schema, place name and schema inside text.format with optional description and strict. Use a name of 1–64 letters, digits, underscores or hyphens. The schema must be a JSON object up to 64 KiB, with no more than 4,096 values or 32 nesting levels. Descriptions can be up to 1,024 characters.

## Handle streaming and completion

Streaming starts with response.created and response.in_progress after acceptance. Text and tool deltas follow. A stream ends with response.completed, response.incomplete, or response.failed. A failure can also emit an error event before any output. There is no [DONE] marker.

- An incomplete response can result from the output limit or content filtering. Inspect status and incomplete_details.
- Use the event type and output indexes to assemble items. Custom tools use response.custom_tool_call_input.delta and response.custom_tool_call_input.done. Treat errors or a closed stream without a terminal event as incomplete.
- Usage can include input_tokens_details.cached_tokens and output_tokens_details.reasoning_tokens when valid counts are available. Responses may also report verified sampling settings or service_tier. An omitted field is unavailable. Check Usage for the settled charge.

## Discover Codex models

Codex uses this catalog to find models available for local shell and MCP function tools through uRouter. Use a uRouter API key as a Bearer token. The response contains a models array with model IDs in slug, display names, reasoning levels, context limits and supported input modalities.

- Codex can send the optional client_version query parameter. It does not change the returned catalog.
- The list can be empty when no supported models are available. A missing or invalid key returns HTTP 401. A missing or stale catalog returns HTTP 503. Model selection does not reserve capacity or credit.

### List Codex models

```text
curl --fail-with-body "https://urouter.net/gateway/v1/codex/models?client_version=0.130.0" \
  -H "Authorization: Bearer $UROUTER_API_KEY"
```
