Gemini provider

Related Documentation
Minimum Version
AI Gateway - 2.0
Incompatible with
on-prem
Tags
#ai
Previous Versions of this page

You can proxy requests to Gemini AI models through AI Gateway by creating AI Model Provider and AI Model entities. This reference documents all supported AI capabilities, configuration requirements, and provider-specific details needed for proper integration.

AI Gateway supports both Gemini Standard and Gemini Enterprise. The following sections cover both variants together and note where their capabilities differ.

Upstream paths

AI Gateway automatically routes requests to the appropriate Gemini API endpoints. The following table shows the upstream paths used for each capability.

Capability

Variant

Path template

Description

Upstream path or API

Generate Gemini Standard & Gemini Enterprise /chat/completions, /completions, or /responses Text generation for chat completions and responses Uses generateContent API
Realtime Gemini Standard only /realtime Bidirectional streaming for real-time applications Uses BidiGenerateContent API
Embeddings Gemini Standard /embeddings Vector embeddings from text input Uses batchEmbedContents API
Embeddings Gemini Enterprise /embeddings Vector embeddings from text input Uses predict API
Image Gemini Standard & Gemini Enterprise /images/generations or /images/edits Image generation and editing Uses generateContent API
Video Gemini Standard & Gemini Enterprise /videos Video generation Uses predictLongRunning API
Batches Gemini Standard /batches Batch processing of requests Uses batches API
Batches Gemini Enterprise /batches Batch processing of requests Uses batchPredictionJobs API
Files Gemini Standard /files File management and storage Uses uploadFile and files API
Files Gemini Enterprise /files File management and storage /openai/files

Supported capabilities

The following tables show the AI capabilities supported by the Gemini provider when configuring AI Models.

By default, AI Gateway uses the path templates shown in the tables below (e.g., /chat/completions, /embeddings, etc.). To customize these paths, configure the config.paths field in your AI Model entity. Custom paths take the form {configured_path}/{template_path} — for example, if you set a custom path of /v2, requests to /embeddings would be routed to /v2/embeddings.

Text generation

Support for Gemini text generation capabilities:

Capability

Variant

Streaming

Model example

Path template

Min version

generate Gemini Standard & Gemini Enterprise Supported gemini-2.5-flash /chat/completions, /completions, or /responses 2.0

Embeddings

Support for Gemini embeddings generation:

Capability

Variant

Model example

Path template

Min version

embeddings Gemini Standard & Gemini Enterprise text-embedding-004 /embeddings 2.0

Image

Support for Gemini image generation and editing capabilities:

Capability

Variant

Model example

Path template

Min version

image Gemini Standard & Gemini Enterprise gemini-2.5-flash-preview-image-generation /images/generations or /images/edits 2.0

For requests with large payloads, consider increasing config.max_request_body_size on your AI Model entity to three times the raw binary size.

Supported image sizes and formats vary by model. Refer to your provider’s documentation for allowed dimensions and requirements.

Video

Support for Gemini video generation capabilities:

Capability

Variant

Model example

Path template

Min version

video Gemini Standard & Gemini Enterprise veo-3.1-generate-001 /videos 2.0

For requests with large payloads (video generation), consider increasing config.max_request_body_size on your AI Model entity to three times the raw binary size.

Realtime

Support for Gemini’s bidirectional streaming for realtime applications:

Realtime processing uses WebSocket protocol (ws/wss). This protocol is automatically enabled when you configure your AI Model with the realtime capability.

Capability

Variant

Model example

Path template

Min version

realtime1 Gemini Standard only gemini-2.5-flash-preview-native-audio /realtime 2.0

1 Gemini Standard: Realtime processing for Gemini is supported in the native format from SDK only

Batches

Support for Gemini batch processing capabilities:

Capability

Variant

Model example

Path template

Min version

batches2 Gemini Standard & Gemini Enterprise n/a /batches 2.0

2 Gemini Standard: Batches processing for Gemini is supported in the native format from SDK only

Batches are configured on a separate AI Model with type: "api", distinct from regular models that handle synchronous capabilities like generate and embeddings. Create a dedicated AI Model exclusively for batches and files, as each model must be either a regular model or an API model, not both.

Files

Support for Gemini file management capabilities:

Capability

Variant

Model example

Path template

Min version

files3 Gemini Standard & Gemini Enterprise n/a /files 2.0

3 Gemini Standard: Files processing for Gemini is supported in the native format from SDK only 4 Gemini Enterprise: Gemini Enterprise does not have a dedicated Files API. File storage uses Google Cloud Storage, similar to AWS S3.

Batches are configured on a separate AI Model with type: "api", distinct from regular models that handle synchronous capabilities like generate and embeddings. Create a dedicated AI Model exclusively for batches and files, as each model must be either a regular model or an API model, not both.## Gemini base URL By default, AI Gateway routes Gemini requests to Gemini Standard at https://generativelanguage.googleapis.com.

Setting config.gcp_environment (with api_endpoint, location_id, and project_id) on the AI Model’s target. This switches routing to Gemini Enterprise at https://aiplatform.googleapis.com/.

AI Gateway uses the correct URL automatically based on this configuration. You only need to set upstream_url in your AI Model configuration if you’re using a self-hosted or Gemini-compatible endpoint instead.

Supported native LLM formats for Gemini

By default, AI Gateway uses OpenAI-compatible request formats. Configure a native format in your AI Model to use Gemini-specific APIs and features.

The following native Gemini formats are supported:

LLM format

Variant

Supported APIs

gemini Gemini Standard
  • /v1beta/models/{model_name}:generateContent
  • /v1beta/models/{model_name}:streamGenerateContent
  • /v1beta/models/{model_name}:embedContent
  • /v1beta/models/{model_name}:batchEmbedContents
  • /v1beta/batches
  • /upload/v1beta/files
  • /v1beta/files
gemini Gemini Enterprise
  • /v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:generateContent
  • /v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:streamGenerateContent
  • /v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:embedContent
  • /v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:predict
  • /v1/projects/{project_id}/locations/{location}/publishers/{publisher}/models/{model_name}:predictLongRunning
  • /v1/projects/{project_id}/locations/{location}/rankingConfigs/{config_name}:rank
  • /v1/projects/{project_id}/locations/{location}/batchPredictionJobs

Provider-specific limitations for native formats

Gemini Standard:

  • Gemini only supports auth.allow_override = false.

Gemini Enterprise:

  • None.

Configure Gemini

To use Gemini with AI Gateway, configure a new AI Model Provider. You can then access supported AI Models from Gemini.

Gemini Standard

Here’s a minimal configuration for chat completions, authenticating with an API key:

Gemini Enterprise

Gemini Enterprise requires GCP credentials instead of an API key. The Provider only handles authentication; auth.type: gcp by itself doesn’t select Gemini Enterprise, since Gemini Standard can use the same GCP auth. What actually routes to Gemini Enterprise is config.gcp_environment on the AI Model’s target that attaches to this Provider (see Gemini base URL).

Create the Provider to store your GCP credentials:

kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" << 'EOF'
ai_gateway_model_providers:
  - ref: my-gemini-enterprise-account
    ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
    name: my-gemini-enterprise-account
    display_name: "Gemini Enterprise Production"
    type: gemini
    config:
      auth:
        type: gcp
        use_gcp_service_account: true
        service_account_json: !env GCP_ACCOUNT_JSON
EOF

Then attach an AI Model to it, setting config.gcp_environment on the target to route to Gemini Enterprise:

kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" << 'EOF'
ai_gateway_models:
  - ref: my-gemini-enterprise-model
    ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
    name: my-gemini-enterprise-model
    display_name: "my-gemini-enterprise-model"
    type: model
    capabilities:
      - generate
    formats:
      - type: openai
    config:
      route:
        paths:
          - /v1
    targets:
      - name: gemini-2.5-flash
        provider: my-gemini-enterprise-account
        config:
          type: gemini
          gcp_environment:
            api_endpoint: us-east5-aiplatform.googleapis.com
            location_id: us-east5
            project_id: my-gcp-project-id
    policies: []
EOF

targets[].config.gcp_environment requires api_endpoint, location_id, and project_id together. Without it, this same Provider would route to Gemini Standard instead.

Authentication with GCP IAM

Gemini Enterprise requires credentials from Google Cloud Platform (GCP). Gemini Standard can also use GCP credentials instead of an API key by setting auth to gcp.

The authentication chain follows the same order of precedence as the gcloud tool:

  1. Service account JSON defined directly in the Provider: auth.service_account_json.
  2. Service account JSON defined in environment variable GCP_SERVICE_ACCOUNT.
  3. Workload IAM Role (for example, a GKE or Deployment Service Account).
  4. VM Instance defined IAM Role.

For restricted networks, override the default endpoints with auth.metadata_url or auth.oauth_token_url.

FAQs

You can configure model generation parameters when calling Gemini through AI Gateway:

  • Using the Gemini SDK:

    1. Create an AI Model Provider for Gemini and an AI Model that references it.
    2. Configure parameters like temperature, top_p, and top_k on the client side:
       model = genai.GenerativeModel(
           'gemini-2.5-flash',
           generation_config=genai.types.GenerationConfig(
               temperature=0.7,
               top_p=0.9,
               top_k=40,
               max_output_tokens=1024
           )
       )
  • Using the OpenAI SDK with AI Gateway:

    1. Create an AI Model with an openai entry in its formats array, and a target that references your Gemini AI Model Provider.
    2. You can configure parameters in one of three ways:
      • Configure them in the AI Model only.
      • Configure them in the client only.
      • Configure them in both. The client-side values override the model config.

Configure an AI Model that uses a Gemini AI Model Provider, then declare the googleSearch tool in your requests.

Pass imageConfig parameters via generationConfig in your image generation requests.

Pass thinkingConfig parameters via extra_body in your requests to enable detailed reasoning traces.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!