For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
    • Overview
    • Usage for Agents
  • TypeScript SDK
    • Overview
      • Analytics
      • APIKeys
      • Byok
      • Chat
      • Credits
      • Embeddings
      • Endpoints
      • Generations
      • Guardrails
        • Models
        • ChatRequest
      • OAuth
      • Observability
      • Organization
      • Presets
      • Providers
      • Rerank
      • Beta.Responses
      • Transcriptions
      • Speech
      • VideoGeneration
      • Workspaces
  • Python SDK
    • Overview
  • Go SDK
  • DevTools
    • Overview
    • Migrating to @openrouter/agent
LogoLogo
ModelsChatRankingsDocs
On this page
  • Example Usage
  • Fields
TypeScript SDKAPI ReferenceModels

ChatRequest - TypeScript SDK

ChatRequest type definition
Was this page helpful?
Previous

OAuth - TypeScript SDK

OAuth method reference
Next
Built with

The TypeScript SDK and docs are currently in beta. Report issues on GitHub.

Chat completion request parameters

Example Usage

1import { ChatRequest } from "@openrouter/sdk/models";
2
3let value: ChatRequest = {
4 messages: [
5 {
6 content: "You are a helpful assistant.",
7 role: "system",
8 },
9 {
10 content: "What is the capital of France?",
11 role: "user",
12 },
13 ],
14};

Fields

FieldTypeRequiredDescriptionExample
cacheControlmodels.AnthropicCacheControlDirective➖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"}
debugmodels.ChatDebugOptions➖Debug options for inspecting request transformations (streaming only){"echo_upstream_body": true}
frequencyPenaltynumber➖Frequency penalty (-2.0 to 2.0)0
imageConfigRecord<string, *models.ImageConfig*>➖Provider-specific image configuration options. Keys and values vary by model/provider. See https://openrouter.ai/docs/guides/overview/multimodal/image-generation for more details.{"aspect_ratio": "16:9","quality": "high"}
logitBiasRecord<string, *number*>➖Token logit bias adjustments{"50256": -100}
logprobsboolean➖Return log probabilitiesfalse
maxCompletionTokensnumber➖Maximum tokens in completion100
maxTokensnumber➖Maximum tokens (deprecated, use max_completion_tokens). Note: some providers enforce a minimum of 16.100
messagesmodels.ChatMessages[]✔️List of messages for the conversation[
{"content": "Hello!","role": "user"}
]
metadataRecord<string, *string*>➖Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values){"session_id": "session-456","user_id": "user-123"}
modalitiesmodels.Modality[]➖Output modalities for the response. Supported values are “text”, “image”, and “audio”.[
“text”,
“image”
]
modelstring➖Model to use for completionopenai/gpt-4
modelsstring[]➖Models to use for completion[
“openai/gpt-4”,
“openai/gpt-4o”
]
parallelToolCallsboolean➖Whether to enable parallel function calling during tool use. When true, the model may generate multiple tool calls in a single response.true
pluginsmodels.ChatRequestPlugin[]➖Plugins you want to enable for this request, including their settings.
presencePenaltynumber➖Presence penalty (-2.0 to 2.0)0
providermodels.ProviderPreferences➖When multiple model providers are available, optionally indicate your routing preference.{"allow_fallbacks": true}
reasoningmodels.ChatRequestReasoning➖Configuration options for reasoning models{"effort": "medium","summary": "concise"}
responseFormatmodels.ResponseFormat➖Response format configuration{"type": "json_object"}
seednumber➖Random seed for deterministic outputs42
serviceTiermodels.ChatRequestServiceTier➖The service tier to use for processing this request.auto
sessionIdstring➖A unique identifier for grouping related requests (e.g., a conversation or agent workflow) for observability. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters.
stopmodels.Stop➖Stop sequences (up to 4)[
""
]
stopServerToolsWhenmodels.StopServerToolsWhenCondition[]➖Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides max_tool_calls.[
{"step_count": 5,"type": "step_count_is"},
{"max_cost_in_dollars": 0.5,"type": "max_cost"}
]
streamboolean➖Enable streaming responsefalse
streamOptionsmodels.ChatStreamOptions➖Streaming configuration options{"include_usage": true}
temperaturenumber➖Sampling temperature (0-2)0.7
toolChoicemodels.ChatToolChoice➖Tool choice configurationauto
toolsmodels.ChatFunctionTool[]➖Available tools for function calling[
{"function": {"description": "Get weather","name": "get_weather"},
“type”: “function”
}
]
topLogprobsnumber➖Number of top log probabilities to return (0-20)5
topPnumber➖Nucleus sampling parameter (0-1)1
tracemodels.TraceConfig➖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"}
userstring➖Unique user identifieruser-123