ChatRequest - Go SDK
ChatRequest - Go SDK
ChatRequest type definition
The Go SDK and docs are currently in beta. Report issues on GitHub.
Chat completion request parameters
Fields
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
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} |
FrequencyPenalty | optionalnullable.OptionalNullable[float64] | ➖ | Frequency penalty (-2.0 to 2.0) | 0 |
ImageConfig | map[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"} |
LogitBias | optionalnullable.OptionalNullable[map[string]float64] | ➖ | Token logit bias adjustments | {"50256": -100} |
Logprobs | optionalnullable.OptionalNullable[bool] | ➖ | Return log probabilities | false |
MaxCompletionTokens | optionalnullable.OptionalNullable[int64] | ➖ | Maximum tokens in completion | 100 |
MaxTokens | optionalnullable.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"}] |
Metadata | map[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"} |
MinP | optionalnullable.OptionalNullable[float64] | ➖ | Minimum probability threshold relative to the most likely token. Tokens with probability below min_p * (probability of top token) are filtered out. Not all providers support this parameter. | 0.1 |
Modalities | []components.Modality | ➖ | Output modalities for the response. Supported values are “text”, “image”, and “audio”. | [ “text”, “image” ] |
Model | *string | ➖ | Model to use for completion | openai/gpt-4 |
Models | []string | ➖ | Models to use for completion | [ “openai/gpt-4”, “openai/gpt-4o” ] |
ParallelToolCalls | optionalnullable.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. | |
PresencePenalty | optionalnullable.OptionalNullable[float64] | ➖ | Presence penalty (-2.0 to 2.0) | 0 |
Provider | optionalnullable.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"} |
ReasoningEffort | optionalnullable.OptionalNullable[components.ChatRequestReasoningEffort] | ➖ | Shorthand for setting reasoning effort. Equivalent to setting reasoning.effort. Cannot be used simultaneously with reasoning.effort if they differ. | medium |
RepetitionPenalty | optionalnullable.OptionalNullable[float64] | ➖ | Penalizes tokens based on how much they have already appeared in the text. A value of 1.0 means no penalty. Values above 1.0 penalize repeated tokens more strongly. Not all providers support this parameter. | 1 |
ResponseFormat | *components.ResponseFormat | ➖ | Response format configuration | {"type": "json_object"} |
Seed | optionalnullable.OptionalNullable[int64] | ➖ | Random seed for deterministic outputs | 42 |
ServiceTier | optionalnullable.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. | |
Stop | optionalnullable.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 response | false |
StreamOptions | optionalnullable.OptionalNullable[components.ChatStreamOptions] | ➖ | Streaming configuration options | {"include_usage": true} |
Temperature | optionalnullable.OptionalNullable[float64] | ➖ | Sampling temperature (0-2) | 0.7 |
ToolChoice | *components.ChatToolChoice | ➖ | Tool choice configuration | auto |
Tools | []components.ChatFunctionTool | ➖ | Available tools for function calling | [{"function": {"description": "Get weather","name": "get_weather"},“type”: “function” } ] |
TopA | optionalnullable.OptionalNullable[float64] | ➖ | Consider only tokens with “sufficiently high” probabilities based on the probability of the most likely token. Not all providers support this parameter. | 0 |
TopK | optionalnullable.OptionalNullable[int64] | ➖ | Limits the model to choose from the top K most likely tokens at each step. A value of 1 means the model will always pick the most likely next token. Not all providers support this parameter. | 40 |
TopLogprobs | optionalnullable.OptionalNullable[int64] | ➖ | Number of top log probabilities to return (0-20) | 5 |
TopP | optionalnullable.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 identifier | user-123 |