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.
-
#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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/open_router.rb', line 63 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 # 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
93 94 95 96 97 |
# File 'lib/open_router.rb', line 93 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.
36 37 38 |
# File 'lib/open_router.rb', line 36 def api_version @api_version end |
#auto_force_on_unsupported_models ⇒ Object
Automatic forcing configuration
51 52 53 |
# File 'lib/open_router.rb', line 51 def auto_force_on_unsupported_models @auto_force_on_unsupported_models end |
#auto_heal_responses ⇒ Object
Healing configuration
39 40 41 |
# File 'lib/open_router.rb', line 39 def auto_heal_responses @auto_heal_responses end |
#cache_ttl ⇒ Object
Cache configuration
42 43 44 |
# File 'lib/open_router.rb', line 42 def cache_ttl @cache_ttl end |
#default_structured_output_mode ⇒ Object
Default structured output mode configuration
54 55 56 |
# File 'lib/open_router.rb', line 54 def default_structured_output_mode @default_structured_output_mode end |
#extra_headers ⇒ Object
Returns the value of attribute extra_headers.
36 37 38 |
# File 'lib/open_router.rb', line 36 def extra_headers @extra_headers end |
#faraday_config ⇒ Object
Returns the value of attribute faraday_config.
36 37 38 |
# File 'lib/open_router.rb', line 36 def faraday_config @faraday_config end |
#healer_model ⇒ Object
Healing configuration
39 40 41 |
# File 'lib/open_router.rb', line 39 def healer_model @healer_model end |
#log_errors ⇒ Object
Returns the value of attribute log_errors.
36 37 38 |
# File 'lib/open_router.rb', line 36 def log_errors @log_errors end |
#max_heal_attempts ⇒ Object
Healing configuration
39 40 41 |
# File 'lib/open_router.rb', line 39 def max_heal_attempts @max_heal_attempts end |
#model_registry_retries ⇒ Object
Model registry configuration
45 46 47 |
# File 'lib/open_router.rb', line 45 def model_registry_retries @model_registry_retries end |
#model_registry_timeout ⇒ Object
Model registry configuration
45 46 47 |
# File 'lib/open_router.rb', line 45 def model_registry_timeout @model_registry_timeout end |
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
36 37 38 |
# File 'lib/open_router.rb', line 36 def request_timeout @request_timeout end |
#strict_mode ⇒ Object
Capability validation configuration
48 49 50 |
# File 'lib/open_router.rb', line 48 def strict_mode @strict_mode end |
#uri_base ⇒ Object
Returns the value of attribute uri_base.
36 37 38 |
# File 'lib/open_router.rb', line 36 def uri_base @uri_base end |
Instance Method Details
#faraday(&block) ⇒ Object
99 100 101 |
# File 'lib/open_router.rb', line 99 def faraday(&block) self.faraday_config = block end |
#site_name=(value) ⇒ Object
103 104 105 |
# File 'lib/open_router.rb', line 103 def site_name=(value) @extra_headers["X-Title"] = value end |
#site_url=(value) ⇒ Object
107 108 109 |
# File 'lib/open_router.rb', line 107 def site_url=(value) @extra_headers["HTTP-Referer"] = value end |