Class: Ask::Providers::OpenRouter
- Inherits:
-
OpenAI
- Object
- Ask::Provider
- OpenAI
- Ask::Providers::OpenRouter
show all
- Defined in:
- lib/ask/provider/openrouter.rb
Overview
OpenRouter API — an OpenAI-compatible aggregator at openrouter.ai. Provides access to many models through a single endpoint.
Configuration via environment:
OPENROUTER_API_KEY — required, your OpenRouter API key
OPENROUTER_API_BASE — optional, base URL (default: https://openrouter.ai/api/v1)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from OpenAI
assume_models_exist?, capabilities, #chat, #embed, #initialize, #list_models, #parse_error
Class Method Details
.configuration_options ⇒ Object
27
|
# File 'lib/ask/provider/openrouter.rb', line 27
def configuration_options; %i[api_key base_url]; end
|
.configuration_requirements ⇒ Object
28
|
# File 'lib/ask/provider/openrouter.rb', line 28
def configuration_requirements; %i[api_key]; end
|
29
30
31
32
33
|
# File 'lib/ask/provider/openrouter.rb', line 29
def configured?(config)
key = config.respond_to?(:api_key) ? config.api_key : nil
key ||= ENV["OPENROUTER_API_KEY"]
key.to_s.length > 0
end
|
.slug ⇒ Object
26
|
# File 'lib/ask/provider/openrouter.rb', line 26
def slug; "openrouter"; end
|
Instance Method Details
#api_base ⇒ Object
12
13
14
|
# File 'lib/ask/provider/openrouter.rb', line 12
def api_base
@config.base_url || ENV["OPENROUTER_API_BASE"] || "https://openrouter.ai/api/v1"
end
|
16
17
18
19
20
21
22
23
|
# File 'lib/ask/provider/openrouter.rb', line 16
def
h = super
key = @config.api_key || ENV["OPENROUTER_API_KEY"]
h["Authorization"] = "Bearer #{key}" if key
h["HTTP-Referer"] = ENV["OPENROUTER_REFERER"] || "https://github.com/ask-rb"
h["X-Title"] = ENV["OPENROUTER_APP_TITLE"] || "ask-rb"
h
end
|