> ## Documentation Index
> Fetch the complete documentation index at: https://copilot-api.nick3.top/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment variables for Copilot API

> Configure GitHub token, data directory, OAuth app, enterprise URL, admin access, and proxy settings through environment variables before starting the server.

Environment variables let you configure Copilot API without editing files, which is useful for Docker containers, scripted setups, and any environment where interactive prompts are not available. Variables are read at startup; changing them requires a server restart.

## Variable reference

| Variable                     | Description                                                                                                                                                                                                 | Default                                                                                          |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `GH_TOKEN`                   | GitHub personal access token. Skips the interactive OAuth flow. Must be a token generated by the `auth` subcommand.                                                                                         | None                                                                                             |
| `COPILOT_API_HOME`           | Custom data directory for tokens, `config.json`, and `admin.sqlite`. Equivalent to `--api-home`.                                                                                                            | `~/.local/share/copilot-api` (Linux/macOS) or `%USERPROFILE%\.local\share\copilot-api` (Windows) |
| `COPILOT_API_OAUTH_APP`      | OAuth app identifier. Set to `opencode` to use the opencode GitHub Copilot OAuth app. Equivalent to `--oauth-app`.                                                                                          | None (uses the default Copilot app)                                                              |
| `COPILOT_API_ENTERPRISE_URL` | GitHub Enterprise hostname (e.g. `company.ghe.com`). Equivalent to `--enterprise-url`.                                                                                                                      | None                                                                                             |
| `ADMIN_TOKEN`                | Token required to access the Admin UI and Admin API from non-loopback addresses. When not set, admin routes are only accessible from `localhost`, `127.0.0.1`, or `::1`.                                    | None                                                                                             |
| `ANTHROPIC_API_KEY`          | Anthropic API key for accurate Claude token counting. Equivalent to `anthropicApiKey` in `config.json`. The token counting endpoint is free; a \$5 minimum balance is required only to activate API access. | None                                                                                             |
| `COPILOT_API_KEY`            | **Deprecated.** Legacy single API key for request authentication. Prefer `auth.apiKeys` in `config.json`. Used only when `auth.apiKeys` is empty.                                                           | None                                                                                             |
| `HTTP_PROXY`                 | HTTP proxy URL. Applied when you start the server with the `--proxy-env` flag.                                                                                                                              | None                                                                                             |
| `HTTPS_PROXY`                | HTTPS proxy URL. Applied when you start the server with the `--proxy-env` flag.                                                                                                                             | None                                                                                             |

## Usage examples

### Providing a GitHub token directly

Useful in Docker or CI environments where interactive device-code authentication is not possible:

```bash theme={null}
GH_TOKEN=ghp_your_token npx @nick3/copilot-api@latest start
```

### Setting a custom data directory

```bash theme={null}
COPILOT_API_HOME=/opt/copilot-data npx @nick3/copilot-api@latest start
```

### Using opencode OAuth

```bash theme={null}
COPILOT_API_OAUTH_APP=opencode npx @nick3/copilot-api@latest start
```

### Connecting to GitHub Enterprise

```bash theme={null}
COPILOT_API_ENTERPRISE_URL=company.ghe.com npx @nick3/copilot-api@latest start
```

### Enabling remote admin access

```bash theme={null}
ADMIN_TOKEN=your_secure_token npx @nick3/copilot-api@latest start
```

Once set, include the token in admin requests as `x-admin-token: <token>` or `Authorization: Bearer <token>`.

### Enabling Claude token counting

```bash theme={null}
ANTHROPIC_API_KEY=sk-ant-... npx @nick3/copilot-api@latest start
```

### Using a proxy

```bash theme={null}
HTTPS_PROXY=http://proxy.example.com:8080 npx @nick3/copilot-api@latest start --proxy-env
```

<Note>
  Proxy variables (`HTTP_PROXY`, `HTTPS_PROXY`) are only read when you pass the `--proxy-env` flag to the `start` command. Without that flag, proxy settings are ignored even if the variables are set.
</Note>

## Variable precedence for API keys

When determining which API keys to enforce, the server checks in this order:

1. `auth.apiKeys` in `config.json` (preferred)
2. `COPILOT_API_KEY` environment variable (deprecated fallback)
3. `apiKey` field in `config.json` (deprecated fallback)

If none of these are set, authentication is disabled and all requests are accepted.

## Docker compose example

```yaml theme={null}
services:
  copilot-api:
    build: .
    ports:
      - "4141:4141"
    environment:
      - GH_TOKEN=your_github_token_here
      - ADMIN_TOKEN=your_admin_token_here
      - ANTHROPIC_API_KEY=sk-ant-...
    volumes:
      - ./copilot-data:/root/.local/share/copilot-api
    restart: unless-stopped
```

<Warning>
  Never commit files containing `GH_TOKEN`, `ADMIN_TOKEN`, or `ANTHROPIC_API_KEY` to source control. Use secrets management or environment injection provided by your deployment platform.
</Warning>
