88module ActiveAgent
99 module Providers
1010 module OpenRouter
11+ # Configuration options for OpenRouter provider
12+ #
13+ # Extends OpenAI::Options with OpenRouter-specific settings including
14+ # HTTP-Referer and X-Title headers for app identification and ranking.
15+ #
16+ # @example Basic configuration
17+ # options = Options.new(
18+ # api_key: 'sk-or-v1-...',
19+ # app_name: 'MyApp',
20+ # site_url: 'https://myapp.com'
21+ # )
22+ #
23+ # @example Rails auto-configuration
24+ # # Automatically resolves app_name from Rails.application
25+ # # and site_url from routes.default_url_options
26+ # options = Options.new(api_key: ENV['OPENROUTER_API_KEY'])
27+ #
28+ # @see https://openrouter.ai/docs/api-keys OpenRouter API Keys
29+ # @see https://openrouter.ai/docs/rankings OpenRouter App Rankings
1130 class Options < ActiveAgent ::Providers ::OpenAI ::Options
31+ # @!attribute base_url
32+ # @return [String] API endpoint (default: "https://openrouter.ai/api/v1")
1233 attribute :base_url , :string , as : "https://openrouter.ai/api/v1"
34+
35+ # @!attribute app_name
36+ # @return [String] application name for X-Title header (default: "ActiveAgent" or Rails app name)
1337 attribute :app_name , :string , fallback : "ActiveAgent"
38+
39+ # @!attribute site_url
40+ # @return [String] site URL for HTTP-Referer header (default: "https://activeagents.ai/" or Rails URL)
1441 attribute :site_url , :string , fallback : "https://activeagents.ai/"
1542
43+ # Creates new OpenRouter options with auto-resolution
44+ #
45+ # Automatically resolves app_name from Rails application name and
46+ # site_url from Rails routes/ActionMailer default_url_options.
47+ #
48+ # @param kwargs [Hash] configuration options
49+ # @option kwargs [String] :api_key OpenRouter API key
50+ # @option kwargs [String] :app_name application name for rankings
51+ # @option kwargs [String] :site_url site URL for rankings
52+ # @return [Options]
1653 def initialize ( kwargs = { } )
1754 kwargs = kwargs . deep_symbolize_keys if kwargs . respond_to? ( :deep_symbolize_keys )
1855
@@ -22,11 +59,22 @@ def initialize(kwargs = {})
2259 ) ) )
2360 end
2461
62+ # Serializes options for API requests
63+ #
64+ # Excludes app_name and site_url as they're sent via headers.
65+ #
66+ # @return [Hash] serialized options
2567 def serialize
2668 super . except ( :app_name , :site_url )
2769 end
2870
29- # We fallback to ActiveAgent but allow empty strings to unset
71+ # Returns extra headers for OpenRouter API
72+ #
73+ # Maps app_name and site_url to OpenRouter's required headers:
74+ # - HTTP-Referer: site_url
75+ # - X-Title: app_name
76+ #
77+ # @return [Hash] headers hash
3078 def extra_headers
3179 deep_compact (
3280 "http-referer" => site_url . presence ,
0 commit comments