What are Providers?
Providers are the abstraction layer in Goose that connects to different AI model services. Each provider implements theProvider trait, which standardizes how Goose communicates with various AI backends like Anthropic, OpenAI, Databricks, and Ollama.
Provider Trait
All providers implement theProvider trait, which defines the core interface:
Key Methods
stream()
The primary method for streaming responses from the AI model. Returns a MessageStream that yields partial messages as they’re generated.
complete()
A convenience method that collects the entire stream into a single message and usage information. Most implementations delegate to stream() and collect the results.
get_model_config()
Returns the current model configuration including model name, temperature, and other parameters.
fetch_supported_models()
Queries the provider’s API to get a list of available models.
Provider Metadata
Each provider defines metadata through theProviderDef trait:
Configuration Keys
Providers specify their required configuration throughConfigKey:
Model Configuration
TheModelConfig struct controls model behavior:
Usage and Pricing
Providers track token usage throughProviderUsage:
Built-in Providers
Goose includes several built-in providers:- Anthropic - Claude models (Sonnet, Opus, Haiku)
- OpenAI - GPT-4, GPT-4o, and other OpenAI models
- Databricks - Models on Databricks AI Gateway
- Ollama - Local open-source models
- Azure OpenAI - OpenAI models hosted on Azure
- Google Vertex AI - Google’s AI models
- AWS Bedrock - Amazon’s model marketplace
Custom Providers
You can create custom providers in two ways:- Declarative Providers - JSON configuration files for OpenAI-compatible APIs
- Rust Implementation - Implement the
Providertrait for full control
Provider Registry
Providers are registered at startup and can be retrieved by name:Error Handling
Providers use theProviderError enum for error handling:
Retry Configuration
Providers support configurable retry logic:Next Steps
- Explore specific provider implementations:
- Learn how to create custom providers