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
  • Python SDK
    • Overview
  • Go SDK
      • Analytics
      • APIKeys
      • Byok
      • Chat
      • Credits
      • Datasets
      • Embeddings
      • Endpoints
      • Generations
      • Guardrails
        • Models
        • ChatRequest
      • OAuth
      • Observability
      • Organization
      • Presets
      • Providers
      • Rerank
      • Beta.Responses
      • Transcriptions
      • Speech
      • VideoGeneration
      • Workspaces
  • DevTools
    • Overview
    • Migrating to @openrouter/agent
LogoLogo
ModelsChatRankingsDocs
On this page
  • Fields
Go SDKAPI ReferenceModels

ChatRequest - Go SDK

ChatRequest type definition
Was this page helpful?
Previous

OAuth - Go SDK

OAuth method reference
Next
Built with

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

Chat completion request parameters

Fields

FieldTypeRequiredDescriptionExample
CacheControl*components.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"}
Debug*components.ChatDebugOptions➖Debug options for inspecting request transformations (streaming only){"echo_upstream_body": true}
FrequencyPenaltyoptionalnullable.OptionalNullable[float64]➖Frequency penalty (-2.0 to 2.0)0
ImageConfigmap[string]components.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"}
LogitBiasoptionalnullable.OptionalNullable[map[string]float64]➖Token logit bias adjustments{"50256": -100}
Logprobsoptionalnullable.OptionalNullable[bool]➖Return log probabilitiesfalse
MaxCompletionTokensoptionalnullable.OptionalNullable[int64]➖Maximum tokens in completion100
MaxTokensoptionalnullable.OptionalNullable[int64]➖Maximum tokens (deprecated, use max_completion_tokens). Note: some providers enforce a minimum of 16.100
Messages[]components.ChatMessages✔️List of messages for the conversation[
{"content": "Hello!","role": "user"}
]
Metadatamap[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"}
Modalities[]components.Modality➖Output modalities for the response. Supported values are “text”, “image”, and “audio”.[
“text”,
“image”
]
Model*string➖Model to use for completionopenai/gpt-4
Models[]string➖Models to use for completion[
“openai/gpt-4”,
“openai/gpt-4o”
]
ParallelToolCallsoptionalnullable.OptionalNullable[bool]➖Whether to enable parallel function calling during tool use. When true, the model may generate multiple tool calls in a single response.true
Plugins[]components.ChatRequestPlugin➖Plugins you want to enable for this request, including their settings.
PresencePenaltyoptionalnullable.OptionalNullable[float64]➖Presence penalty (-2.0 to 2.0)0
Provideroptionalnullable.OptionalNullable[components.ProviderPreferences]➖When multiple model providers are available, optionally indicate your routing preference.{"allow_fallbacks": true}
Reasoning*components.ChatRequestReasoning➖Configuration options for reasoning models{"effort": "medium","summary": "concise"}
ResponseFormat*components.ResponseFormat➖Response format configuration{"type": "json_object"}
Seedoptionalnullable.OptionalNullable[int64]➖Random seed for deterministic outputs42
ServiceTieroptionalnullable.OptionalNullable[components.ChatRequestServiceTier]➖The service tier to use for processing this request.auto
SessionID*string➖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.
Stopoptionalnullable.OptionalNullable[components.Stop]➖Stop sequences (up to 4)[
""
]
StopServerToolsWhen[]components.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"}
]
Stream*bool➖Enable streaming responsefalse
StreamOptionsoptionalnullable.OptionalNullable[components.ChatStreamOptions]➖Streaming configuration options{"include_usage": true}
Temperatureoptionalnullable.OptionalNullable[float64]➖Sampling temperature (0-2)0.7
ToolChoice*components.ChatToolChoice➖Tool choice configurationauto
Tools[]components.ChatFunctionTool➖Available tools for function calling[
{"function": {"description": "Get weather","name": "get_weather"},
“type”: “function”
}
]
TopLogprobsoptionalnullable.OptionalNullable[int64]➖Number of top log probabilities to return (0-20)5
TopPoptionalnullable.OptionalNullable[float64]➖Nucleus sampling parameter (0-1)1
Trace*components.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"}
User*string➖Unique user identifieruser-123