GitHub Copilot CLI
GitHub Copilot CLI ↗ supports bring-your-own-key (BYOK) model providers configured through environment variables. Route it through AI Gateway's REST API, an OpenAI-compatible /chat/completions endpoint authenticated with a Cloudflare API token. Third-party models are billed through Unified Billing, so no provider API keys are needed in your environment. Alternatively, you can store your own provider API keys in AI Gateway with BYOK (Store Keys) and use the same Cloudflare API token to authenticate — AI Gateway resolves the stored key on each request.
Unlike Claude Code, GitHub Copilot CLI authenticates the model provider with a single Authorization header and cannot send custom request headers. This is why the configuration uses the REST API — it accepts a Cloudflare API token in the standard Authorization header — rather than the gateway token and cf-aig-authorization header flow used for Claude Code. Because Copilot CLI cannot set the cf-aig-gateway-id header either, requests route through your account's default gateway.
Before you start, you need:
- GitHub Copilot CLI installed. To install it, refer to Installing GitHub Copilot CLI ↗.
- A Cloudflare API token with
AI Gatewaypermission. - Credits loaded on your account for third-party models.
- A model that supports tool calling and streaming. For best results, use a model with a context window of at least 128k tokens.
-
Set the provider environment variables. GitHub Copilot CLI reads these on startup and appends
/chat/completionsto the base URL. The commands set these variables for the current session. To persist them, add them to your shell profile (for example,~/.zshrcor~/.bashrc).Replace
<ACCOUNT_ID>with your Cloudflare account ID and<CF_API_TOKEN>with your Cloudflare API token. SetCOPILOT_MODELto any supported model inprovider/modelformat.Terminal window export COPILOT_PROVIDER_TYPE="openai"export COPILOT_PROVIDER_BASE_URL="https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/ai/v1"export COPILOT_PROVIDER_API_KEY="<CF_API_TOKEN>"export COPILOT_MODEL="openai/gpt-4.1"PowerShell $env:COPILOT_PROVIDER_TYPE = "openai"$env:COPILOT_PROVIDER_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/ai/v1"$env:COPILOT_PROVIDER_API_KEY = "<CF_API_TOKEN>"$env:COPILOT_MODEL = "openai/gpt-4.1" -
Start GitHub Copilot CLI and send a prompt. Requests now route through AI Gateway.
Terminal window copilot
To confirm traffic reaches AI Gateway, refer to Verify it works.