Class: LLM::OpenRouter

Inherits:
OpenAI show all
Defined in:
lib/llm/providers/openrouter.rb

Overview

The OpenRouter class implements a provider for OpenRouter through its OpenAI-compatible API.

Examples:

#!/usr/bin/env ruby
require "llm"

llm = LLM.openrouter(key: ENV["KEY"])
ctx = LLM::Context.new(llm)
ctx.talk "Hello"

Constant Summary collapse

HOST =
"openrouter.ai"
BASE_PATH =
"/api/v1"

Instance Method Summary collapse

Methods inherited from OpenAI

#adapt_function, #assistant_role, #complete, #models, #responses, #server_tools, #web_search

Methods included from LLM::OpenAI::RequestAdapter

#adapt

Methods inherited from Provider

#adapt_function, #assistant_role, #build_messages, #chat, #complete, #developer_role, #inspect, #interrupt!, #key?, #models, #ocr, #registry, #request_owner, #respond, #responses, #schema, #server_tool, #server_tools, #system_role, #tool_role, #tracer, #tracer=, #user_role, #web_search, #with, #with_tracer

Constructor Details

#initialize(host: HOST, base_path: BASE_PATH) ⇒ LLM::OpenRouter

Parameters:

  • key (String, nil)

    The secret key for authentication

  • host (String) (defaults to: HOST)

    The host address of the LLM provider

  • base_path (String) (defaults to: BASE_PATH)

    Optional base path prefix for HTTP API routes.



26
27
28
# File 'lib/llm/providers/openrouter.rb', line 26

def initialize(host: HOST, base_path: BASE_PATH, **)
  super
end

Instance Method Details

#audioObject

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/llm/providers/openrouter.rb', line 63

def audio
  raise NotImplementedError
end

#default_modelString

Returns the default model for chat completions

Returns:

  • (String)

See Also:



83
84
85
# File 'lib/llm/providers/openrouter.rb', line 83

def default_model
  "openrouter/auto"
end

#embed(input, model: "openai/text-embedding-3-small", **params) ⇒ LLM::Response

Provides an embedding.

Parameters:

  • input (String, Array<String>)

    The input to embed

  • model (String) (defaults to: "openai/text-embedding-3-small")

    The embedding model to use

  • params (Hash)

    Other embedding parameters

Returns:

See Also:



45
46
47
# File 'lib/llm/providers/openrouter.rb', line 45

def embed(input, model: "openai/text-embedding-3-small", **params)
  super
end

#filesObject

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/llm/providers/openrouter.rb', line 51

def files
  raise NotImplementedError
end

#imagesObject

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/llm/providers/openrouter.rb', line 57

def images
  raise NotImplementedError
end

#moderationsObject

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/llm/providers/openrouter.rb', line 69

def moderations
  raise NotImplementedError
end

#nameSymbol

Returns the provider's name

Returns:

  • (Symbol)

    Returns the provider's name



33
34
35
# File 'lib/llm/providers/openrouter.rb', line 33

def name
  :openrouter
end

#vector_storesObject

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/llm/providers/openrouter.rb', line 75

def vector_stores
  raise NotImplementedError
end