Gemini CLI
Gemini CLI is Google's terminal client for the Gemini model family. It reads its endpoint and credential from environment variables, so pointing it at the Cequence AI Gateway is a matter of setting them to the right values. It also reads custom headers, which is how the Agent Access Key travels when a route needs one alongside a provider key.
Which setup do you need?
| What you get | Use it when | |
|---|---|---|
| LLM Registry entry | The model, governed | You only need model access |
| Agent Persona | The model and the persona's MCP tools, under one set of policies | You want the CLI to use tools as well as a model |
Which credentials you send depends on the entry's credential mode. If you haven't read which credentials your entry needs, start there.
Connect to an LLM Registry entry
Gemini CLI only supports the Gemini provider. Pick the credential mode on the entry's Provider Credential panel.
- Gemini
- API Key
- Passthrough (Agent Access Key Required)
- Passthrough (No Agent Access Key)
The gateway stores your Google API key, so Gemini CLI sends only its Agent Access Key.
export GOOGLE_GEMINI_BASE_URL="https://<gateway-host>/llm/<url-prefix>"
export GEMINI_API_KEY="<your-agent-access-key>"
gemini -m "<model-id>" -p "Hello"
Gemini CLI sends GEMINI_API_KEY as x-goog-api-key. The gateway authenticates the caller from that header, attaches the stored Google credential on the outbound side, and forwards to Google.
The Connect flow additionally sets GEMINI_CLI_CUSTOM_HEADERS="X-API-Key: <your-agent-access-key>", a fallback header the gateway also honours. It's harmless to include and unnecessary on its own.
Two credentials travel, in two separate variables.
export GOOGLE_GEMINI_BASE_URL="https://<gateway-host>/llm/<url-prefix>"
export GEMINI_API_KEY="<your-gemini-api-key>"
export GEMINI_CLI_CUSTOM_HEADERS="X-Agent-Key: <your-agent-access-key>"
gemini -m "<model-id>" -p "Hello"
GEMINI_API_KEY carries your own Gemini key, which the gateway forwards unchanged. GEMINI_CLI_CUSTOM_HEADERS carries the Agent Access Key on X-Agent-Key, which is where the gateway looks for it on a passthrough entry.
The header name differs between the two modes. On an API Key entry the fallback header is X-API-Key; on a passthrough entry it must be X-Agent-Key, because the gateway looks only there once a provider key occupies the other slots.
With Require an agent access key off, only your Gemini key travels.
export GOOGLE_GEMINI_BASE_URL="https://<gateway-host>/llm/<url-prefix>"
export GEMINI_API_KEY="<your-gemini-api-key>"
gemini -m "<model-id>" -p "Hello"
Connect through an Agent Persona
An Agent Persona bundles a set of MCP tools and, optionally, LLM access under one endpoint. Wiring Gemini CLI to it covers two sockets:
- The tools socket, at
https://<gateway-host>/p/<persona-id>, registered withgemini mcp add. - The model route, at
https://<gateway-host>/p/<persona-id>/llm/<registry-entry-id>, set through the same environment variables as above.
One Agent Access Key covers both. The same key authenticates the model route and the tools socket, whichever Inbound Authentication method the persona uses.
Two separate settings are in play here, and only one of them changes the code below.
- The entry's credential mode — API Key or Passthrough — decides which credentials you send. This is what the tabs below switch between, exactly as on the route above.
- The persona's own Inbound Authentication method — Interactive or Passthrough — decides how the persona identifies you. Either way an Agent Access Key is issued, and neither changes the configuration below.
Because a persona always identifies you by an Agent Access Key, the entry's third mode — Passthrough (No Agent Access Key) — has no tab here. It applies to the LLM Registry entry route only.
- Gemini
- API Key
- Passthrough (Agent Access Key Required)
export GOOGLE_GEMINI_BASE_URL="https://<gateway-host>/p/<persona-id>/llm/<registry-entry-id>"
export GEMINI_API_KEY="<your-agent-access-key>"
export GEMINI_CLI_CUSTOM_HEADERS="X-API-Key: <your-agent-access-key>"
export GEMINI_CLI_AIGW_AGENT_KEY="$GEMINI_API_KEY"
gemini mcp add -t http <persona-name> \
--url "https://<gateway-host>/p/<persona-id>" \
-H "x-api-key: ${GEMINI_API_KEY}"
What each line does:
GOOGLE_GEMINI_BASE_URLpoints Gemini CLI at the persona-scoped LLM route. That path is what makes the call flow through the persona's guardrails.GEMINI_API_KEYis the Agent Access Key. Gemini CLI sends it onx-goog-api-key, which the gateway accepts on this mode.GEMINI_CLI_CUSTOM_HEADERSadds the same key onX-API-Key, a fallback header the gateway also honours.GEMINI_CLI_AIGW_AGENT_KEYmirrors the key for the wrapper's internal use.gemini mcp addregisters the persona's tool socket with the same key. From here the CLI can call the model and invoke the persona's tools with one credential.
export GOOGLE_GEMINI_BASE_URL="https://<gateway-host>/p/<persona-id>/llm/<registry-entry-id>"
export GEMINI_API_KEY="<your-gemini-api-key>"
export GEMINI_CLI_CUSTOM_HEADERS="X-Agent-Key: <your-agent-access-key>"
gemini mcp add -t http <persona-name> \
--url "https://<gateway-host>/p/<persona-id>" \
-H "X-Agent-Key: <your-agent-access-key>"
GEMINI_API_KEY belongs to your own Gemini key here, so the Agent Access Key moves to GEMINI_CLI_CUSTOM_HEADERS on X-Agent-Key for the model route, and onto the -H flag for the tools socket.
Run gemini mcp list afterwards to confirm the persona endpoint is registered.
Registering the tools socket with a config file
Instead of gemini mcp add, the same socket can be declared in Gemini CLI's MCP settings:
{
"mcpServers": {
"<persona-name>": {
"httpUrl": "https://<gateway-host>/p/<persona-id>",
"headers": { "X-Agent-Key": "<your-agent-access-key>" }
}
}
}
The headers block is always needed on this route: an Agent Access Key is required whatever the entry's credential mode.
Where to find each value
| Placeholder | Where to find it |
|---|---|
<gateway-host> | Host from the entry's Overview tab |
<url-prefix> | The URL prefix field on the entry's Overview tab |
<model-id> | A model identifier from the entry's Allowed Models list, for example gemini-3.6-flash |
<persona-id> | The persona's ID on the Agent Persona page |
<registry-entry-id> | The LLM Registry entry's ID in the entry's URL |
<persona-name> | Any short name you want Gemini CLI to use for this MCP server locally |
<your-agent-access-key> | Generate from the entry's Agent Access Keys step, or the persona's Connect flow. Plaintext is shown once. |
<your-gemini-api-key> | Your own Google Gemini API key, needed only in the passthrough modes |
Tips
- One key covers both surfaces. In the persona setup the same Agent Access Key authenticates the LLM call and the MCP tool socket. Generate one key and use it in both places.
- Watch the header name.
X-API-Keyon an API Key entry,X-Agent-Keyon a passthrough one. Sending the wrong one on a passthrough route fails as though the key were invalid. - Restart the CLI after any env change. Gemini CLI reads its environment at startup, so export in a fresh shell before invoking
gemini. - Verify MCP registration. Run
gemini mcp listaftergemini mcp addto confirm the persona endpoint is registered. - Unset when finished. If these variables are set only for testing, run
unset GOOGLE_GEMINI_BASE_URL GEMINI_API_KEY GEMINI_CLI_CUSTOM_HEADERS GEMINI_CLI_AIGW_AGENT_KEYbefore returning to your normal Gemini CLI usage.
Cequence AI Gateway