| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/ai-gateway/integrations/coding-agents/github-copilot-cli/ | [Back] [Original] |
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:
AI Gateway permission.Set the provider environment variables. GitHub Copilot CLI reads these on startup and appends /chat/completions to the base URL. The commands set these variables for the current session. To persist them, add them to your shell profile (for example, ~/.zshrc or ~/.bashrc).
Replace <ACCOUNT_ID> with your Cloudflare account ID and <CF_API_TOKEN> with your Cloudflare API token. Set COPILOT_MODEL to any supported model in provider/model format.
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"$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.
copilot
Note
GitHub Copilot CLI keeps a built-in catalog of known models and their token limits. If your selected model is not in the catalog, Copilot CLI prints a warning and falls back to default token limits. You can ignore the warning, or set the limits explicitly to match your model:
export COPILOT_PROVIDER_MAX_PROMPT_TOKENS="200000"
export COPILOT_PROVIDER_MAX_OUTPUT_TOKENS="32000"To confirm traffic reaches AI Gateway, refer to Verify it works.
| Web Proxy Viewer | New URL | Original Page |