module

Grafito::AI::Config

Configuration management for AI providers.

Supports both explicit provider selection via GRAFITO_AI_PROVIDER and auto-detection based on available API keys.

Environment Variables:

  • GRAFITO_AI_PROVIDER: Force specific provider (anthropic, openai, z_ai, groq, ollama)
  • ANTHROPIC_API_KEY: Anthropic/Claude API key
  • Z_AI_API_KEY: Z.AI API key (backward compatible)
  • OPENAI_API_KEY: OpenAI API key
  • GROQ_API_KEY: Groq API key
  • TOGETHER_API_KEY: Together.ai API key
  • GRAFITO_AI_API_KEY: Generic API key (fallback)
  • GRAFITO_AI_MODEL: Override default model
  • GRAFITO_AI_ENDPOINT: Custom endpoint URL (for Ollama, etc.)

Constants

ANTHROPIC_PROVIDERS = {"anthropic", "claude"}

Provider IDs that map to Anthropic

Log = ::Log.for(self)
OPENAI_COMPATIBLE_API_KEYS = {"Z_AI_API_KEY", "OPENAI_API_KEY", "GROQ_API_KEY", "TOGETHER_API_KEY", "GRAFITO_AI_API_KEY"}

API key environment variables for OpenAI-compatible providers

OPENAI_COMPATIBLE_PROVIDERS = {"openai", "z_ai", "zai", "groq", "ollama", "together", "openai_compatible"}

Provider IDs that map to OpenAI-compatible

Instance methods

available_providers

List all available providers with their status

Source
enabled?

Check if any AI provider is available

Source
log_config

Log current configuration (for debugging)

Source
models_for_provider(id : String) : Array(ModelInfo)

Get available models for a specific provider

Source
provider

Get an instance of the configured provider, or nil if none available

Source
provider_by_id(id : String, model : String | Nil = nil) : Provider | Nil

Get a specific provider by ID, optionally with a specific model

Source
provider_name

Get human-readable name of the active provider

Source
provider_type

Determine which provider type to use

Source

Nested types