Class: OpenRouter::Configuration
- Inherits:
-
Object
- Object
- OpenRouter::Configuration
- Defined in:
- lib/open_router.rb
Constant Summary collapse
- DEFAULT_API_VERSION =
"v1"- DEFAULT_REQUEST_TIMEOUT =
120- DEFAULT_URI_BASE =
"https://openrouter.ai/api"- DEFAULT_CACHE_TTL =
7 days in seconds
7 * 24 * 60 * 60
- DEFAULT_MODEL_REGISTRY_TIMEOUT =
30- DEFAULT_MODEL_REGISTRY_RETRIES =
3
Instance Attribute Summary collapse
- #access_token ⇒ Object
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#auto_force_on_unsupported_models ⇒ Object
Automatic forcing configuration.
-
#auto_heal_responses ⇒ Object
Healing configuration.
-
#auto_native_healing ⇒ Object
Native OpenRouter response healing (server-side).
-
#cache_ttl ⇒ Object
Cache configuration.
-
#default_structured_output_mode ⇒ Object
Default structured output mode configuration.
-
#extra_headers ⇒ Object
Returns the value of attribute extra_headers.
-
#faraday_config ⇒ Object
Returns the value of attribute faraday_config.
-
#healer_model ⇒ Object
Healing configuration.
-
#log_errors ⇒ Object
Returns the value of attribute log_errors.
-
#logger ⇒ Object
Optional logger.
-
#max_heal_attempts ⇒ Object
Healing configuration.
-
#model_registry_retries ⇒ Object
Model registry configuration.
-
#model_registry_timeout ⇒ Object
Model registry configuration.
-
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
-
#strict_mode ⇒ Object
Capability validation configuration.
-
#uri_base ⇒ Object
Returns the value of attribute uri_base.
Instance Method Summary collapse
- #faraday(&block) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #site_name=(value) ⇒ Object
- #site_url=(value) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/open_router.rb', line 76 def initialize self.access_token = nil self.api_version = DEFAULT_API_VERSION self.extra_headers = {} self.log_errors = false self.request_timeout = DEFAULT_REQUEST_TIMEOUT self.uri_base = DEFAULT_URI_BASE # Healing defaults self.auto_heal_responses = false self.healer_model = "openai/gpt-4o-mini" self.max_heal_attempts = 2 # Native OpenRouter healing (enabled by default for non-streaming structured outputs) self.auto_native_healing = ENV.fetch("OPENROUTER_AUTO_NATIVE_HEALING", "true").downcase == "true" # Cache defaults self.cache_ttl = ENV.fetch("OPENROUTER_CACHE_TTL", DEFAULT_CACHE_TTL).to_i # Model registry defaults self.model_registry_timeout = ENV.fetch("OPENROUTER_REGISTRY_TIMEOUT", DEFAULT_MODEL_REGISTRY_TIMEOUT).to_i self.model_registry_retries = ENV.fetch("OPENROUTER_REGISTRY_RETRIES", DEFAULT_MODEL_REGISTRY_RETRIES).to_i # Capability validation defaults self.strict_mode = ENV.fetch("OPENROUTER_STRICT_MODE", "false").downcase == "true" # Auto forcing defaults self.auto_force_on_unsupported_models = ENV.fetch("OPENROUTER_AUTO_FORCE", "true").downcase == "true" # Default structured output mode self.default_structured_output_mode = ENV.fetch("OPENROUTER_DEFAULT_MODE", "strict").to_sym end |
Instance Attribute Details
#access_token ⇒ Object
109 110 111 112 113 |
# File 'lib/open_router.rb', line 109 def access_token return @access_token if @access_token raise ConfigurationError, "OpenRouter access token missing!" end |
#api_version ⇒ Object
Returns the value of attribute api_version.
42 43 44 |
# File 'lib/open_router.rb', line 42 def api_version @api_version end |
#auto_force_on_unsupported_models ⇒ Object
Automatic forcing configuration
60 61 62 |
# File 'lib/open_router.rb', line 60 def auto_force_on_unsupported_models @auto_force_on_unsupported_models end |
#auto_heal_responses ⇒ Object
Healing configuration
45 46 47 |
# File 'lib/open_router.rb', line 45 def auto_heal_responses @auto_heal_responses end |
#auto_native_healing ⇒ Object
Native OpenRouter response healing (server-side)
48 49 50 |
# File 'lib/open_router.rb', line 48 def auto_native_healing @auto_native_healing end |
#cache_ttl ⇒ Object
Cache configuration
51 52 53 |
# File 'lib/open_router.rb', line 51 def cache_ttl @cache_ttl end |
#default_structured_output_mode ⇒ Object
Default structured output mode configuration
63 64 65 |
# File 'lib/open_router.rb', line 63 def default_structured_output_mode @default_structured_output_mode end |
#extra_headers ⇒ Object
Returns the value of attribute extra_headers.
42 43 44 |
# File 'lib/open_router.rb', line 42 def extra_headers @extra_headers end |
#faraday_config ⇒ Object
Returns the value of attribute faraday_config.
42 43 44 |
# File 'lib/open_router.rb', line 42 def faraday_config @faraday_config end |
#healer_model ⇒ Object
Healing configuration
45 46 47 |
# File 'lib/open_router.rb', line 45 def healer_model @healer_model end |
#log_errors ⇒ Object
Returns the value of attribute log_errors.
42 43 44 |
# File 'lib/open_router.rb', line 42 def log_errors @log_errors end |
#logger ⇒ Object
Optional logger. When set, gem warnings are routed through it (e.g. Rails.logger). When nil (default), warnings go to Kernel.warn → $stderr.
67 68 69 |
# File 'lib/open_router.rb', line 67 def logger @logger end |
#max_heal_attempts ⇒ Object
Healing configuration
45 46 47 |
# File 'lib/open_router.rb', line 45 def max_heal_attempts @max_heal_attempts end |
#model_registry_retries ⇒ Object
Model registry configuration
54 55 56 |
# File 'lib/open_router.rb', line 54 def model_registry_retries @model_registry_retries end |
#model_registry_timeout ⇒ Object
Model registry configuration
54 55 56 |
# File 'lib/open_router.rb', line 54 def model_registry_timeout @model_registry_timeout end |
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
42 43 44 |
# File 'lib/open_router.rb', line 42 def request_timeout @request_timeout end |
#strict_mode ⇒ Object
Capability validation configuration
57 58 59 |
# File 'lib/open_router.rb', line 57 def strict_mode @strict_mode end |
#uri_base ⇒ Object
Returns the value of attribute uri_base.
42 43 44 |
# File 'lib/open_router.rb', line 42 def uri_base @uri_base end |
Instance Method Details
#faraday(&block) ⇒ Object
115 116 117 |
# File 'lib/open_router.rb', line 115 def faraday(&block) self.faraday_config = block end |
#site_name=(value) ⇒ Object
119 120 121 |
# File 'lib/open_router.rb', line 119 def site_name=(value) @extra_headers["X-Title"] = value end |
#site_url=(value) ⇒ Object
123 124 125 |
# File 'lib/open_router.rb', line 123 def site_url=(value) @extra_headers["HTTP-Referer"] = value end |