Gemini CLI
Last updated Oct 6, 2026
supports a custom Google Gemini API base URL. Point it at an AI Gateway custom domain protected by Cloudflare Access. Use cloudflared to generate a short-lived Access token before you start Gemini CLI.
Gemini CLI does not support an API key helper. You must refresh the token when the Access session expires.
Prerequisites
Before you start, you need:
- An AI Gateway with a custom domain.
- Cloudflare Access enabled on the custom domain with a policy that allows your identity.
- Credentials for Google AI Studio. Use Unified Billing credits or store a Google AI Studio key in AI Gateway with BYOK (Store Keys).
cloudflaredinstalled.-
Gemini CLI ↗︎ installed and updated to the latest version.
-
Set the Google Gemini base URL to your AI Gateway custom domain. Replace
ai.example.comwith your custom domain.
bash
export GOOGLE_GEMINI_BASE_URL="https://ai.example.com/google-ai-studio"
- Authenticate to Access and store the resulting token in
GEMINI_API_KEY.
bash
export GEMINI_API_KEY="$(cloudflared access login -app https://ai.example.com)"
- Start Gemini CLI and send a prompt. Requests now route through AI Gateway.
bash
gemini
Run the authentication command again when the Access token expires. You can also add these commands to a bootstrap script that starts Gemini CLI.
For more information about these environment variables, refer to Gemini CLI configuration ↗︎.
To confirm traffic reaches AI Gateway, refer to Verify it works.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai-gateway/integrations/coding-agents/gemini-cli/#page","headline":"Gemini CLI","description":"Route Gemini CLI through an Access-protected AI Gateway custom domain.","url":"https://developers.cloudflare.com/ai-gateway/integrations/coding-agents/gemini-cli/","inLanguage":"en","image":"https://developers.cloudflare.com/ai-gateway/integrations/coding-agents/gemini-cli/og.png?v=bfa3016cbc84b6de","dateModified":"2026-10-06","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Route GitHub Copilot CLI through AI Gateway using the REST API and Unified Billing. title: GitHub Copilot CLI image: https://developers.cloudflare.com/ai-gateway/integrations/coding-agents/github-copilot-cli/og.png?v=bef2cc74d96ccfec
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ai-gateway/llms.txt
Use this file to discover all available pages before exploring further.
Docs