# Chat
(*chat*)

## Overview

### Available Operations

* [send](#send) - Create a chat completion

## send

Sends a request for a model response for the given chat conversation. Supports both streaming and non-streaming modes.

### Example Usage

<!-- UsageSnippet language="python" operationID="sendChatCompletionRequest" method="post" path="/chat/completions" -->
```python
from openrouter import OpenRouter
import os


with OpenRouter(
    http_referer="<value>",
    x_title="<value>",
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.chat.send(messages=[], stream=False)

    with res as event_stream:
        for event in event_stream:
            # handle event
            print(event, flush=True)

```

### Parameters

| Parameter                                                                                                                                         | Type                                                                                                                                              | Required                                                                                                                                          | Description                                                                                                                                       |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `messages`                                                                                                                                        | List[[components.Message](../../components/message.md)]                                                                                           | :heavy_check_mark:                                                                                                                                | N/A                                                                                                                                               |
| `http_referer`                                                                                                                                    | *Optional[str]*                                                                                                                                   | :heavy_minus_sign:                                                                                                                                | The app identifier should be your app's URL and is used as the primary identifier for rankings.<br/>This is used to track API usage per application.<br/> |
| `x_title`                                                                                                                                         | *Optional[str]*                                                                                                                                   | :heavy_minus_sign:                                                                                                                                | The app display name allows you to customize how your app appears in OpenRouter's dashboard.<br/>                                                 |
| `provider`                                                                                                                                        | [OptionalNullable[components.Schema0]](../../components/schema0.md)                                                                               | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `plugins`                                                                                                                                         | List[[components.Schema17](../../components/schema17.md)]                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `route`                                                                                                                                           | [OptionalNullable[components.Route]](../../components/route.md)                                                                                   | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `user`                                                                                                                                            | *Optional[str]*                                                                                                                                   | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `session_id`                                                                                                                                      | *Optional[str]*                                                                                                                                   | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `model`                                                                                                                                           | *Optional[str]*                                                                                                                                   | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `models`                                                                                                                                          | List[*str*]                                                                                                                                       | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `frequency_penalty`                                                                                                                               | *OptionalNullable[float]*                                                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `logit_bias`                                                                                                                                      | Dict[str, *float*]                                                                                                                                | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `logprobs`                                                                                                                                        | *OptionalNullable[bool]*                                                                                                                          | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `top_logprobs`                                                                                                                                    | *OptionalNullable[float]*                                                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `max_completion_tokens`                                                                                                                           | *OptionalNullable[float]*                                                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `max_tokens`                                                                                                                                      | *OptionalNullable[float]*                                                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `metadata`                                                                                                                                        | Dict[str, *str*]                                                                                                                                  | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `presence_penalty`                                                                                                                                | *OptionalNullable[float]*                                                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `reasoning`                                                                                                                                       | [Optional[components.Reasoning]](../../components/reasoning.md)                                                                                   | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `response_format`                                                                                                                                 | [Optional[components.ResponseFormat]](../../components/responseformat.md)                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `seed`                                                                                                                                            | *OptionalNullable[int]*                                                                                                                           | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `stop`                                                                                                                                            | [OptionalNullable[components.Stop]](../../components/stop.md)                                                                                     | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `stream`                                                                                                                                          | *Optional[bool]*                                                                                                                                  | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `stream_options`                                                                                                                                  | [OptionalNullable[components.ChatStreamOptions]](../../components/chatstreamoptions.md)                                                           | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `temperature`                                                                                                                                     | *OptionalNullable[float]*                                                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `tool_choice`                                                                                                                                     | *Optional[Any]*                                                                                                                                   | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `tools`                                                                                                                                           | List[[components.ToolDefinitionJSON](../../components/tooldefinitionjson.md)]                                                                     | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `top_p`                                                                                                                                           | *OptionalNullable[float]*                                                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `debug`                                                                                                                                           | [Optional[components.Debug]](../../components/debug.md)                                                                                           | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `image_config`                                                                                                                                    | Dict[str, [components.ChatGenerationParamsImageConfig](../../components/chatgenerationparamsimageconfig.md)]                                      | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `modalities`                                                                                                                                      | List[[components.Modality](../../components/modality.md)]                                                                                         | :heavy_minus_sign:                                                                                                                                | N/A                                                                                                                                               |
| `retries`                                                                                                                                         | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.md)                                                                                  | :heavy_minus_sign:                                                                                                                                | Configuration to override the default retry behavior of the client.                                                                               |

### Response

**[operations.SendChatCompletionRequestResponse](../../operations/sendchatcompletionrequestresponse.md)**

### Errors

| Error Type                    | Status Code                   | Content Type                  |
| ----------------------------- | ----------------------------- | ----------------------------- |
| errors.ChatError              | 400, 401, 429                 | application/json              |
| errors.ChatError              | 500                           | application/json              |
| errors.OpenRouterDefaultError | 4XX, 5XX                      | \*/\*                         |