### Installation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/index.html Instructions on how to add the OpenRouter library as a dependency to your Crystal project and install it using shards. ```yaml dependencies: openrouter: github: petterthowsen/openrouter ``` -------------------------------- ### Reasoning Configuration Instance Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Reasoning.html Provides documentation for instance methods that manage the properties of a reasoning configuration object. This includes setting and getting the effort level, enabling/disabling reasoning, excluding tokens, and specifying the maximum number of tokens. ```Crystal def effort : String | Nil # Effort level for reasoning: "high", "medium", or "low" (OpenAI-style) end def effort=(effort : String | Nil) # Effort level for reasoning: "high", "medium", or "low" (OpenAI-style) end def enabled : Bool | Nil # Enable reasoning with default parameters (default: inferred from effort or max_tokens) end def enabled=(enabled : Bool | Nil) # Enable reasoning with default parameters (default: inferred from effort or max_tokens) end def exclude : Bool # Whether to exclude reasoning tokens from response (default: false) end def exclude=(exclude : Bool) # Whether to exclude reasoning tokens from response (default: false) end def max_tokens : Int32 | Nil # Specific token limit for reasoning (Anthropic-style) end def max_tokens=(max_tokens : Int32 | Nil) # Specific token limit for reasoning (Anthropic-style) end ``` -------------------------------- ### OpenRouter API Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Client.html Provides documentation for various OpenRouter API interaction methods, including low-level GET and POST, retrieving models, and sending completion requests. ```APIDOC post(endpoint : String, body : String | Nil) : JSON::Any Post to a specific endpoint. This is a low-level method that is available for edge cases. Parameters: endpoint: The target endpoint string. body: The request body, can be a String or Nil. Returns: JSON::Any representing the API response. get(endpoint : String) : JSON::Any Get a specific endpoint. This is a low-level method that is available for edge cases. Parameters: endpoint: The target endpoint string. Returns: JSON::Any representing the API response. get_models() : Array(Model) Returns an array of Model structs representing the available models currently supported by OpenRouter. complete(prompt : String, model : String) : Response Send a completion request for a text prompt using the specified model. Parameters: prompt: The text prompt to complete. model: The model to use for completion. Returns: A Response object. complete(request : CompletionRequest) : Response Send a completion request using the specified CompletionRequest object. Parameters: request: A CompletionRequest object containing the request details. Returns: A Response object. ``` -------------------------------- ### OpenRouter Client Initialization (Ruby) Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html Demonstrates how to initialize the OpenRouter client with messages, an optional model, and tools. ```Ruby OpenRouter::Client.new(messages, model, tools) ``` -------------------------------- ### OpenRouter Client Initialization and Configuration Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Client.html This section covers the initialization of the OpenRouter client and its configuration options. It includes setting the API key, application name and URL, and connection timeouts. ```APIDOC OpenRouter::Client: BASE_URL = "https://openrouter.ai/api/v1" # Constructors .new(api_key : String, app_name : String | Nil = nil, app_url : String | Nil = nil, connect_timeout : Float64 = 60.0, read_timeout : Float64 = 60.0) Initialize a new OpenRouter::Client. Parameters: api_key: Your OpenRouter API key. app_name: The name of your application (optional). app_url: The URL of your application (optional). connect_timeout: The connection timeout in seconds (default: 60.0). read_timeout: The read timeout in seconds (default: 60.0). # Instance Methods # API Key #attr_reader api_key : String #attr_writer api_key= (api_key : String) # Application Info #attr_reader app_name : String | Nil #attr_writer app_name= (app_name : String | Nil) It tells OpenRouter which app is using the API see #app_url #attr_reader app_url : String | Nil #attr_writer app_url= (app_url : String | Nil) Together with #app_name it tells OpenRouter which app is using the API # Timeouts #attr_reader connect_timeout : Float64 #attr_writer connect_timeout= (connect_timeout : Float64) Connection timeout in seconds (default: 60.0) ``` -------------------------------- ### Get Type as String Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/ToolCall.html Returns the type of an object as a String. ```ruby def type : String # Implementation details... end ``` -------------------------------- ### OpenRouter::Usage API Documentation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Usage.html This section details the OpenRouter::Usage struct, covering its constructors and instance methods. It specifies the types of parameters and return values for each method, along with their purpose. ```APIDOC OpenRouter::Usage: Defined in: openrouter/types/response.cr Constructors: .new(json : JSON::Any) Initializes a new Usage object from JSON data. Instance Methods: #completion : Int32 Returns the completion token count. #prompt : Int32 Returns the prompt token count. #to_json(io : IO) Serializes the Usage object to JSON and writes it to the given IO stream. #to_json(json : JSON::Builder) Serializes the Usage object to JSON using a JSON::Builder. #total : Int32 Returns the total token count. ``` -------------------------------- ### Tool Calls List Management Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Message.html Methods for getting and setting the list of tool calls. Each tool call is represented by a ToolCall object, and the list can be nil. ```APIDOC tool_calls : Array(ToolCall) | Nil tool_calls=(tool_calls : Array(ToolCall) | Nil) ``` -------------------------------- ### Tool Call ID Management Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Message.html Methods for getting and setting the tool call ID, which is an optional string or nil. This is likely used to identify specific tool interactions. ```APIDOC tool_call_id : String | Nil # Optional fields for specific roles tool_call_id=(tool_call_id : String | Nil) # Optional fields for specific roles ``` -------------------------------- ### OpenRouter Client Initialization Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Client.html Initializes a new OpenRouter client. Requires an API key and optionally accepts application name, URL, and timeout values. ```APIDOC OpenRouter::Client.new(api_key : String, app_name : String | Nil = nil, app_url : String | Nil = nil, connect_timeout : Float64 = 60.0, read_timeout : Float64 = 60.0) Initialize a new OpenRouter::Client Parameters: api_key: The API key for authentication (generally required). app_name: Optional name of the application using the API. app_url: Optional URL of the application using the API. connect_timeout: Connection timeout in seconds (default: 60.0). read_timeout: Read timeout in seconds (default: 60.0). ``` -------------------------------- ### OpenRouter::Reasoning Constructors and Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Reasoning.html Provides documentation for the OpenRouter::Reasoning struct, including its constructor, class methods for creating reasoning configurations, and instance methods for managing reasoning parameters. ```APIDOC OpenRouter::Reasoning: struct Value Object # Overview Represents the reasoning configuration for models that support reasoning tokens. # Defined in: openrouter/types/reasoning.cr # Constructors .new(effort : String | Nil = nil, max_tokens : Int32 | Nil = nil, exclude : Bool = false, enabled : Bool | Nil = nil) # Class Method Summary .enabled(exclude : Bool = false) Create a reasoning config with default parameters. .high(exclude : Bool = false) Create a reasoning config with high effort. .low(exclude : Bool = false) Create a reasoning config with low effort. .medium(exclude : Bool = false) Create a reasoning config with medium effort. .with_max_tokens(max_tokens : Int32, exclude : Bool = false) Create a reasoning config with specific max tokens. # Instance Method Summary # effort: String | Nil Effort level for reasoning: "high", "medium", or "low" (OpenAI-style). # effort= (effort : String | Nil) Effort level for reasoning: "high", "medium", or "low" (OpenAI-style). # enabled: Bool | Nil Enable reasoning with default parameters (default: inferred from effort or max_tokens). # enabled= (enabled : Bool | Nil) Enable reasoning with default parameters (default: inferred from effort or max_tokens). # exclude: Bool Whether to exclude reasoning tokens from response (default: false). # exclude= (exclude : Bool) Whether to exclude reasoning tokens from response (default: false). # max_tokens: Int32 | Nil Specific token limit for reasoning (Anthropic-style). # max_tokens= (max_tokens : Int32 | Nil) Specific token limit for reasoning (Anthropic-style). ``` -------------------------------- ### OpenRouter API Instance Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Model.html Details the instance methods available for interacting with the OpenRouter API. This includes methods for accessing model architecture, pricing, and provider-specific limits. ```APIDOC OpenRouter API Instance Methods: architecture_instruct_type: String | Nil Returns the instruction type of the model's architecture. architecture_modality: String Returns the modality of the model's architecture (e.g., text->text). architecture_tokenizer: String Returns the tokenizer used by the model's architecture. context_length: Int32 Returns the context length of the model. created: Int32 Returns the creation timestamp of the model. description: String Returns the description of the model. id: String Returns the unique identifier of the model. name: String Returns the name of the model. per_request_limits_completion_tokens: Int32? Returns the per-request limit for completion tokens, if any. per_request_limits_prompt_tokens: Int32? Returns the per-request limit for prompt tokens, if any. pricing_completion: String Returns the pricing information for completions. pricing_image: String Returns the pricing information for images. pricing_input_cache_read: String Returns the pricing information for input cache reads. pricing_input_cache_write: String Returns the pricing information for input cache writes. pricing_internal_reasoning: String Returns the pricing information for internal reasoning. pricing_prompt: String Returns the pricing information for prompts. pricing_request: String Returns the pricing information for requests. pricing_web_search: String Returns the pricing information for web search. to_s: Returns a nicely readable and concise string representation of this object, typically intended for users. This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations. Also see #inspect. top_provider_context_length: Int32 | Nil Returns the context length provided by the top provider, if available. top_provider_is_moderated: Bool Indicates whether the top provider's content is moderated. top_provider_max_completion_tokens: Int32 | Nil Returns the maximum completion tokens allowed by the top provider, if available. ``` -------------------------------- ### AI Model Configuration Parameters Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html This section details various parameters used for configuring AI models, including model selection, routing, and response generation. It covers parameters like `models`, `provider`, `route`, `prompt`, `stop`, `stream`, and `tools`. ```APIDOC #models : Array(String) | Nil for models and route, See "Model Routing" section at openrouter.ai/docs/model-routing #models=(models : Array(String) | Nil) for models and route, See "Model Routing" section at openrouter.ai/docs/model-routing #prompt : String | Nil A simple text prompt #prompt=(prompt : String | Nil) A simple text prompt #provider : String | Nil See "Provider Routing" section: openrouter.ai/docs/provider-routing #provider=(provider : String | Nil) See "Provider Routing" section: openrouter.ai/docs/provider-routing #route : String | Nil #route=(route : String | Nil) #stop : String | Array(String) | Nil the stop tokens #stop=(stop : String | Array(String) | Nil) the stop tokens #stream : Bool whether to stream the response #stream=(stream : Bool) whether to stream the response #tools : Array(Tool) Tool calling Will be passed down as-is for providers implementing OpenAI's interface. #tools=(tools : Array(Tool)) Tool calling Will be passed down as-is for providers implementing OpenAI's interface. ``` -------------------------------- ### OpenRouter::Function Constructor and Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Function.html This section provides documentation for the OpenRouter::Function class, including its constructor and various instance methods for managing function properties like name, description, and parameters. It also includes methods for JSON serialization. ```APIDOC class OpenRouter::Function # Constructor # Initializes a new Function object. # # @param name [String] The name of the function. # @param description [String | Nil, optional] A description of the function. Defaults to nil. # @param parameters [Array(FunctionParameter), optional] An array of FunctionParameter objects defining the function's parameters. Defaults to an empty array. def self.new(name : String, description : String | Nil = nil, parameters : Array(FunctionParameter) = [] of FunctionParameter) end # Instance Methods # Gets the description of the function. # @return [String | Nil] The function's description. def description : String | Nil end # Sets the description of the function. # @param description [String | Nil] The new description for the function. def description=(description : String | Nil) end # Gets the name of the function. # @return [String] The function's name. def name : String end # Sets the name of the function. # @param name [String] The new name for the function. def name=(name : String) end # Gets the parameters of the function. # @return [Array(FunctionParameter)] An array of the function's parameters. def parameters : Array(FunctionParameter) end # Sets the parameters of the function. # @param parameters [Array(FunctionParameter)] The new array of parameters for the function. def parameters=(parameters : Array(FunctionParameter)) end # Serializes the function object to JSON using an IO stream. # @param io [IO] The IO stream to write the JSON to. def to_json(io : IO) end # Serializes the function object to JSON using a JSON::Builder. # @param json [JSON::Builder] The JSON builder to use for serialization. def to_json(json : JSON::Builder) end end ``` -------------------------------- ### OpenRouter::Tool Constructors Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Tool.html Details the constructors for creating an OpenRouter::Tool object. The first constructor takes a Function object, while the second allows creation using name, description, and parameters. ```APIDOC OpenRouter::Tool: .new(function : Function) Creates a new Tool object from a Function object. .new(name : String, description : String | Nil = nil, parameters : Array(FunctionParameter) = [] of FunctionParameter) Creates a new Tool object with the specified name, description, and parameters. ``` -------------------------------- ### OpenRouter::CompletionRequest Instance Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html Instance methods for configuring and managing a CompletionRequest. These methods allow you to add tools, force tool support, and set various generation parameters like frequency penalty, max tokens, and model. ```APIDOC OpenRouter::CompletionRequest #add_tool(tool : Tool) #force_tool_support : Bool #force_tool_support= (force_tool_support : Bool) #frequency_penalty : Float32 | Nil Range: (-2, 2) #frequency_penalty= (frequency_penalty : Float32 | Nil) Range: (-2, 2) #logit_bias_key : Float32 | Nil #logit_bias_key= (logit_bias_key : Float32 | Nil) #logit_bias_value : Float32 | Nil #logit_bias_value= (logit_bias_value : Float32 | Nil) #max_tokens : Int32 | Nil See LLM Parameters (openrouter.ai/docs/parameters) #max_tokens= (max_tokens : Int32 | Nil) See LLM Parameters (openrouter.ai/docs/parameters) #messages : Array(Message) | Nil The chat message history #messages= (messages : Array(Message) | Nil) The chat message history #min_p : Float32 | Nil Range: [0, 1] #min_p= (min_p : Float32 | Nil) Range: [0, 1] #model : String | Nil The model to use. #model= (model : String | Nil) The model to use. ``` -------------------------------- ### Basic Usage: Text Completion Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/index.html Demonstrates how to create an OpenRouter client instance and perform a simple text completion request. ```crystal require "openrouter" # create a client instance client = OpenRouter::Client.new "sk-or-v1-123456789..." # get a completion from a single text prompt: response = client.complete("Hello, how are you?", "mistralai/mistral-7b-instruct:free") ``` -------------------------------- ### OpenRouter Client Configuration Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Client.html Details on how to access and set configuration properties for the OpenRouter client, including API key, application details, and timeouts. ```APIDOC api_key() : String Returns the current API key. api_key=(api_key : String) Sets the API key. app_name() : String | Nil Returns the application name. It tells OpenRouter which app is using the API see #app_url. app_name=(app_name : String | Nil) Sets the application name. It tells OpenRouter which app is using the API see #app_url. app_url() : String | Nil Returns the application URL. Together with #app_name it tells OpenRouter which app is using the API. app_url=(app_url : String | Nil) Sets the application URL. Together with #app_name it tells OpenRouter which app is using the API. read_timeout() : Float64 Returns the read timeout in seconds (default: 60.0). read_timeout=(read_timeout : Float64) Sets the read timeout in seconds (default: 60.0). connect_timeout() : Float64 Returns the connection timeout in seconds (default: 60.0). connect_timeout=(connect_timeout : Float64) Sets the connection timeout in seconds (default: 60.0). ``` -------------------------------- ### OpenRouter Message Construction and Serialization Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Message.html Provides methods for creating and managing messages within the OpenRouter system. This includes constructors for initializing messages with various parameters like role, content, tool calls, and reasoning details. It also covers instance methods for adding tool calls, accessing and modifying message content, name, role, reasoning, and tool call IDs, as well as utility methods for checking multi-modal content and converting messages to JSON. ```APIDOC OpenRouter Message API: Class Methods: new(role : Role, content : Content | Nil, name : String | Nil = nil, tool_call_id : String | Nil = nil, tool_calls : Array(ToolCall) | Nil = nil, reasoning : String | Nil = nil, reasoning_details : JSON::Any | Nil = nil) Initialize for user/assistant/system messages. new(tool_call : ToolCall) Create a tool result message. Role will be Role::Tool, name will be set to tool_call.name, tool_call_id will be set to tool_call.id, content will be set to serialized string of tool_call.arguments.to_json(). from_json(json : JSON::Any) Instance Methods: add_tool_call(tool_call : ToolCall) add_tool_call(name : String, arguments : Array(ToolCallArgument) = [], tool_call_type : String = "function", tool_call_id : String | Nil = nil) content : Content | Nil content=(content : Content | Nil) content_string : String Get the content, or in case of a multi-modal message, the content of the first part. length : Int32 multi_modal? : Bool Check if content is an Array name : String | Nil name=(name : String | Nil) reasoning : String | Nil Reasoning tokens - visible reasoning trace from the model reasoning=(reasoning : String | Nil) Reasoning tokens - visible reasoning trace from the model reasoning_details : JSON::Any | Nil Reasoning details for preserving reasoning blocks (used in tool calling) reasoning_details=(reasoning_details : JSON::Any | Nil) Reasoning details for preserving reasoning blocks (used in tool calling) role : Role | Nil Common fields role=(role : Role | Nil) Common fields to_json(io : IO) to_json(json : JSON::Builder) tool_call_id : String | Nil Optional fields for specific roles tool_call_id=(tool_call_id : String | Nil) Optional fields for specific roles tool_calls : Array(ToolCall) | Nil tool_calls=(tool_calls : Array(ToolCall) | Nil) ``` -------------------------------- ### OpenRouter API Parameters Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html This section details the various parameters available for configuring models via the OpenRouter API. It covers settings for provider routing, reasoning configuration, repetition penalty, response formatting, routing, seeding, stop tokens, streaming behavior, temperature, tool calling capabilities, and sampling parameters like top_a, top_k, and top_p. ```APIDOC provider=(provider : String | Nil) See "Provider Routing" section: openrouter.ai/docs/provider-routing reasoning : [Reasoning](../OpenRouter/Reasoning.html) | Nil Reasoning configuration for models that support reasoning tokens reasoning=(reasoning : [Reasoning](../OpenRouter/Reasoning.html) | Nil) Reasoning configuration for models that support reasoning tokens repetition_penalty : Float32 | Nil Range: (0, 29) repetition_penalty=(repetition_penalty : Float32 | Nil) Range: (0, 29) respond_with_json : Bool respond_with_json=(respond_with_json : Bool) route : String | Nil route=(route : String | Nil) seed : Int32 | Nil Advanced optional parameters seed=(seed : Int32 | Nil) Advanced optional parameters stop : String | Array(String) | Nil the stop tokens stop=(stop : String | Array(String) | Nil) the stop tokens stream : Bool whether to stream the response stream=(stream : Bool) whether to stream the response temperature : Float32 | Nil temperature=(temperature : Float32 | Nil) to_json(io : IO) to_json(json : JSON::Builder) tools : Array([Tool](../OpenRouter/Tool.html)) 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 tools=(tools : Array([Tool](../OpenRouter/Tool.html))) 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 top_a : Float32 | Nil Range: [0, 1] top_a=(top_a : Float32 | Nil) Range: [0, 1] top_k : Float32 | Nil Range: (1, Infinity) Not available for OpenAI models top_k=(top_k : Float32 | Nil) Range: (1, Infinity) Not available for OpenAI models top_logprobs : Int32 | Nil top_logprobs=(top_logprobs : Int32 | Nil) top_p : Float32 | Nil Range: (0, 1) top_p=(top_p : Float32 | Nil) Range: (0, 1) 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::FunctionDescription API Documentation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/FunctionDescription.html Provides a comprehensive overview of the OpenRouter::FunctionDescription struct, including its definition, constructors, and instance methods. This documentation is generated from CrystalDocs. ```APIDOC struct OpenRouter::FunctionDescription # Defined in: src/openrouter/types/tool.cr:3 # Constructors: # .new(name : String, description : String | Nil = nil) # Instance Methods: # #description : String | Nil # #name : String # #to_json(io : IO) # #to_json(json : JSON::Builder) # Constructor Detail: # def self.new(name : String, description : String | Nil = nil) # [View source](https://github.com/petterthowsen/openrouter/blob/v0.1.0/src/openrouter/types/tool.cr#L7) # # Instance Method Detail: # def description : String | Nil # [View source](https://github.com/petterthowsen/openrouter/blob/v0.1.0/src/openrouter/types/tool.cr#L5) # # def name : String # [View source](https://github.com/petterthowsen/openrouter/blob/v0.1.0/src/openrouter/types/tool.cr#L4) # # def to_json(io : IO) # [View source](https://github.com/petterthowsen/openrouter/blob/v0.1.0/src/openrouter/types/tool.cr#L12) # # def to_json(json : JSON::Builder) # [View source](https://github.com/petterthowsen/openrouter/blob/v0.1.0/src/openrouter/types/tool.cr#L18) end ``` -------------------------------- ### Reasoning Configuration Constructor and Class Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Reasoning.html Defines the constructor for creating reasoning configurations and class methods for setting default effort levels (high, medium, low) and specific token limits. These methods allow for flexible configuration of reasoning parameters. ```Crystal def self.new(effort : String | Nil = nil, max_tokens : Int32 | Nil = nil, exclude : Bool = false, enabled : Bool | Nil = nil) end def self.enabled(exclude : Bool = false) # Create a reasoning config with default parameters end def self.high(exclude : Bool = false) # Create a reasoning config with high effort end def self.low(exclude : Bool = false) # Create a reasoning config with low effort end def self.medium(exclude : Bool = false) # Create a reasoning config with medium effort end def self.with_max_tokens(max_tokens : Int32, exclude : Bool = false) # Create a reasoning config with specific max tokens end ``` -------------------------------- ### OpenRouter::ToolCallArgument API Documentation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/ToolCallArgument.html Provides a comprehensive overview of the OpenRouter::ToolCallArgument struct, including its constructors, class methods, and instance methods. This documentation covers how to create instances with different value types (JSON::Any or String), convert them to JSON, and access their properties. ```APIDOC struct OpenRouter::ToolCallArgument # Defined in: openrouter/types/tool_call.cr # Constructors: # Creates a new ToolCallArgument with a name and a JSON::Any value. new(name : String, value : JSON::Any) # Creates a new ToolCallArgument with a name and a String value. new(name : String, value : String) # Class Methods: # Creates a ToolCallArgument instance from JSON data. from_json(json : JSON::Any) # Instance Methods: # Returns the name of the tool call argument. name : String # Serializes the ToolCallArgument to an IO stream. to_json(io : IO) # Serializes the ToolCallArgument to a JSON::Builder. to_json(json : JSON::Builder) # Returns the value of the tool call argument as JSON::Any. value : JSON::Any end ``` -------------------------------- ### OpenRouter::Choice API Documentation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Choice.html This section details the OpenRouter::Choice struct, an abstract base class for various choice types within the OpenRouter library. It covers its constructors, instance methods like `finish_reason` and `to_json`, and lists its direct known subclasses. ```APIDOC OpenRouter::Choice ================== * [OpenRouter::Choice](../OpenRouter/Choice.html) * Struct * Value * Object [](#direct-known-subclasses)Direct Known Subclasses --------------------------------------------------- * [OpenRouter::NonChatChoice](../OpenRouter/NonChatChoice.html) * [OpenRouter::NonStreamingChoice](../OpenRouter/NonStreamingChoice.html) * [OpenRouter::StreamingChoice](../OpenRouter/StreamingChoice.html) [](#defined-in)Defined in: -------------------------- openrouter/types/response.cr [](#constructors)Constructors ----------------------------- * [**.new**(json : JSON::Any)](#new%28json%3AJSON%3A%3AAny%29-class-method) [](#instance-method-summary)Instance Method Summary --------------------------------------------------- * [**#finish_reason** : String | Nil](#finish_reason%3AString%7CNil-instance-method) * [**#to_json**(io : IO)](#to_json%28io%3AIO%29-instance-method) * [**#to_json**(json : JSON::Builder)](#to_json%28json%3AJSON%3A%3ABuilder%29-instance-method) [](#constructor-detail)Constructor Detail ----------------------------------------- def self.**new**(json : JSON::Any) [#](#new%28json%3AJSON%3A%3AAny%29-class-method) [](#instance-method-detail)Instance Method Detail ------------------------------------------------- def **finish_reason** : String | Nil [#](#finish_reason%3AString%7CNil-instance-method) abstract def **to_json**(io : IO) [#](#to_json%28io%3AIO%29-instance-method) abstract def **to_json**(json : JSON::Builder) [#](#to_json%28json%3AJSON%3A%3ABuilder%29-instance-method) ``` -------------------------------- ### OpenRouter::Response API Documentation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Response.html Provides a comprehensive overview of the OpenRouter::Response struct, detailing its constructors, class methods like `from_request`, and instance methods for accessing response data such as choices, creation timestamp, ID, model, and usage information. It also covers JSON serialization methods. ```APIDOC struct OpenRouter::Response # Constructors # Initializes a new instance from JSON data. # Parameters: # json: JSON::Any - The JSON data representing the response. new(json : JSON::Any) # Class Methods # Creates a Response object from a completion request and its JSON response. # Parameters: # request: CompletionRequest - The original completion request. # response_json: JSON::Any - The JSON data of the response. # Returns: OpenRouter::Response from_request(request : CompletionRequest, response_json : JSON::Any) # Instance Methods # Returns an array of choices from the response. # Returns: Array(Choice) choices : Array(Choice) # Returns the creation timestamp of the response. # Returns: Int32 created : Int32 # Returns the ID of the response, or nil if not available. # Returns: String | Nil id : String | Nil # Returns the model used for the response. # Returns: String model : String # Serializes the response object to JSON using an IO stream. # Parameters: # io: IO - The IO stream to write the JSON to. to_json(io : IO) # Serializes the response object to JSON using a JSON::Builder. # Parameters: # json: JSON::Builder - The JSON builder to use. to_json(json : JSON::Builder) # Returns the usage data associated with the response, or nil if not available. # Usage data is always returned for non-streaming responses. For streaming responses, # a single usage object is returned at the end with an empty choices array. # Returns: Usage | Nil usage : Usage | Nil end ``` -------------------------------- ### OpenRouter::CompletionRequest Constructors Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html Constructors for creating a new CompletionRequest object. You can initialize it with a list of messages or a single prompt string, optionally specifying the model and tools. ```APIDOC OpenRouter::CompletionRequest .new(messages : Array(Message), model : String | Nil = nil, tools : Array(Tool) = [] of Tool) .new(prompt : String, model : String | Nil = nil, tools : Array(Tool) = [] of Tool) ``` -------------------------------- ### OpenRouter API Parameters Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html This section details the various parameters available for configuring the OpenRouter API, including model selection, prompt management, and generation controls. ```APIDOC OpenRouter-only parameters: provider?: ProviderPreferences; // See "Prompt Transforms" section at openrouter.ai/docs/transforms #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; }; Constructor Detail: def self.new(messages : Array([Message](../OpenRouter/Message.html)), model : String | Nil = nil, tools : Array([Tool](../OpenRouter/Tool.html)) = [] of Tool) def self.new(prompt : String, model : String | Nil = nil, tools : Array([Tool](../OpenRouter/Tool.html)) = [] of Tool) Instance Method Detail: def add_tool(tool : [Tool](../OpenRouter/Tool.html)) def force_tool_support : Bool def force_tool_support=(force_tool_support : Bool) def frequency_penalty : Float32 | Nil Range: (-2, 2) def frequency_penalty=(frequency_penalty : Float32 | Nil) Range: (-2, 2) def logit_bias_key : Float32 | Nil def logit_bias_key=(logit_bias_key : Float32 | Nil) def logit_bias_value : Float32 | Nil def logit_bias_value=(logit_bias_value : Float32 | Nil) def max_tokens : Int32 | Nil See LLM Parameters (openrouter.ai/docs/parameters) def max_tokens=(max_tokens : Int32 | Nil) See LLM Parameters (openrouter.ai/docs/parameters) def messages : Array([Message](../OpenRouter/Message.html)) | Nil The chat message history def messages=(messages : Array([Message](../OpenRouter/Message.html)) | Nil) The chat message history def min_p : Float32 | Nil Range: [0, 1] def min_p=(min_p : Float32 | Nil) Range: [0, 1] def model : String | Nil The model to use. Browse models at openrouter.ai/models, or use the `get_models` method of the OpenRouter::Client def model=(model : String | Nil) The model to use. Browse models at openrouter.ai/models, or use the `get_models` method of the OpenRouter::Client def models : Array(String) | Nil for models and route, See "Model Routing" section at openrouter.ai/docs/model-routing def models=(models : Array(String) | Nil) for models and route, See "Model Routing" section at openrouter.ai/docs/model-routing def presence_penalty : Float32 | Nil Range: (-2, 2) def presence_penalty=(presence_penalty : Float32 | Nil) Range: (-2, 2) def prompt : String | Nil A simple text prompt def prompt=(prompt : String | Nil) A simple text prompt def provider : String | Nil See "Provider Routing" section: openrouter.ai/docs/provider-routing ``` -------------------------------- ### OpenRouter::NonChatChoice API Documentation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/NonChatChoice.html Provides details on the OpenRouter::NonChatChoice struct, including its constructors and instance methods. It also lists inherited methods from the OpenRouter::Choice struct. ```APIDOC OpenRouter::NonChatChoice Struct Value Object Defined in: openrouter/types/response.cr Constructors: .new(json : JSON::Any) Instance Methods: #text : String #to_json(io : IO) #to_json(json : JSON::Builder) Inherited Instance Methods from OpenRouter::Choice: #finish_reason : String | Nil #to_json(io : IO) #to_json(json : JSON::Builder) Inherited Constructor Methods from OpenRouter::Choice: .new(json : JSON::Any) Constructor Detail: def self.new(json : JSON::Any) Instance Method Detail: def text : String def to_json(io : IO) def to_json(json : JSON::Builder) ``` -------------------------------- ### OpenRouter::Tool Instance Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/Tool.html Describes the instance methods available for OpenRouter::Tool objects, including methods for accessing and modifying the associated Function object, converting the object to JSON, and managing its type. ```APIDOC OpenRouter::Tool: #function : Function Returns the associated Function object. #function=(function : Function) Sets the associated Function object. #to_json(io : IO) Serializes the Tool object to JSON and writes it to the given IO. #to_json(json : JSON::Builder) Serializes the Tool object to JSON using a JSON::Builder. #type : String Returns the type of the tool. #type=(type : String) Sets the type of the tool. ``` -------------------------------- ### OpenRouter::FunctionParameter API Documentation Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/FunctionParameter.html Provides a comprehensive reference for the OpenRouter::FunctionParameter class, detailing its constructors, properties, and JSON serialization methods. ```APIDOC class OpenRouter::FunctionParameter # Constructor to create a new FunctionParameter. # # @param name [String] The name of the parameter. # @param type [String] The data type of the parameter (e.g., 'string', 'integer', 'boolean', 'array'). # @param description [String] A description of what the parameter represents. # @param required [Bool] Whether the parameter is required (defaults to false). # @param items_type [String | Nil] If the type is 'array', this specifies the type of items in the array. new(name : String, type : String, description : String, required : Bool = false, items_type : String | Nil = nil) # Gets the description of the parameter. # @return [String] The parameter description. description : String # Sets the description of the parameter. # @param description [String] The new description for the parameter. description= (description : String) # Gets the type of items if the parameter is an array. # @return [String | Nil] The type of items in the array, or nil if not an array or not specified. items_type : String | Nil # Sets the type of items for an array parameter. # @param items_type [String | Nil] The new item type for the array parameter. items_type= (items_type : String | Nil) # Gets the name of the parameter. # @return [String] The parameter name. name : String # Sets the name of the parameter. # @param name [String] The new name for the parameter. name= (name : String) # Checks if the parameter is required. # @return [Bool] True if the parameter is required, false otherwise. required : Bool # Sets whether the parameter is required. # @param required [Bool] Set to true if the parameter is required, false otherwise. required= (required : Bool) # Serializes the FunctionParameter object to JSON using an IO stream. # @param io [IO] The IO stream to write the JSON to. to_json(io : IO) # Serializes the FunctionParameter object to JSON using a JSON::Builder. # @param json [JSON::Builder] The JSON builder to use for serialization. to_json(json : JSON::Builder) # Gets the data type of the parameter. # @return [String] The parameter data type. type : String # Sets the data type of the parameter. # @param type [String] The new data type for the parameter. type= (type : String) end ``` -------------------------------- ### OpenRouter::StreamingChoice Constructor and Methods Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/StreamingChoice.html Details the constructor and instance methods for the OpenRouter::StreamingChoice struct, including how to create a new instance from JSON and methods for JSON serialization. It also inherits methods from OpenRouter::Choice. ```APIDOC OpenRouter::StreamingChoice __init__(json : JSON::Any) Constructs a new StreamingChoice instance from JSON data. #delta : Message Returns the partial message content in a streaming response. #to_json(io : IO) Serializes the StreamingChoice object to an IO stream. #to_json(json : JSON::Builder) Serializes the StreamingChoice object using a JSON::Builder. Inherited from OpenRouter::Choice: #finish_reason : String | Nil The reason for finishing the response. #to_json(io : IO) Serializes the Choice object to an IO stream. #to_json(json : JSON::Builder) Serializes the Choice object using a JSON::Builder. __init__(json : JSON::Any) Constructs a new Choice instance from JSON data. ``` -------------------------------- ### AI Model Response Tuning Parameters Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html This section covers parameters that fine-tune the AI model's response generation, including penalties, temperature, and top-k/top-p sampling. It also includes parameters for JSON output and seeding. ```APIDOC #presence_penalty : Float32 | Nil Range: (-2, 2) #presence_penalty=(presence_penalty : Float32 | Nil) Range: (-2, 2) #repetition_penalty : Float32 | Nil Range: (0, 29) #repetition_penalty=(repetition_penalty : Float32 | Nil) Range: (0, 29) #respond_with_json : Bool #respond_with_json=(respond_with_json : Bool) #seed : Int32 | Nil ### [](#advanced-optional-parameters)Advanced optional parameters #seed=(seed : Int32 | Nil) ### [](#advanced-optional-parameters)Advanced optional parameters #temperature : Float32 | Nil #temperature=(temperature : Float32 | Nil) #top_a : Float32 | Nil Range: [0, 1] #top_a=(top_a : Float32 | Nil) Range: [0, 1] #top_k : Float32 | Nil Range: (1, Infinity) Not available for OpenAI models #top_k=(top_k : Float32 | Nil) Range: (1, Infinity) Not available for OpenAI models #top_logprobs : Int32 | Nil #top_logprobs=(top_logprobs : Int32 | Nil) #top_p : Float32 | Nil Range: (0, 1) #top_p=(top_p : Float32 | Nil) Range: (0, 1) ``` -------------------------------- ### AI Model Serialization and Reasoning Source: https://github.com/petterthowsen/petterthowsen.github.io/blob/master/OpenRouter/CompletionRequest.html This section covers methods for serializing AI model configurations to JSON and configuring reasoning capabilities. It includes `to_json` methods and the `reasoning` parameter. ```APIDOC #reasoning : Reasoning | Nil Reasoning configuration for models that support reasoning tokens #reasoning=(reasoning : Reasoning | Nil) Reasoning configuration for models that support reasoning tokens #to_json(io : IO) #to_json(json : JSON::Builder) ```