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

# ChatRequest - TypeScript SDK

> ChatRequest type definition

<Warning>
  The TypeScript SDK and docs are currently in beta.
  Report issues on [GitHub](https://github.com/OpenRouterTeam/typescript-sdk/issues).
</Warning>

Chat completion request parameters

## Example Usage

```typescript lines theme={null}
import { ChatRequest } from "@openrouter/sdk/models";

let value: ChatRequest = {
  messages: [
    {
      content: "You are a helpful assistant.",
      role: "system",
    },
    {
      content: "What is the capital of France?",
      role: "user",
    },
  ],
};
```

## Fields

| Field                 | Type                                                                                                               | Required             | Description                                                                                                                                                                                                                                                                                                                                                                                                          | Example                                                                                                            |
| --------------------- | ------------------------------------------------------------------------------------------------------------------ | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `cacheControl`        | [models.AnthropicCacheControlDirective](/agent-sdk/typescript/api-reference/models/anthropiccachecontroldirective) | :heavy\_minus\_sign: | Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. Currently supported for Anthropic Claude models.                                                                                                                                                                                                          | `{"type": "ephemeral"}`                                                                                            |
| `debug`               | [models.ChatDebugOptions](/agent-sdk/typescript/api-reference/models/chatdebugoptions)                             | :heavy\_minus\_sign: | Debug options for inspecting request transformations (streaming only)                                                                                                                                                                                                                                                                                                                                                | `{"echo_upstream_body": true}`                                                                                     |
| `frequencyPenalty`    | *number*                                                                                                           | :heavy\_minus\_sign: | Frequency penalty (-2.0 to 2.0)                                                                                                                                                                                                                                                                                                                                                                                      | 0                                                                                                                  |
| `imageConfig`         | `Record<string, *models.ImageConfig*>`                                                                             | :heavy\_minus\_sign: | Provider-specific image configuration options. Keys and values vary by model/provider. See [https://openrouter.ai/docs/guides/overview/multimodal/image-generation](https://openrouter.ai/docs/guides/overview/multimodal/image-generation) for more details.                                                                                                                                                        | `{"aspect_ratio": "16:9","quality": "high"}`                                                                       |
| `logitBias`           | `Record<string, *number*>`                                                                                         | :heavy\_minus\_sign: | Token logit bias adjustments                                                                                                                                                                                                                                                                                                                                                                                         | `{"50256": -100}`                                                                                                  |
| `logprobs`            | *boolean*                                                                                                          | :heavy\_minus\_sign: | Return log probabilities                                                                                                                                                                                                                                                                                                                                                                                             | false                                                                                                              |
| `maxCompletionTokens` | *number*                                                                                                           | :heavy\_minus\_sign: | Maximum tokens in completion                                                                                                                                                                                                                                                                                                                                                                                         | 100                                                                                                                |
| `maxTokens`           | *number*                                                                                                           | :heavy\_minus\_sign: | Maximum tokens (deprecated, use max\_completion\_tokens). Note: some providers enforce a minimum of 16.                                                                                                                                                                                                                                                                                                              | 100                                                                                                                |
| `messages`            | *models.ChatMessages*\[]                                                                                           | :heavy\_check\_mark: | List of messages for the conversation                                                                                                                                                                                                                                                                                                                                                                                | \[<br />`{"content": "Hello!","role": "user"}`<br />]                                                              |
| `metadata`            | `Record<string, *string*>`                                                                                         | :heavy\_minus\_sign: | Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)                                                                                                                                                                                                                                                                                                                      | `{"session_id": "session-456","user_id": "user-123"}`                                                              |
| `modalities`          | [models.Modality](/agent-sdk/typescript/api-reference/models/modality)\[]                                          | :heavy\_minus\_sign: | Output modalities for the response. Supported values are "text", "image", and "audio".                                                                                                                                                                                                                                                                                                                               | \[<br />"text",<br />"image"<br />]                                                                                |
| `model`               | *string*                                                                                                           | :heavy\_minus\_sign: | Model to use for completion                                                                                                                                                                                                                                                                                                                                                                                          | openai/gpt-4                                                                                                       |
| `models`              | *string*\[]                                                                                                        | :heavy\_minus\_sign: | Models to use for completion                                                                                                                                                                                                                                                                                                                                                                                         | \[<br />"openai/gpt-4",<br />"openai/gpt-4o"<br />]                                                                |
| `parallelToolCalls`   | *boolean*                                                                                                          | :heavy\_minus\_sign: | Whether to enable parallel function calling during tool use. When true, the model may generate multiple tool calls in a single response.                                                                                                                                                                                                                                                                             | true                                                                                                               |
| `plugins`             | *models.ChatRequestPlugin*\[]                                                                                      | :heavy\_minus\_sign: | Plugins you want to enable for this request, including their settings.                                                                                                                                                                                                                                                                                                                                               |                                                                                                                    |
| `presencePenalty`     | *number*                                                                                                           | :heavy\_minus\_sign: | Presence penalty (-2.0 to 2.0)                                                                                                                                                                                                                                                                                                                                                                                       | 0                                                                                                                  |
| `provider`            | [models.ProviderPreferences](/agent-sdk/typescript/api-reference/models/providerpreferences)                       | :heavy\_minus\_sign: | When multiple model providers are available, optionally indicate your routing preference.                                                                                                                                                                                                                                                                                                                            | `{"allow_fallbacks": true}`                                                                                        |
| `reasoning`           | [models.ChatRequestReasoning](/agent-sdk/typescript/api-reference/models/chatrequestreasoning)                     | :heavy\_minus\_sign: | Configuration options for reasoning models                                                                                                                                                                                                                                                                                                                                                                           | `{"effort": "medium","summary": "concise"}`                                                                        |
| `responseFormat`      | *models.ResponseFormat*                                                                                            | :heavy\_minus\_sign: | Response format configuration                                                                                                                                                                                                                                                                                                                                                                                        | `{"type": "json_object"}`                                                                                          |
| `seed`                | *number*                                                                                                           | :heavy\_minus\_sign: | Random seed for deterministic outputs                                                                                                                                                                                                                                                                                                                                                                                | 42                                                                                                                 |
| `serviceTier`         | [models.ChatRequestServiceTier](/agent-sdk/typescript/api-reference/models/chatrequestservicetier)                 | :heavy\_minus\_sign: | The service tier to use for processing this request.                                                                                                                                                                                                                                                                                                                                                                 | auto                                                                                                               |
| `sessionId`           | *string*                                                                                                           | :heavy\_minus\_sign: | A unique identifier for grouping related requests (e.g., a conversation or agent workflow). When provided, OpenRouter uses it as the sticky routing key, routing all requests in the session to the same provider to maximize prompt cache hits. Also used for observability grouping. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. |                                                                                                                    |
| `stop`                | *models.Stop*                                                                                                      | :heavy\_minus\_sign: | Stop sequences (up to 4)                                                                                                                                                                                                                                                                                                                                                                                             | \[<br />""<br />]                                                                                                  |
| `stopServerToolsWhen` | *models.StopServerToolsWhenCondition*\[]                                                                           | :heavy\_minus\_sign: | Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides `max_tool_calls`.                                                                                                                                                                                                                                                                           | \[<br />`{"step_count": 5,"type": "step_count_is"}`,<br />`{"max_cost_in_dollars": 0.5,"type": "max_cost"}`<br />] |
| `stream`              | *boolean*                                                                                                          | :heavy\_minus\_sign: | Enable streaming response                                                                                                                                                                                                                                                                                                                                                                                            | false                                                                                                              |
| `streamOptions`       | [models.ChatStreamOptions](/agent-sdk/typescript/api-reference/models/chatstreamoptions)                           | :heavy\_minus\_sign: | Streaming configuration options                                                                                                                                                                                                                                                                                                                                                                                      | `{"include_usage": true}`                                                                                          |
| `temperature`         | *number*                                                                                                           | :heavy\_minus\_sign: | Sampling temperature (0-2)                                                                                                                                                                                                                                                                                                                                                                                           | 0.7                                                                                                                |
| `toolChoice`          | *models.ChatToolChoice*                                                                                            | :heavy\_minus\_sign: | Tool choice configuration                                                                                                                                                                                                                                                                                                                                                                                            | auto                                                                                                               |
| `tools`               | *models.ChatFunctionTool*\[]                                                                                       | :heavy\_minus\_sign: | Available tools for function calling                                                                                                                                                                                                                                                                                                                                                                                 | \[<br />`{"function": {"description": "Get weather","name": "get_weather"}`,<br />"type": "function"<br />}<br />] |
| `topLogprobs`         | *number*                                                                                                           | :heavy\_minus\_sign: | Number of top log probabilities to return (0-20)                                                                                                                                                                                                                                                                                                                                                                     | 5                                                                                                                  |
| `topP`                | *number*                                                                                                           | :heavy\_minus\_sign: | Nucleus sampling parameter (0-1)                                                                                                                                                                                                                                                                                                                                                                                     | 1                                                                                                                  |
| `trace`               | [models.TraceConfig](/agent-sdk/typescript/api-reference/models/traceconfig)                                       | :heavy\_minus\_sign: | Metadata for observability and tracing. Known keys (trace\_id, trace\_name, span\_name, generation\_name, parent\_span\_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations.                                                                                                                                                                       | `{"trace_id": "trace-abc123","trace_name": "my-app-trace"}`                                                        |
| `user`                | *string*                                                                                                           | :heavy\_minus\_sign: | Unique user identifier                                                                                                                                                                                                                                                                                                                                                                                               | user-123                                                                                                           |
