> ## 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.

# Chat Completions

> Generate responses using the OpenAI-compatible chat completions endpoint.

The Chat Completions API is the primary way to interact with language models through Routeway. Send a list of messages and receive a model-generated response. The endpoint is fully compatible with OpenAI's `/v1/chat/completions` format, so any existing client or SDK works without changes.

<Info>
  Routeway supports the same request and response schema as the OpenAI Chat Completions API. Point your base URL to `https://api.routeway.ai/v1` and you're set.
</Info>

<Tip>
  **New:** Append `@flux-2-turbo` or `@online` to any model ID to generate images or search the web directly in chat — no client-side tool setup required. See [Server Tools](/guides/chat-completions/server-tools).
</Tip>

***

## Quick Example

<Tabs>
  <Tab title="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.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "What is the capital of France?"}
        ]
    )

    print(response.choices[0].message.content)
    ```
  </Tab>

  <Tab title="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,
    });

    async function main() {
      const response = await client.chat.completions.create({
        model: "gpt-4o-mini",
        messages: [
          { role: "system", content: "You are a helpful assistant." },
          { role: "user", content: "What is the capital of France?" },
        ],
      });

      console.log(response.choices[0].message.content);
    }

    main().catch(console.error);
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl https://api.routeway.ai/v1/chat/completions \
      -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-4o-mini",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "What is the capital of France?"}
        ]
      }'
    ```
  </Tab>
</Tabs>

***

## Response Shape

A successful response looks like this:

```json theme={null}
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1718500000,
  "model": "gpt-4o-mini",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 8,
    "total_tokens": 32
  }
}
```

| Field                        | Description                                               |
| ---------------------------- | --------------------------------------------------------- |
| `choices[0].message.content` | The model's text response.                                |
| `choices[0].finish_reason`   | Why the model stopped: `stop`, `length`, or `tool_calls`. |
| `usage`                      | Token counts for billing and monitoring.                  |

***

## Request Model

These are the most common fields you can include in a Chat Completions request:

| Field              | Type      | Description                                                                                                                                                   |
| ------------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`            | `string`  | The model to use (e.g. `gpt-4o-mini`, `claude-sonnet-4-20250514`).                                                                                            |
| `messages`         | `array`   | The conversation history. Each message has a `role` and `content`.                                                                                            |
| `tools`            | `array`   | Function definitions the model can call. See [Tool Calling](/guides/chat-completions/tool-calling).                                                           |
| `response_format`  | `object`  | Constrain output to JSON or a JSON Schema. See [Structured Outputs](/guides/chat-completions/structured-outputs).                                             |
| `stream`           | `boolean` | Return tokens incrementally via SSE. See [Streaming](/guides/chat-completions/streaming).                                                                     |
| `stream_options`   | `object`  | Options for streaming (e.g. `include_usage`).                                                                                                                 |
| `reasoning_effort` | `string`  | Control thinking depth for reasoning models. See [Reasoning](/guides/chat-completions/reasoning).                                                             |
| `service_tier`     | `string`  | Choose processing tier (`default`, `flex`, or `priority`) on supported OpenAI and Gemini models. See [Service Tiers](/guides/chat-completions/service-tiers). |

***

## Learn More

<CardGroup cols={2}>
  <Card title="Streaming" icon="radio" href="/guides/chat-completions/streaming">
    Receive tokens as they are generated for real-time output.
  </Card>

  <Card title="Tool Calling" icon="wrench" href="/guides/chat-completions/tool-calling">
    Let the model invoke functions and external tools.
  </Card>

  <Card title="Server Tools" icon="cpu" href="/guides/chat-completions/server-tools">
    Use image generation and online search via model tag syntax.
  </Card>

  <Card title="Structured Outputs" icon="braces" href="/guides/chat-completions/structured-outputs">
    Constrain responses to JSON or a specific schema.
  </Card>

  <Card title="Reasoning" icon="brain" href="/guides/chat-completions/reasoning">
    Use extended thinking for complex multi-step problems.
  </Card>

  <Card title="Multimodal Inputs" icon="image" href="/guides/chat-completions/multimodal-inputs">
    Send images and other media alongside text messages.
  </Card>

  <Card title="Caching" icon="database" href="/guides/chat-completions/caching">
    Reduce costs and latency with prompt caching.
  </Card>

  <Card title="Service Tiers" icon="gauge" href="/guides/chat-completions/service-tiers">
    Trade cost for speed with flex and priority processing.
  </Card>

  <Card title="Presets" icon="sliders-horizontal" href="/guides/chat-completions/presets">
    Apply reusable configurations to your requests.
  </Card>
</CardGroup>
