Class: SavvyOpenrouter::Resources::Models

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

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Instance Method Details

#countObject

Returns:

  • (Object)


27
28
29
30
31
# File 'lib/savvy_openrouter/resources/models.rb', line 27

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

#endpoints(author:, slug:) ⇒ Object

Parameters:

  • author: (String)
  • slug: (String)

Returns:

  • (Object)


39
40
41
42
43
# File 'lib/savvy_openrouter/resources/models.rb', line 39

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") ⇒ Hash[Symbol, untyped]?

Uses GET /models with category + free-price filters, then returns the first model whose prompt and completion pricing are both zero. OpenRouter returns models in curated rank order; the first free match aligns with site “top free” picks when combined with output_modalities=text. Models scheduled for removal (expiration_date) are still eligible — callers often want the current top free pick even when it is temporary.

Parameters:

  • category: (String)
  • output_modalities: (String) (defaults to: "text")

Returns:

  • (Hash[Symbol, untyped], nil)


21
22
23
24
25
# File 'lib/savvy_openrouter/resources/models.rb', line 21

def first_ranked_free_text_model(category:, output_modalities: "text")
  res = list(category: category, output_modalities: output_modalities, max_price: 0)
  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).

Parameters:

  • params (Object)

Returns:

  • (Object)


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

Returns:

  • (Object)


33
34
35
36
37
# File 'lib/savvy_openrouter/resources/models.rb', line 33

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