> For the complete documentation index, see [llms.txt](https://docs.avis.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avis.xyz/integrations/coding/copilot.md).

# Copilot CLI

## GitHub Copilot CLI Integration Guide

This document explains how to integrate [GitHub Copilot CLI](https://github.com/github/copilot-cli) with AVIS, using Copilot CLI's official **BYOK (Bring Your Own Key)** support for custom model providers.

### What is GitHub Copilot CLI

GitHub Copilot CLI is GitHub's terminal coding agent — it reads/edits files and runs commands as part of an agentic loop. By default it uses GitHub's own Copilot models, but it officially supports pointing at any OpenAI Chat-Completions-compatible endpoint (or an Anthropic-compatible one) via environment variables — no GitHub Copilot subscription model lock-in required for the model itself.

### 1) Install Copilot CLI

```bash
# npm
npm install -g @github/copilot

# Homebrew
brew install copilot-cli

# macOS / Linux (curl)
curl -fsSL https://gh.io/copilot-install | bash

# Windows Package Manager
winget install GitHub.Copilot
```

### 2) Get an AVIS API key

See Authentication — sign in at [avis.xyz](https://avis.xyz), go to **Settings → API Keys**, and create one.

### 3) Configure AVIS as a custom provider

Copilot CLI reads provider config entirely from environment variables — there is no config file for this.

| Variable                    | Required              | Value                                                                                           |
| --------------------------- | --------------------- | ----------------------------------------------------------------------------------------------- |
| `COPILOT_PROVIDER_BASE_URL` | Yes                   | AVIS's API base URL (see options below)                                                         |
| `COPILOT_PROVIDER_TYPE`     | No (default `openai`) | `openai` for AVIS's OpenAI-compatible surface, `anthropic` for the Anthropic-compatible surface |
| `COPILOT_PROVIDER_API_KEY`  | Yes for AVIS          | your AVIS API key                                                                               |
| `COPILOT_MODEL`             | Yes                   | the model ID (see §4)                                                                           |

#### Option A — OpenAI-compatible surface (recommended, covers every AVIS model)

```bash
export COPILOT_PROVIDER_BASE_URL="https://api.avis.xyz/api/openai/v1"
export COPILOT_PROVIDER_API_KEY="<your-avis-api-key>"
export COPILOT_MODEL="claude-sonnet-5"
copilot
```

`COPILOT_PROVIDER_TYPE` defaults to `openai`, so it can be omitted here.

#### Option B — Anthropic-compatible surface (Anthropic-brand models only)

```bash
export COPILOT_PROVIDER_TYPE=anthropic
export COPILOT_PROVIDER_BASE_URL="https://api.avis.xyz/api/anthropic"
export COPILOT_PROVIDER_API_KEY="<your-avis-api-key>"
export COPILOT_MODEL="claude-sonnet-5"
copilot
```

### 4) Pick a model

* Under **Option A** (OpenAI-compatible), `COPILOT_MODEL` must be AVIS's flat canonical id (no `anthropic/`/`openai/` prefix) — query the live catalog:

  ```bash
  curl https://api.avis.xyz/api/openai/v1/models \
    -H "x-api-key: $COPILOT_PROVIDER_API_KEY" | jq '.data[].id'
  ```
* Under **Option B** (Anthropic-compatible), `COPILOT_MODEL` is the bare Anthropic-native model name (e.g. `claude-opus-5`), matching what Claude Code and Claude Desktop send — see Claude Code's integration guide §4 for background on this surface's model-id handling.

Copilot CLI requires the model to support tool/function calling and streaming, with a recommended minimum context window of 128k tokens — pick accordingly from AVIS's catalog.

### 5) Run Copilot CLI

```bash
cd your-project
copilot
```

List provider setup examples (built into the CLI):

```bash
copilot help providers
```

### 6) Troubleshooting

* `401 Unauthorized`
  * `COPILOT_PROVIDER_API_KEY` isn't exported in the shell Copilot CLI was launched from.
  * AVIS key is invalid or revoked — verify directly: `curl -H "x-api-key: $COPILOT_PROVIDER_API_KEY" https://api.avis.xyz/api/openai/v1/models`.
* `404` / model not found
  * `COPILOT_MODEL` doesn't match AVIS's catalog for the surface you selected — flat id for `openai` type, bare Anthropic-native id for `anthropic` type (§4).
* `403` with a valid key
  * Account balance is depleted — see Errors.
* Model behaves poorly / tool calls fail
  * Confirm the chosen model actually supports tool calling and streaming, and has at least a 128k context window — Copilot CLI's own stated requirement, not AVIS-specific.
* Copilot still calls GitHub's own models instead of AVIS
  * One of the required env vars (`COPILOT_PROVIDER_BASE_URL`, `COPILOT_PROVIDER_API_KEY`, `COPILOT_MODEL`) isn't set in the shell `copilot` was launched from — BYOK only activates when all the required variables for the chosen `COPILOT_PROVIDER_TYPE` are present.

### 7) Minimal End-to-End Checklist

1. AVIS API key created (§2).
2. `COPILOT_PROVIDER_BASE_URL`, `COPILOT_PROVIDER_API_KEY`, `COPILOT_MODEL` exported (and `COPILOT_PROVIDER_TYPE` if using Option B) (§3).
3. Model ID confirmed against the right AVIS catalog for the chosen surface (§4).
4. `copilot` starts and a message returns model output from the AVIS-backed model.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.avis.xyz/integrations/coding/copilot.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
