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_heal_responses ⇒ Object
Healing configuration.
-
#auto_native_healing ⇒ Object
Native OpenRouter response healing (server-side).
-
#cache_ttl ⇒ Object
Cache 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.
-
#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.
-
#structured_output_strict ⇒ Object
Default validation strictness for structured outputs.
-
#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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/open_router.rb', line 70 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" # Default structured output validation strictness (loose/best-effort by default) self.structured_output_strict = ENV.fetch("OPENROUTER_STRUCTURED_STRICT", "false").downcase == "true" end |
Instance Attribute Details
#access_token ⇒ Object
100 101 102 103 104 |
# File 'lib/open_router.rb', line 100 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.
40 41 42 |
# File 'lib/open_router.rb', line 40 def api_version @api_version end |
#auto_heal_responses ⇒ Object
Healing configuration
43 44 45 |
# File 'lib/open_router.rb', line 43 def auto_heal_responses @auto_heal_responses end |
#auto_native_healing ⇒ Object
Native OpenRouter response healing (server-side)
46 47 48 |
# File 'lib/open_router.rb', line 46 def auto_native_healing @auto_native_healing end |
#cache_ttl ⇒ Object
Cache configuration
49 50 51 |
# File 'lib/open_router.rb', line 49 def cache_ttl @cache_ttl end |
#extra_headers ⇒ Object
Returns the value of attribute extra_headers.
40 41 42 |
# File 'lib/open_router.rb', line 40 def extra_headers @extra_headers end |
#faraday_config ⇒ Object
Returns the value of attribute faraday_config.
40 41 42 |
# File 'lib/open_router.rb', line 40 def faraday_config @faraday_config end |
#healer_model ⇒ Object
Healing configuration
43 44 45 |
# File 'lib/open_router.rb', line 43 def healer_model @healer_model end |
#log_errors ⇒ Object
Returns the value of attribute log_errors.
40 41 42 |
# File 'lib/open_router.rb', line 40 def log_errors @log_errors end |
#max_heal_attempts ⇒ Object
Healing configuration
43 44 45 |
# File 'lib/open_router.rb', line 43 def max_heal_attempts @max_heal_attempts end |
#model_registry_retries ⇒ Object
Model registry configuration
52 53 54 |
# File 'lib/open_router.rb', line 52 def model_registry_retries @model_registry_retries end |
#model_registry_timeout ⇒ Object
Model registry configuration
52 53 54 |
# File 'lib/open_router.rb', line 52 def model_registry_timeout @model_registry_timeout end |
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
40 41 42 |
# File 'lib/open_router.rb', line 40 def request_timeout @request_timeout end |
#strict_mode ⇒ Object
Capability validation configuration
55 56 57 |
# File 'lib/open_router.rb', line 55 def strict_mode @strict_mode end |
#structured_output_strict ⇒ Object
Default validation strictness for structured outputs.
false (default): best-effort, return parsed JSON as-is.
true: raise StructuredOutputError when the response doesn't match the schema.
Overridden per-call by the strict: option.
61 62 63 |
# File 'lib/open_router.rb', line 61 def structured_output_strict @structured_output_strict end |
#uri_base ⇒ Object
Returns the value of attribute uri_base.
40 41 42 |
# File 'lib/open_router.rb', line 40 def uri_base @uri_base end |
Instance Method Details
#faraday(&block) ⇒ Object
106 107 108 |
# File 'lib/open_router.rb', line 106 def faraday(&block) self.faraday_config = block end |
#site_name=(value) ⇒ Object
110 111 112 |
# File 'lib/open_router.rb', line 110 def site_name=(value) @extra_headers["X-Title"] = value end |
#site_url=(value) ⇒ Object
114 115 116 |
# File 'lib/open_router.rb', line 114 def site_url=(value) @extra_headers["HTTP-Referer"] = value end |