class OpenRouter::Client

Overview

Client for the OpenRouter API

Defined in:

openrouter/client.cr

Constant Summary

BASE_URL = "https://openrouter.ai/api/v1"

Constructors

Instance Method Summary

Constructor Detail

def self.new(api_key : String, app_name : String | Nil = nil, app_url : String | Nil = nil) #

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.


[View source]

Instance Method Detail

def api_key : String #

[View source]
def api_key=(api_key : String) #

[View source]
def app_name : String | Nil #

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


[View source]
def app_name=(app_name : String | Nil) #

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


[View source]
def app_url : String | Nil #

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


[View source]
def app_url=(app_url : String | Nil) #

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


[View source]
def complete(prompt : String, model : String) : Response #

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


[View source]
def complete(request : CompletionRequest) : Response #

Send a completion request using the specified CompletionRequest object


[View source]
def get(endpoint : String) : JSON::Any #

Get a specific endpoint

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


[View source]
def get_models : Array(Model) #

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


[View source]
def 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.


[View source]