Configure Gemini CLI with AI Gateway
This guide explains how to configure Google Gemini CLI to send requests through Agent Control Plane using the Choreo AI Gateway and a Gemini LLM Service Provider.
By routing requests through Agent Control Plane instead of invoking Google Gemini directly, you can apply security, traffic control, and governance policies such as guardrails and rate limiting. The AI Gateway acts as an intermediary, forwarding requests from Google Gemini CLI to Google Gemini while enforcing these controls.
Prerequisites
Before you begin, make sure you have the following:
- A Google Gemini API key.
- An Agent Control Plane account. Sign up for free.
- Docker and Docker Compose, to run the self-hosted gateway.
- Google Gemini CLI installed.
Step 1: Add an AI Gateway in Agent Control Plane
If an AI Gateway is already created and active, continue to Step 2.
For the same self-hosted gateway flow in a standalone guide, see the Quick Start Guide.
If an AI Gateway is not already created, follow these steps:
-
Sign in to the Console.
-
In the left navigation menu, go to Infrastructure → Gateways.
-
Click Add gateway.
-
Enter the following values:
Field Value Display Name My AI Gateway Name my-ai-gatewayEnvironment Select your environment. Public URL https://localhost:8443 -
Click Create.
-
Follow the instructions shown on the Set up My AI Gateway panel. In the Docker tab, run these steps on the machine that hosts the gateway:
- Download and unzip the gateway package with the command that the panel shows.
- Open the unzipped directory, and run
./scripts/setup.sh. The script creates the listener certificate, the at-rest encryption key, and theapi-platform.envfile. It prints the admin password once, so copy it. - Click Copy next to the third step, and run the command. It appends the control plane host and your gateway token to
api-platform.env. - Start the gateway with
docker compose up.
The Console shows the gateway token only once, when you create the gateway. Run the command in the third step before you close the panel.
If a default gateway port is already in use on your machine, edit the port mappings in the docker-compose.yaml file before you start the gateway, and use the same host port in the Public URL.
Once the AI Gateway is active, you can continue to create the Gemini LLM Service Provider.
Step 2: Create and Deploy a Gemini LLM Service Provider
- Sign in to the Console.
Create a Gemini LLM Service Provider
-
In the left navigation menu, go to Resources → LLM service providers.
-
Click Add service provider.
-
Under Basic Details, enter the following values:
Field Value Name Gemini Version v1.0 Context path /geminicli -
Under Provider Template, select Gemini as the LLM Service Provider.
-
Under Runtime Configuration, in the API key / Credential field, enter your Google Gemini API key.
-
Under Deployment Configuration, select the environment that your gateway belongs to. Open the gateway list that appears, and select My AI Gateway. The list defaults to the managed gateway, so change it.
-
Click Add provider.
The Gemini LLM Service Provider is now deployed to the selected AI Gateway.
Step 3: Configure the API Key Header and Create an API Key
The LLM Service Provider is the endpoint that Google Gemini CLI invokes through Agent Control Plane.
Configure the API Key Header for Google Gemini CLI
Google Gemini CLI sends its API key in a header named x-goog-api-key. The LLM Service Provider must be configured to accept this header.
-
On the provider page, go to the Security tab.
-
Under Authentication, change the Header Key from:
API-Keyto:
x-goog-api-key -
Click Save.
Generate an API Key for Gemini CLI
Google Gemini CLI needs an API key from Agent Control Plane to invoke the deployed LLM Service Provider.
-
On the provider page, open the API Keys tab.
-
Click Create API key.
-
Enter a Display name for the API key.
-
Click Create.
-
Copy and save the generated API key. The Console shows it only once.
This is the key that you provide to Gemini CLI.
-
In the Overview tab, copy and save the Invoke URL.
You use these values when configuring Gemini CLI.
Step 4: Configure Gemini CLI Environment Variables
Open a terminal session where you want to run Google Gemini CLI.
Export the Invoke URL copied from the LLM Service Provider overview page:
export GOOGLE_GEMINI_BASE_URL="<INVOKE URL>"
Export the API key generated in Agent Control Plane:
export GEMINI_API_KEY="<AI GATEWAY API KEY>"
Replace the following placeholders:
<INVOKE URL>with the Invoke URL copied from the LLM Service Provider overview page.<AI GATEWAY API KEY>with the API key generated in Agent Control Plane.
Set these environment variables in the same terminal session where you run Gemini CLI. Alternatively, you can configure them as permanent environment variables.
Configure SSL Certificate Trust
When you use a local Choreo AI Gateway over HTTPS, Gemini CLI must be able to trust the certificate presented by the AI Gateway.
If the AI Gateway uses a valid CA-signed certificate, no additional certificate configuration is required.
If the AI Gateway uses a self-signed certificate, Gemini CLI might fail to connect because of certificate verification errors. In such cases, extract the gateway certificate and point Node.js at it before you run the client:
-
Extract the certificate and save it as
gateway_certificate.pemin the current directory.echo -n | openssl s_client -connect localhost:8443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > gateway_certificate.pemIf you changed the HTTPS host port of the gateway, use that port instead of
8443. -
Export the certificate path in the terminal where you run the client.
export NODE_EXTRA_CA_CERTS="$PWD/gateway_certificate.pem"
For more information, see the official Gemini CLI documentation.
To bypass SSL certificate validation during testing, run:
export NODE_TLS_REJECT_UNAUTHORIZED=0
Step 5: Run Google Gemini CLI
After you set the required environment variables, run Gemini CLI:
gemini
Google Gemini CLI now sends requests through Agent Control Plane instead of directly calling the Gemini API.
Use Case Examples
Implement Choreo AI Gateway Guardrails for Enhanced Control
Choreo AI Gateway guardrails enable granular control over the data exchanged between Gemini CLI and the Google Gemini API.
By applying guardrails, you can enforce security and compliance policies.
For example, you can configure a PII Masking Regex Guardrail on the provider's Guardrails tab to prevent Personally Identifiable Information (PII) from reaching the Google Gemini API. If a user submits a prompt containing PII, the guardrail evaluates the request against defined patterns and redacts the matches before they reach the Google Gemini API.

For more information, see the PII Masking Regex policy in the Policy Hub. To block prompt injection with guardrails, see Block Prompt Injection with Guardrails.
Rate Limiting at the AI Gateway
Choreo AI Gateway supports request-based and token-based rate limiting for AI APIs. This lets you control Gemini CLI usage when requests are routed through the AI Gateway.
For example, set a consumer-level token limit on the provider's Rate Limiting tab. Each developer's key then gets its own quota, and the AI Gateway returns HTTP 429 once a developer reaches it. For the steps, see Enforce Token-Based Rate Limiting.
This helps control token consumption and avoid unexpected costs.
The following screenshot illustrates Gemini CLI operating under a minute-level token limit, where requests are delayed until the quota is refreshed.

Multi-Model Routing
Choreo AI Gateway supports multi-model routing, which lets you dynamically route requests to different AI models based on defined conditions or strategies.
This is useful when you work with Gemini CLI in scenarios such as fallback handling, load balancing, or cost optimization. Instead of sending all requests to a single model, the AI Gateway can distribute or reroute requests across multiple endpoints.
To set it up, follow these steps:
- On the provider page, open the Guardrails tab.
- Under Global Guardrails, click Add guardrail, and then select Model Round Robin.
- Expand models, and click Add item for each model. Add
gemini-2.5-flash-liteandgemini-2.5-flash. - For each item, enter the provider's own ID in Provider. The ID is the value after
/llm-providers/view/in the page URL. If you leave Provider empty, the deployment fails. - Click Add, and then click Save at the bottom of the tab.
For example, the following screenshot illustrates Gemini CLI being routed through the Choreo AI Gateway, where the user explicitly requests the gemini-3.1-pro-preview model. Since this model has exceeded its usage limits, the request fails.

With multi-model routing configured using a Round Robin strategy across gemini-2.5-flash-lite and gemini-2.5-flash, the behavior changes. Even though Gemini CLI continues to request the gemini-3.1-pro-preview model, the AI Gateway dynamically routes the request to one of the available configured models.
As a result, the request is successfully processed without requiring any changes on the client side.

For more information, see the Model Round Robin policy in the Policy Hub and Set Up a Multi-Model LLM Service Provider.
Prompt Decorator
Choreo AI Gateway supports Prompt Decorators, which let you modify or enrich prompts before the AI Gateway sends them to the backend AI provider. This is useful for enforcing consistent instructions, adding system-level context, or guiding model behavior without requiring changes in the client application.
As an example, you can configure a Prompt Decorator on the provider's Guardrails tab to prepend a system instruction to all incoming prompts:
You are operating behind an enterprise AI gateway. Follow these rules:
1. Be concise and direct.
2. Never output secrets, tokens, or credentials.
3. When editing code, explain the change briefly.
4. When unsure, state the assumption explicitly.
5. At the end of every response, add the text: 'Routed through WSO2 AI Gateway'.
Once configured, the AI Gateway automatically modifies every request sent from Gemini CLI to include this instruction before forwarding it to the AI provider.

For more information, see the Prompt Decorator policy in the Policy Hub and Enforce a Consistent AI Persona.
Related Guides
- Configure Claude Code with AI Gateway
- Configure Codex CLI with AI Gateway
- Configure GitHub Copilot with AI Gateway
- Route LLM Traffic Through a Self-Hosted Gateway
Was this page helpful?