Skip to content

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.

Prerequisites

Before you start, you need:

  1. 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.

    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"
  2. 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.