Skip to main content
Avante.nvim’s flexible provider system allows you to integrate any AI service that offers a REST API. This guide shows you how to create custom providers.

Provider Interface

A provider must implement specific functions to work with Avante:

Required Functions

  1. parse_curl_args(prompt_opts): Generate API request parameters
  2. parse_response(ctx, data_stream, event_state, opts): Parse streaming responses
  3. is_env_set(): Check if provider is properly configured

Optional Functions

  • setup(): Initialize provider (authentication, tokenizer, etc.)
  • parse_api_key(): Extract API key from environment
  • on_error(result): Handle API errors
  • list_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:
Then configure it:

Real-World Examples

OpenRouter

OpenRouter provides access to multiple models:

Mistral AI

Together AI

Groq

Message Format

Avante uses a standardized message format:
Your provider must convert this to your API’s 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

1

Set API key

2

Configure provider

3

Test in Neovim

4

Debug if needed

Advanced Features

Prompt Caching

Model Listing

Troubleshooting

Error: “Failed to find provider: my_provider”Ensure the provider is defined in providers table.
Error: “missing the __inherited_from attribute or a custom parse_curl_args function”Either:
  1. Set __inherited_from = "openai"
  2. Or implement parse_curl_args function
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.

Complete Example

Here’s a complete custom provider:
Configuration: