Provider Interface
A provider must implement specific functions to work with Avante:Required Functions
parse_curl_args(prompt_opts): Generate API request parametersparse_response(ctx, data_stream, event_state, opts): Parse streaming responsesis_env_set(): Check if provider is properly configured
Optional Functions
setup(): Initialize provider (authentication, tokenizer, etc.)parse_api_key(): Extract API key from environmenton_error(result): Handle API errorslist_models(): List available models
Creating a Custom Provider
Method 1: Inherit from Existing Provider
The easiest way is to inherit from an OpenAI-compatible provider:Method 2: Custom Implementation
For non-OpenAI-compatible APIs, create a custom module:Real-World Examples
OpenRouter
OpenRouter provides access to multiple models:Mistral AI
Together AI
Groq
Message Format
Avante uses a standardized message format:Tool Support
To support function calling:Authentication Methods
API Key from Environment
API Key from Command
OAuth
See the Claude provider implementation for OAuth example:Streaming Responses
Server-Sent Events (SSE)
Most providers use SSE:Newline-Delimited JSON
Error Handling
Testing Your Provider
Advanced Features
Prompt Caching
Model Listing
Troubleshooting
Provider Not Found
Provider Not Found
Error: “Failed to find provider: my_provider”Ensure the provider is defined in
providers table.Missing parse_curl_args
Missing parse_curl_args
Error: “missing the
__inherited_from attribute or a custom parse_curl_args function”Either:- Set
__inherited_from = "openai" - Or implement
parse_curl_argsfunction
API Key Not Set
API Key Not Set
Ensure environment variable is set:
Best Practices
Inherit When Possible
Use
__inherited_from for OpenAI-compatible APIs to reduce code.Handle Errors
Implement proper error handling and user-friendly messages.
Support Streaming
Implement streaming for better UX and responsiveness.
Document Your Provider
Add comments explaining API-specific quirks and requirements.