Skip to main content
Google’s Gemini models offer industry-leading context windows (up to 1M+ tokens) and powerful multimodal capabilities. Avante.nvim provides full support for Gemini’s API.

Quick Start

1

Get your API key

Get an API key from Google AI Studio.
2

Set environment variable

Add to your shell configuration:
# Scoped (recommended)
export AVANTE_GEMINI_API_KEY=your-api-key

# Or global
export GEMINI_API_KEY=your-api-key
3

Configure provider

{
  "yetone/avante.nvim",
  opts = {
    provider = "gemini",
  },
}

Configuration

Basic Configuration

providers = {
  gemini = {
    endpoint = "https://generativelanguage.googleapis.com/v1beta/models",
    model = "gemini-2.0-flash",
    timeout = 30000,
    context_window = 1048576, -- 1M+ tokens
    extra_request_body = {
      generationConfig = {
        temperature = 0.75,
      },
    },
  },
}

Available Models

providers = {
  gemini = {
    model = "gemini-2.0-flash",
    context_window = 1048576,
  },
}

Environment Variables

VariableScoped VersionPurpose
GEMINI_API_KEYAVANTE_GEMINI_API_KEYAPI authentication

API Endpoint Structure

Gemini uses a unique endpoint structure:
endpoint = "https://generativelanguage.googleapis.com/v1beta/models"

-- Full URL is constructed as:
-- {endpoint}/{model}:streamGenerateContent?alt=sse&key={api_key}

Generation Configuration

Gemini uses generationConfig for model parameters:
extra_request_body = {
  generationConfig = {
    temperature = 0.75,
    topP = 0.95,
    topK = 40,
    maxOutputTokens = 8192,
    candidateCount = 1,
  },
}

Parameters

ParameterTypeDefaultDescription
temperaturenumber0.75Controls randomness (0.0-1.0)
topPnumber0.95Nucleus sampling threshold
topKnumber40Top-k sampling parameter
maxOutputTokensnumber8192Maximum response length
candidateCountnumber1Number of response candidates

Tool Calling

Gemini uses a different format for function declarations:
-- Avante automatically converts tools to Gemini format:
{
  tools = {
    {
      functionDeclarations = {
        {
          name = "tool_name",
          description = "Tool description",
          parameters = {
            type = "object",
            properties = { ... },
            required = { ... },
          },
        },
      },
    },
  },
}

Function Responses

-- Function results are formatted as:
{
  functionResponse = {
    name = "tool_name",
    response = {
      name = "tool_name",
      content = { result_data },
    },
  },
}

Safety Settings

Gemini includes safety filters. If your prompt is blocked:
-- Response includes:
{
  promptFeedback = {
    blockReason = "SAFETY", -- or "RECITATION"
  },
}
To adjust safety settings, add to your configuration:
extra_request_body = {
  safetySettings = {
    {
      category = "HARM_CATEGORY_HARASSMENT",
      threshold = "BLOCK_MEDIUM_AND_ABOVE",
    },
    -- Add other categories as needed
  },
}

Finish Reasons

Gemini responses include finish reasons:
ReasonMeaning
STOPNatural completion
MAX_TOKENSReached token limit
SAFETYBlocked by safety filters
RECITATIONBlocked due to recitation
TOOL_CODETool use requested

Vertex AI

For Google Cloud Vertex AI, use the vertex provider:
providers = {
  vertex = {
    endpoint = "https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models",
    model = "gemini-1.5-flash-002",
    timeout = 30000,
    context_window = 1048576,
    extra_request_body = {
      generationConfig = {
        temperature = 0.75,
      },
    },
  },
}

Authentication

Vertex AI uses Google Cloud authentication:
# Set up gcloud CLI authentication
gcloud auth application-default login

# Or use a service account
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json

Advanced Features

ReAct Prompting

Enable ReAct-style prompting for better tool use:
providers = {
  gemini = {
    use_ReAct_prompt = true,
  },
}

Stop Sequences

Custom stop sequences for ReAct mode:
extra_request_body = {
  generationConfig = {
    stopSequences = { "</tool_use>" },
  },
}

Multimodal Input

Gemini supports image inputs:
-- Images are automatically formatted as:
{
  inline_data = {
    mime_type = "image/png",
    data = "base64_encoded_data",
  },
}

Troubleshooting

Ensure your API key is set:
echo $GEMINI_API_KEY
# or
echo $AVANTE_GEMINI_API_KEY
Get a key from Google AI Studio.
If your prompt is blocked:
  1. Review the blockReason in the error
  2. Adjust your prompt to be less sensitive
  3. Configure safety settings (use with caution)
For Vertex AI:
  1. Ensure gcloud is authenticated: gcloud auth list
  2. Check project ID in endpoint URL
  3. Verify service account permissions
Gemini has generous quotas, but if you hit limits:
  1. Check quota at Google Cloud Console
  2. Request quota increase
  3. Implement request throttling

Best Practices

Model Selection

  • Gemini 2.0 Flash: Latest, best performance
  • Gemini 1.5 Pro: Maximum capability
  • Gemini 1.5 Flash: Fastest responses

Context Window

  • 1M+ token context is unique to Gemini
  • Great for large codebases
  • Entire files can fit in context

Temperature Settings

  • 0.0-0.3: Focused, consistent
  • 0.4-0.7: Balanced (recommended)
  • 0.8-1.0: Creative, varied

Safety

  • Default filters are moderate
  • Adjust only when necessary
  • Review blocked content carefully

Example Configurations

{
  provider = "gemini",
  providers = {
    gemini = {
      model = "gemini-2.0-flash",
      timeout = 30000,
      extra_request_body = {
        generationConfig = {
          temperature = 0.7,
          maxOutputTokens = 8192,
        },
      },
    },
  },
}

Build docs developers (and LLMs) love