Class: Riffer::Providers::OpenRouter

Inherits:
Base
  • Object
show all
Defined in:
lib/riffer/providers/open_router.rb

Overview

OpenRouter provider (openrouter.ai). Requires the openai gem —OpenRouter exposes an OpenAI-compatible endpoint, so this reuses the OpenAI SDK with a base_url override. api_key falls back to config, then OPENROUTER_API_KEY.

Constant Summary collapse

BASE_URL =

: String

"https://openrouter.ai/api/v1"
FINISH_REASONS =
{
  "stop" => :stop,
  "length" => :length,
  "tool_calls" => :tool_calls,
  "function_call" => :tool_calls,
  "content_filter" => :content_filter,
  "error" => :error
}.freeze

Constants inherited from Base

Base::WIRE_SEPARATOR

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#generate_text, skills_adapter, #stream_text

Constructor Details

#initialize(api_key: nil, **options) ⇒ OpenRouter

– : (?api_key: String?, **untyped) -> void



31
32
33
34
35
36
37
# File 'lib/riffer/providers/open_router.rb', line 31

def initialize(api_key: nil, **options)
  depends_on "openai"

  api_key ||= Riffer.config.openrouter.api_key || ENV["OPENROUTER_API_KEY"]

  @client = ::OpenAI::Client.new(api_key: api_key, base_url: BASE_URL, **options)
end

Class Method Details

.semconv_provider_nameObject

The GenAI semconv well-known provider name. – : () -> String



25
26
27
# File 'lib/riffer/providers/open_router.rb', line 25

def self.semconv_provider_name
  "openrouter"
end