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.
-
#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.
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 99 100 101 |
# 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" # 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
103 104 105 106 107 |
# File 'lib/open_router.rb', line 103 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_force_on_unsupported_models ⇒ Object
Automatic forcing configuration
58 59 60 |
# File 'lib/open_router.rb', line 58 def auto_force_on_unsupported_models @auto_force_on_unsupported_models 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 |
#default_structured_output_mode ⇒ Object
Default structured output mode configuration
61 62 63 |
# File 'lib/open_router.rb', line 61 def default_structured_output_mode @default_structured_output_mode 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 |
#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
109 110 111 |
# File 'lib/open_router.rb', line 109 def faraday(&block) self.faraday_config = block end |
#site_name=(value) ⇒ Object
113 114 115 |
# File 'lib/open_router.rb', line 113 def site_name=(value) @extra_headers["X-Title"] = value end |
#site_url=(value) ⇒ Object
117 118 119 |
# File 'lib/open_router.rb', line 117 def site_url=(value) @extra_headers["HTTP-Referer"] = value end |