class

OpenRouter::CompletionRequest

Inherits JSON::Serializable < Reference < Object

Constructors

new(messages : Array(Message), model : String | Nil = nil, tools : Array(Tool) = [] of Tool)
Source
new(prompt : String, model : String | Nil = nil, tools : Array(Tool) = [] of Tool)
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Instance methods

add_tool(tool : Tool)
Source
force_tool_support
Source
force_tool_support=(force_tool_support : Bool)
Source
frequency_penalty

Range: (-2, 2)

Source
frequency_penalty=(frequency_penalty : Float32 | Nil)

Range: (-2, 2)

Source
image_config

Image generation configuration (aspect ratio, size)

Source
image_config=(image_config : ImageConfig | Nil)

Image generation configuration (aspect ratio, size)

Source
logit_bias_key
Source
logit_bias_key=(logit_bias_key : Float32 | Nil)
Source
logit_bias_value
Source
logit_bias_value=(logit_bias_value : Float32 | Nil)
Source
max_tokens

See LLM Parameters (openrouter.ai/docs/parameters)

Source
max_tokens=(max_tokens : Int32 | Nil)

See LLM Parameters (openrouter.ai/docs/parameters)

Source
messages

The chat message history

Source
messages=(messages : Array(Message) | Nil)

The chat message history

Source
min_p

Range: [0, 1]

Source
min_p=(min_p : Float32 | Nil)

Range: [0, 1]

Source
modalities

Output modalities, e.g. ["text"], ["image"], or ["image", "text"] Required for image generation models

Source
modalities=(modalities : Array(String) | Nil)

Output modalities, e.g. ["text"], ["image"], or ["image", "text"] Required for image generation models

Source
model

The model to use.

Browse models at openrouter.ai/models, or use the get_models method of the OpenRouter::Client

Source
model=(model : String | Nil)

The model to use.

Browse models at openrouter.ai/models, or use the get_models method of the OpenRouter::Client

Source
models

for models and route, See "Model Routing" section at openrouter.ai/docs/model-routing

Source
models=(models : Array(String) | Nil)

for models and route, See "Model Routing" section at openrouter.ai/docs/model-routing

Source
presence_penalty

Range: (-2, 2)

Source
presence_penalty=(presence_penalty : Float32 | Nil)

Range: (-2, 2)

Source
prompt

A simple text prompt

Source
prompt=(prompt : String | Nil)

A simple text prompt

Source
provider

See "Provider Routing" section: openrouter.ai/docs/provider-routing

Source
provider=(provider : String | Nil)

See "Provider Routing" section: openrouter.ai/docs/provider-routing

Source
reasoning

Reasoning configuration for models that support reasoning tokens

Source
reasoning=(reasoning : Reasoning | Nil)

Reasoning configuration for models that support reasoning tokens

Source
repetition_penalty

Range: (0, 29)

Source
repetition_penalty=(repetition_penalty : Float32 | Nil)

Range: (0, 29)

Source
respond_with_json
Source
respond_with_json=(respond_with_json : Bool)
Source
route
Source
route=(route : String | Nil)
Source
seed

Advanced optional parameters

Source
seed=(seed : Int32 | Nil)

Advanced optional parameters

Source
stop

the stop tokens

Source
stop=(stop : String | Array(String) | Nil)

the stop tokens

Source
stream

whether to stream the response

Source
stream=(stream : Bool)

whether to stream the response

Source
temperature
Source
temperature=(temperature : Float32 | Nil)
Source
to_json(json : JSON::Builder)

Custom serialization for complex logic

Source
tools

Tool calling Will be passed down as-is for providers implementing OpenAI's interface. For providers with custom interfaces, we transform and map the properties. Otherwise, we transform the tools into a YAML template. The model responds with an assistant message. See models supporting tool calling: openrouter.ai/models?supported_parameters=tools

Source
tools=(tools : Array(Tool))

Tool calling Will be passed down as-is for providers implementing OpenAI's interface. For providers with custom interfaces, we transform and map the properties. Otherwise, we transform the tools into a YAML template. The model responds with an assistant message. See models supporting tool calling: openrouter.ai/models?supported_parameters=tools

Source
top_a

Range: [0, 1]

Source
top_a=(top_a : Float32 | Nil)

Range: [0, 1]

Source
top_k

Range: (1, Infinity) Not available for OpenAI models

Source
top_k=(top_k : Float32 | Nil)

Range: (1, Infinity) Not available for OpenAI models

Source
top_logprobs
Source
top_logprobs=(top_logprobs : Int32 | Nil)
Source
top_p

Range: (0, 1)

Source
top_p=(top_p : Float32 | Nil)

Range: (0, 1)

Source
transforms

Reduce latency by providing the model with a predicted output https://platform.openai.com/docs/guides/latency-optimization#use-predicted-outputs prediction?: { type: 'content'; content: string; };

OpenRouter-only parameters

provider?: ProviderPreferences; // See "Prompt Transforms" section at openrouter.ai/docs/transforms

Source
transforms=(transforms : Array(String) | Nil)

Reduce latency by providing the model with a predicted output https://platform.openai.com/docs/guides/latency-optimization#use-predicted-outputs prediction?: { type: 'content'; content: string; };

OpenRouter-only parameters

provider?: ProviderPreferences; // See "Prompt Transforms" section at openrouter.ai/docs/transforms

Source