class

Grafito::AI::Providers::OpenAICompatible

Inherits Grafito::AI::Provider < Reference < Object

Provider for OpenAI-compatible APIs.

Configuration:

  • Z_AI_API_KEY / OPENAI_API_KEY / GROQ_API_KEY / etc: API key
  • GRAFITO_AI_API_KEY: Generic API key fallback
  • GRAFITO_AI_MODEL: Model override
  • GRAFITO_AI_ENDPOINT: Custom endpoint URL

Constants

KNOWN_MODELS = {"z_ai" => {"glm-4.5-flash" => "GLM 4.5 Flash", "glm-4-plus" => "GLM 4 Plus"}, "openai" => {"gpt-5.2" => "GPT-5.2", "gpt-5.1" => "GPT-5.1", "gpt-5" => "GPT-5", "gpt-5-mini" => "GPT-5 Mini", "gpt-5-nano" => "GPT-5 Nano", "o1" => "O1", "gpt-4.1" => "GPT-4.1", "gpt-4.1-mini" => "GPT-4.1 Mini", "gpt-4.1-nano" => "GPT-4.1 Nano", "gpt-4o" => "GPT-4o", "gpt-4o-mini" => "GPT-4o Mini", "chatgpt-4o-latest" => "ChatGPT-4o Latest", "gpt-4-turbo" => "GPT-4 Turbo", "gpt-4" => "GPT-4", "gpt-3.5-turbo" => "GPT-3.5 Turbo", "gpt-3.5-turbo-16k" => "GPT-3.5 Turbo 16K"}, "groq" => {"llama-3.3-70b-versatile" => "Llama 3.3 70B", "llama-3.1-8b-instant" => "Llama 3.1 8B", "mixtral-8x7b-32768" => "Mixtral 8x7B", "gemma2-9b-it" => "Gemma 2 9B"}, "together" => {"meta-llama/Llama-3.3-70B-Instruct-Turbo" => "Llama 3.3 70B", "meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo" => "Llama 3.2 11B Vision", "mistralai/Mixtral-8x7B-Instruct-v0.1" => "Mixtral 8x7B"}, "ollama" => {"llama3.2" => "Llama 3.2", "llama3.1" => "Llama 3.1", "mistral" => "Mistral", "codellama" => "Code Llama", "qwen2.5" => "Qwen 2.5"}}

Curated list of popular, known-working chat models per provider

Log = ::Log.for(self)
PROVIDERS = {"z_ai" => ProviderConfig.new(endpoint: "https://api.z.ai/api/paas/v4/chat/completions", models_endpoint: nil, default_model: "glm-4.5-flash", env_key: "Z_AI_API_KEY", name: "Z.AI"), "openai" => ProviderConfig.new(endpoint: "https://api.openai.com/v1/chat/completions", models_endpoint: "https://api.openai.com/v1/models", default_model: "gpt-4o-mini", env_key: "OPENAI_API_KEY", name: "OpenAI"), "groq" => ProviderConfig.new(endpoint: "https://api.groq.com/openai/v1/chat/completions", models_endpoint: "https://api.groq.com/openai/v1/models", default_model: "llama-3.1-70b-versatile", env_key: "GROQ_API_KEY", name: "Groq"), "together" => ProviderConfig.new(endpoint: "https://api.together.xyz/v1/chat/completions", models_endpoint: "https://api.together.xyz/v1/models", default_model: "meta-llama/Llama-3-70b-chat-hf", env_key: "TOGETHER_API_KEY", name: "Together.ai"), "ollama" => ProviderConfig.new(endpoint: "http://localhost:11434/v1/chat/completions", models_endpoint: "http://localhost:11434/api/tags", default_model: "llama3", env_key: nil, name: "Ollama")}

Constructors

new(force_provider : String | Nil = nil, model : String | Nil = nil)
Source

Class methods

available?

Check if this provider can be used (has required config)

Source

Instance methods

available?

Check if this provider can be used (has required config)

Source
complete(request : Request) : Response

Execute a completion request and return normalized response

Source
current_model

Get the currently selected model ID

Source
models

Fetch available models from API or return fallback list

Source
name

Human-readable name for this provider instance

Source

Nested types