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

# Responses API

> A modern, stateful API for text generation with server-side multi-turn state and built-in tools.

The `/v1/responses` endpoint is an advanced OpenAI-compatible API format designed for conversational state management and built-in server-side tools. It eliminates the need to manage and resend large message histories on every turn and supports server-executed tools like web search and code execution.

```http theme={null}
POST https://api.routeway.ai/v1/responses
```

***

## Quickstart

> [tab] Python
>
> ```python theme={null}
> import os
> from openai import OpenAI
>
> client = OpenAI(
>     base_url="https://api.routeway.ai/v1",
>     api_key=os.getenv("ROUTEWAY_API_KEY")
> )
>
> response = client.responses.create(
>     model="gpt-4o",
>     input="What is the capital of France?"
> )
>
> print(response.output_text)
> ```

> [tab] Node.js
>
> ```javascript theme={null}
> import OpenAI from "openai";
>
> const client = new OpenAI({
>   baseURL: "https://api.routeway.ai/v1",
>   apiKey: process.env.ROUTEWAY_API_KEY,
> });
>
> const response = await client.responses.create({
>   model: "gpt-4o",
>   input: "What is the capital of France?",
> });
>
> console.log(response.output_text);
> ```

> [tab] cURL
>
> ```bash theme={null}
> curl https://api.routeway.ai/v1/responses \
>   -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "gpt-4o",
>     "input": "What is the capital of France?"
>   }'
> ```

***

## Stateful Multi-turn Conversations

The Responses API allows stateful multi-turn conversations using `previous_response_id`. You only need to pass the ID of the previous response — Routeway server-side reconstructs the conversation context.

```mermaid theme={null}
sequenceDiagram
    participant App
    participant Routeway
    App->>Routeway: input: "What is Rust?"
    Routeway-->>App: id: "resp_1", output_text: "Rust is a systems language..."
    App->>Routeway: input: "How does ownership work?", previous_response_id: "resp_1"
    Routeway-->>App: id: "resp_2", output_text: "Rust's ownership model..."
```

### Multi-turn Code Example

```python theme={null}
# Turn 1
resp1 = client.responses.create(
    model="gpt-4o",
    instructions="You are a helpful coding tutor.",
    input="What is Rust?"
)
print("Turn 1:", resp1.output_text)

# Turn 2: Reference Turn 1 via previous_response_id
resp2 = client.responses.create(
    model="gpt-4o",
    input="How does ownership work?",
    previous_response_id=resp1.id
)
print("Turn 2:", resp2.output_text)
```

***

## Built-in Server Tools

Unlike custom tool calling where your application code must execute the function locally, Responses API includes built-in server-side tools that execute automatically during inference.

| Tool | Type Value | Description |
| - | - | - |
| **Web Search** | `web_search_preview` | Searches live web results for real-time information. |
| **Code Interpreter** | `code_interpreter` | Runs Python code in a secure sandbox to calculate math or analyze data. |

```python theme={null}
response = client.responses.create(
    model="gpt-4o",
    tools=[
        {"type": "web_search_preview"},
        {"type": "code_interpreter"}
    ],
    input="Look up the latest population of Tokyo, then calculate its population density per km²."
)

print(response.output_text)
```

***

## Request Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `model` | string | **required** | Supported model ID (e.g. `gpt-4o`, `gpt-4o-mini`). |
| `input` | string \| array | **required** | The user prompt, or an array of items. |
| `instructions` | string | — | System-level prompt or instructions for the conversation. |
| `previous_response_id` | string | — | The ID of a previous response to continue a conversation. |
| `tools` | array | — | Built-in or custom tools available to the model. |
| `temperature` | number | `1.0` | Sampling randomness. |
| `max_output_tokens` | integer | — | Cap on output tokens generated. |
| `store` | boolean | `true` | When `false`, response is not saved for `previous_response_id` chaining. |

***

## Supported Models

To check which models support the Responses API, verify that `"/v1/responses"` is listed in the model's `endpoints` array on the [Models](https://docs.routeway.ai/getting-started/models.md) page or via `GET /v1/models`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.