Skip to content

max-power/llm_specs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LLMSpecs

LLMSpecs is a lightweight Ruby interface for fetching large language model (LLM) specifications from the Parsera API. It provides a simple, efficient way to access model metadata with built-in caching and query support.

Features

  • Fetches LLM specs from: https://api.parsera.org/v1/llm-specs
  • Caches results locally to llm-specs.json
  • Provides a queryable catalog of models via .models
  • Supports filtering and lookup by model attributes

Example Usage

require 'llm_specs'

models = LLMSpecs.models # all models

models = LLMSpecs.gemini # provider specific models
models = LLMSpecs.anthropic
models = LLMSpecs.openai
models = LLMSpecs.deepseek

providers = LLMSpecs.providers # a list of all providers covered by Parsera API

Find a model by ID

model = LLMSpecs.models.find("claude-3-sonnet")

Filter models

# List all Anthropic models
anthropic_models = LLMSpecs.models.where(provider: "anthropic")
# or 
anthropic_models = LLMSpecs.anthropic

# List all Anthropic models by family "claude-3-7-sonnet"
claude_models = LLMSpecs.models.where(provider: "anthropic", family: "claude-3-7-sonnet")
#or 
claude_models = LLMSpecs.anthropic.where(family: "claude-3-7-sonnet")

# List all models that support streaming
streaming_models = LLMSpecs.models.select(&:streaming?)

# List all models that support audio output
audio_models = LLMSpecs.models.select(&:audio_output?)

Model Capabilities

Each model is represented by an instance of LLMSpecs::Model, a value object that encapsulates:

  • id, name, provider, family

  • Token limits (context_window, max_output_tokens)

  • Supported modalities (e.g. text, image)

  • Capabilities such as:

    • function_calling?
    • structured_output?
    • streaming?
    • reasoning?
    • citations?
    • batch?
  • Pricing breakdowns via pricing, input_pricing and output_pricing

You can easily check capabilities:

model.supports?(:function_calling) # => true/false
model.function_calling?  # => shortcut for above
# with multiple arguments
model.supports?(:function_calling, :batch) # => true/false

or input or output modalities:

model.supports_input?(:audio) # => true/false
model.supports_input?(:audio, :text) # multiple argument
model.audio_input? # shortcut
model.image_input?
model.text_input?

model.supports_output?(:audio) # => true/false
model.supports_output?(:audio, :embeddings) # multiple argument
model.audio_output? # shortcut
model.image_output?
model.text_output?
model.embeddings_output?

Pricing methods:

model.pricing # => returns a hash: 
#  {
#    text_tokens: {
#      standard: {
#        input_per_million: 15.0,
#        cached_input_per_million: 18.75,
#        output_per_million: 75.0
#      },
#      batch: {
#        input_per_million: nil,
#        output_per_million: nil
#      }
#    },
#    embeddings: {
#      standard: {
#        input_per_million: nil
#      },
#      batch: {
#        input_per_million: nil
#      }
#    }
#  }

model.pricing.dig(:text_tokens, :standard, :input_per_million)
# input/output pricing
model.input_pricing  # 15.0 => $ per 1M input tokens (default to pricing[:text_tokens][:standard][:input_per_million])
model.output_pricing # 75.0 => $ per 1M output tokens

model.input_pricing(:text_tokens, :batch)
model.input_pricing(:embeddings)

Cache configuration

LLMSpecs.cache_path = Rails.root.join("tmp", "cache", "llm-specs-cache.json")

License

The gem is available as open source under the terms of the MIT License.

About

Ruby interface for fetching LLM specifications from the Parsera API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors