[ Web Proxy ]
URL:
Viewing: https://developers.cloudflare.com/ai-gateway/integrations/coding-agents/github-copilot-cli/ [Back]  [Original]

GitHub Copilot CLI Cloudflare AI Gateway docsSkip to content
SearchCtrlKLog in
  1. Home
  2. /AI Gateway
  3. /
    Integrations
  4. /Coding agents
  5. /GitHub Copilot CLI

GitHub Copilot CLI

Last updated Jul 2, 2026Copy as MarkdownView as MarkdownAgent setup
OverviewPrerequisites

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:

  • GitHub Copilot CLI installed. To install it, refer to Installing GitHub Copilot CLI .
  • A Cloudflare API token with AI Gateway permission.
  • 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.
  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.

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

PreviousClaude DesktopNextOpenAI Codex

Was this helpful?

YesNo
Edit pageReport issue
[]

Web Proxy Viewer  |  New URL  |  Original Page