Class: ActiveAgent::Providers::OpenRouter::Options

Inherits:
ActiveAgent::Providers::OpenAI::Options show all
Defined in:
lib/active_agent/providers/open_router/options.rb

Overview

Configuration options for OpenRouter provider

Extends OpenAI::Options with OpenRouter-specific settings including HTTP-Referer and X-Title headers for app identification and ranking.

Examples:

Basic configuration

options = Options.new(
  api_key: 'sk-or-v1-...',
  app_name: 'MyApp',
  site_url: 'https://myapp.com'
)

Rails auto-configuration

# Automatically resolves app_name from Rails.application
# and site_url from routes.default_url_options
options = Options.new(api_key: ENV['OPENROUTER_API_KEY'])

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Common::BaseModel

#<=>, #==, attribute, #deep_compact, #deep_dup, delegate_attributes, drop_attributes, inherited, #inspect, keys, #merge!, required_attributes, #to_h, #to_hash

Constructor Details

#initialize(kwargs = {}) ⇒ Options

Creates new OpenRouter options with auto-resolution

Automatically resolves app_name from Rails application name and site_url from Rails routes/ActionMailer default_url_options.

Parameters:

  • kwargs (Hash) (defaults to: {})

    configuration options

Options Hash (kwargs):

  • :api_key (String)

    OpenRouter API key

  • :app_name (String)

    application name for rankings

  • :site_url (String)

    site URL for rankings



53
54
55
56
57
58
59
60
# File 'lib/active_agent/providers/open_router/options.rb', line 53

def initialize(kwargs = {})
  kwargs = kwargs.deep_symbolize_keys if kwargs.respond_to?(:deep_symbolize_keys)

  super(**deep_compact(kwargs.merge(
    app_name: kwargs[:app_name] || resolve_app_name(kwargs),
    site_url: kwargs[:site_url] || resolve_site_url(kwargs),
  )))
end

Instance Attribute Details

#app_nameString

Returns application name for X-Title header (default: “ActiveAgent” or Rails app name).

Returns:

  • (String)

    application name for X-Title header (default: “ActiveAgent” or Rails app name)



37
# File 'lib/active_agent/providers/open_router/options.rb', line 37

attribute :app_name, :string, fallback: "ActiveAgent"

#base_urlString

Returns API endpoint (default: “openrouter.ai/api/v1”).

Returns:



33
# File 'lib/active_agent/providers/open_router/options.rb', line 33

attribute :base_url, :string, as: "https://openrouter.ai/api/v1"

#site_urlString

Returns site URL for HTTP-Referer header (default: “activeagents.ai/” or Rails URL).

Returns:

  • (String)

    site URL for HTTP-Referer header (default: “activeagents.ai/” or Rails URL)



41
# File 'lib/active_agent/providers/open_router/options.rb', line 41

attribute :site_url, :string, fallback: "https://activeagents.ai/"

Instance Method Details

#extra_headersHash

Returns extra headers for OpenRouter API

Maps app_name and site_url to OpenRouter’s required headers:

  • HTTP-Referer: site_url

  • X-Title: app_name

Returns:

  • (Hash)

    headers hash



78
79
80
81
82
83
# File 'lib/active_agent/providers/open_router/options.rb', line 78

def extra_headers
  deep_compact(
    "http-referer" => site_url.presence,
    "x-title"      => app_name.presence
  )
end

#serializeHash

Serializes options for API requests

Excludes app_name and site_url as they’re sent via headers.

Returns:

  • (Hash)

    serialized options



67
68
69
# File 'lib/active_agent/providers/open_router/options.rb', line 67

def serialize
  super.except(:app_name, :site_url)
end