Class: SavvyOpenrouter::Resources::Models

Inherits:
Base
  • Object
show all
Defined in:
lib/savvy_openrouter/resources/models.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SavvyOpenrouter::Resources::Base

Instance Method Details

#countObject



25
26
27
28
29
# File 'lib/savvy_openrouter/resources/models.rb', line 25

def count
  conn.with_call_context(endpoint: "models_count", logical_model: nil) do
    conn.get("/models/count")
  end
end

#endpoints(author:, slug:) ⇒ Object



37
38
39
40
41
# File 'lib/savvy_openrouter/resources/models.rb', line 37

def endpoints(author:, slug:)
  conn.with_call_context(endpoint: "models_endpoints", logical_model: nil) do
    conn.get("/models/#{author}/#{slug}/endpoints")
  end
end

#first_ranked_free_text_model(category:, output_modalities: "text") ⇒ Object

Uses GET /models with filters, then returns the first model whose prompt + completion pricing are zero. OpenRouter returns models in curated rank order within a category; first matching free model aligns with site “top free” picks when combined with output_modalities=text.



19
20
21
22
23
# File 'lib/savvy_openrouter/resources/models.rb', line 19

def first_ranked_free_text_model(category:, output_modalities: "text")
  res = list(category: category, output_modalities: output_modalities)
  data = res[:data] || []
  data.find { |m| free_pricing?(m) }
end

#list(**params) ⇒ Object

Query params match OpenRouter GET /models (e.g. category, output_modalities, supported_parameters).



9
10
11
12
13
14
# File 'lib/savvy_openrouter/resources/models.rb', line 9

def list(**params)
  query = stringify_query(params)
  conn.with_call_context(endpoint: "models", logical_model: nil) do
    conn.get("/models", params: query.empty? ? nil : query)
  end
end

#userObject



31
32
33
34
35
# File 'lib/savvy_openrouter/resources/models.rb', line 31

def user
  conn.with_call_context(endpoint: "models_user", logical_model: nil) do
    conn.get("/models/user")
  end
end