class

OpenRouter::Client

Inherits Reference < Object

Client for the OpenRouter API

Constants

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

The api_key is generally required to use the API (though an invalid key seems to allow querying for models.) app_name and app_url are optional and tell OpenRouter about your application. connect_timeout and read_timeout are timeout values in seconds (default: 60.0).

Source

Instance methods

api_key
Source
api_key=(api_key : String)
Source
app_name

It tells OpenRouter which app is using the API see #app_url

Source
app_name=(app_name : String | Nil)

It tells OpenRouter which app is using the API see #app_url

Source
app_url

Together with #app_name it tells OpenRouter which app is using the API

Source
app_url=(app_url : String | Nil)

Together with #app_name it tells OpenRouter which app is using the API

Source
complete(prompt : String, model : String) : Response

Send a completion request for a text prompt using the specified model

Source
complete(request : CompletionRequest) : Response

Send a completion request using the specified CompletionRequest object

Source
connect_timeout

Connection timeout in seconds (default: 60.0)

Source
connect_timeout=(connect_timeout : Float64)

Connection timeout in seconds (default: 60.0)

Source
embed(input : String | Array(String), model : String, dimensions : Int32 | Nil = nil, user : String | Nil = nil, encoding_format : EmbeddingEncodingFormat | Nil = nil) : EmbeddingResponse

Send an embedding request for a single string or array of strings using the specified model

Source
embed(request : EmbeddingRequest) : EmbeddingResponse

Send an embedding request using the specified EmbeddingRequest object

Source
get(endpoint : String) : JSON::Any

Get a specific endpoint

This is a low-level method that is available for edge cases.

Source
get_models

Returns an array of Model structs representing the available models currently supported by OpenRouter

Source
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.

Source
read_timeout

Read timeout in seconds (default: 60.0)

Source
read_timeout=(read_timeout : Float64)

Read timeout in seconds (default: 60.0)

Source