@jeffreycao/copilot-api 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -208
- package/README.zh-CN.md +198 -223
- package/dist/{auth-B7GYl9ml.js → auth-DflW0qnE.js} +3 -3
- package/dist/{auth-B7GYl9ml.js.map → auth-DflW0qnE.js.map} +1 -1
- package/dist/auth-YxKQGwfw.js +2 -0
- package/dist/{config-HwhWjAUw.js → config-BTzeWHkr.js} +55 -10
- package/dist/config-BTzeWHkr.js.map +1 -0
- package/dist/{debug-mGFDM9t3.js → debug-BwkElUPu.js} +2 -2
- package/dist/{debug-mGFDM9t3.js.map → debug-BwkElUPu.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{models-CMxrj0E1.js → models-FKEDPPpH.js} +2 -2
- package/dist/{models-CMxrj0E1.js.map → models-FKEDPPpH.js.map} +1 -1
- package/dist/{server-CcDq6UwX.js → server-kYZM25jp.js} +74 -34
- package/dist/server-kYZM25jp.js.map +1 -0
- package/dist/{start-BNfSF4DG.js → start-CIEyg9gn.js} +7 -7
- package/dist/{start-BNfSF4DG.js.map → start-CIEyg9gn.js.map} +1 -1
- package/dist/{token-BDTTEbx3.js → token-CVbmPxHp.js} +3 -3
- package/dist/{token-BDTTEbx3.js.map → token-CVbmPxHp.js.map} +1 -1
- package/package.json +4 -3
- package/dist/auth-_h8KBapT.js +0 -2
- package/dist/config-HwhWjAUw.js.map +0 -1
- package/dist/server-CcDq6UwX.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
# Copilot API
|
|
1
|
+
# Copilot API
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="./docs/hero/copilot-api-hero.svg" alt="Copilot API - Universal AI Gateway" width="1600" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Universal AI Gateway</strong><br />
|
|
9
|
+
One Gateway. Any Client. Multiple AI Providers.<br />
|
|
10
|
+
Chat Completions · OpenAI Responses · Anthropic Messages
|
|
11
|
+
</p>
|
|
2
12
|
|
|
3
13
|
<p align="center">
|
|
4
14
|
<a href="https://www.npmjs.com/package/@jeffreycao/copilot-api"><img src="https://img.shields.io/npm/v/@jeffreycao/copilot-api.svg" alt="npm version"></a>
|
|
@@ -8,80 +18,9 @@
|
|
|
8
18
|
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node-%3E%3D22.13.0-green.svg" alt="Node >= 22.13.0"></a>
|
|
9
19
|
</p>
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- [Copilot API Proxy](#copilot-api-proxy)
|
|
16
|
-
- [Table of Contents](#table-of-contents)
|
|
17
|
-
- [Important Notes](#important-notes)
|
|
18
|
-
- [Project Overview](#project-overview)
|
|
19
|
-
- [Quick Start](#quick-start)
|
|
20
|
-
- [Features](#features)
|
|
21
|
-
- [Prerequisites](#prerequisites)
|
|
22
|
-
- [Installation](#installation)
|
|
23
|
-
- [Running from Source](#running-from-source)
|
|
24
|
-
- [Development Mode](#development-mode)
|
|
25
|
-
- [Production Mode](#production-mode)
|
|
26
|
-
- [Using with npx](#using-with-npx)
|
|
27
|
-
- [Using with Docker](#using-with-docker)
|
|
28
|
-
- [Electron Desktop App](#electron-desktop-app)
|
|
29
|
-
- [Desktop App Screenshots](#desktop-app-screenshots)
|
|
30
|
-
- [Using with Claude Code](#using-with-claude-code)
|
|
31
|
-
- [Interactive Setup with `--claude-code` flag](#interactive-setup-with---claude-code-flag)
|
|
32
|
-
- [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson)
|
|
33
|
-
- [Using with OpenCode](#using-with-opencode)
|
|
34
|
-
- [Minimal setup](#minimal-setup)
|
|
35
|
-
- [Using with Codex](#using-with-codex)
|
|
36
|
-
- [Codex `config.toml` Reference](#codex-configtoml-reference)
|
|
37
|
-
- [GPT Tool Search](#gpt-tool-search)
|
|
38
|
-
- [Plugin Integrations](#plugin-integrations)
|
|
39
|
-
- [Claude Code plugin integration (marketplace-based)](#claude-code-plugin-integration-marketplace-based)
|
|
40
|
-
- [Opencode plugin](#opencode-plugin)
|
|
41
|
-
- [Using the Usage Viewer](#using-the-usage-viewer)
|
|
42
|
-
- [Usage Viewer Screenshot](#usage-viewer-screenshot)
|
|
43
|
-
- [Command Structure](#command-structure)
|
|
44
|
-
- [Command Line Options](#command-line-options)
|
|
45
|
-
- [Global Options](#global-options)
|
|
46
|
-
- [Start Command Options](#start-command-options)
|
|
47
|
-
- [Auth Command Options](#auth-command-options)
|
|
48
|
-
- [Debug Command Options](#debug-command-options)
|
|
49
|
-
- [Configuration (config.json)](#configuration-configjson)
|
|
50
|
-
- [API Authentication](#api-authentication)
|
|
51
|
-
- [API Endpoints](#api-endpoints)
|
|
52
|
-
- [OpenAI Compatible Endpoints](#openai-compatible-endpoints)
|
|
53
|
-
- [Codex Backend Proxy Endpoints](#codex-backend-proxy-endpoints)
|
|
54
|
-
- [Anthropic Compatible Endpoints](#anthropic-compatible-endpoints)
|
|
55
|
-
- [Usage Monitoring Endpoints](#usage-monitoring-endpoints)
|
|
56
|
-
- [Admin / Configuration Endpoints](#admin--configuration-endpoints)
|
|
57
|
-
- [Example Usage](#example-usage)
|
|
58
|
-
- [Usage Tips](#usage-tips)
|
|
59
|
-
- [CLAUDE.md or AGENTS.md Recommended Content](#claudemd-or-agentsmd-recommended-content)
|
|
60
|
-
|
|
61
|
-
## Important Notes
|
|
62
|
-
|
|
63
|
-
> [!IMPORTANT]
|
|
64
|
-
> **Before using, please be aware of the following:**
|
|
65
|
-
>
|
|
66
|
-
> 1. **Codex configuration:** When using with Codex, add the gateway provider to `~/.codex/config.toml`. See [Codex `config.toml` Reference](#codex-configtoml-reference).
|
|
67
|
-
>
|
|
68
|
-
> 2. **Claude Code configuration:** When using with Claude Code, please configure the model ID as `claude-opus-4-8[1m]`. Example claude `settings.json` see [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson).
|
|
69
|
-
>
|
|
70
|
-
> 3. **OpenCode configuration:** When using with OpenCode, configure `~/.config/opencode/opencode.json` with `@ai-sdk/anthropic`. See [Using with OpenCode](#using-with-opencode).
|
|
71
|
-
>
|
|
72
|
-
> 4. **Built-in `copilot`, `codex` and third-party providers:** Run `npx @jeffreycao/copilot-api@latest auth` and choose `copilot`, `codex`, `deepseek`, `custom`, or other providers.
|
|
73
|
-
>
|
|
74
|
-
> 5. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
## Project Overview
|
|
79
|
-
|
|
80
|
-
A small AI gateway that can use GitHub Copilot, the built-in `codex` provider, or configured third-party providers such as DashScope. GitHub Copilot is optional: if no GitHub token is available, the server can still start in provider-only mode as long as at least one enabled provider is configured.
|
|
81
|
-
|
|
82
|
-
The gateway exposes OpenAI- and Anthropic-compatible APIs from one local endpoint, so tools like [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview), OpenCode, Codex, and OpenAI-compatible clients can share the same local server.
|
|
83
|
-
|
|
84
|
-
On the GitHub Copilot path, the gateway prefers Copilot's native Anthropic-style Messages API when available, preserving more Claude-native behavior for tool-heavy workflows.
|
|
21
|
+
<p align="center">
|
|
22
|
+
English | <a href="./README.zh-CN.md">简体中文</a>
|
|
23
|
+
</p>
|
|
85
24
|
|
|
86
25
|
## Quick Start
|
|
87
26
|
|
|
@@ -108,134 +47,41 @@ curl http://localhost:4141/v1/models
|
|
|
108
47
|
|
|
109
48
|
From here, jump to the guide for your client: [Claude Code](#using-with-claude-code), [OpenCode](#using-with-opencode), [Codex](#using-with-codex), or run it with [Docker](#using-with-docker).
|
|
110
49
|
|
|
111
|
-
##
|
|
50
|
+
## Highlights
|
|
112
51
|
|
|
113
|
-
- **
|
|
114
|
-
- **
|
|
115
|
-
- **
|
|
116
|
-
- **
|
|
117
|
-
- **
|
|
118
|
-
- **Agent-friendly Claude handling on Copilot**: Prefer native `/v1/messages` when available, preserve Claude-style tool flows, support Anthropic beta features, Claude WebSearch through Responses-capable models, and keep subagent/session markers intact.
|
|
119
|
-
- **Claude Code and OpenCode integration**: Works with Claude Code and OpenCode, including direct Anthropic-compatible usage through `@ai-sdk/anthropic`.
|
|
120
|
-
- **Flexible auth and deployment options**: Supports interactive login or direct tokens, individual/business/enterprise plans, GitHub Enterprise, opencode OAuth, and custom data directories.
|
|
121
|
-
- **Multi-provider routing**: Expose provider-specific `/:provider/...` routes or use `model: "provider/model"` on the top-level API.
|
|
52
|
+
- **Unified API Gateway**: Serve OpenAI-compatible Chat Completions (`/v1/chat/completions`), the OpenAI Responses API (`/v1/responses`), and Anthropic-compatible Messages (`/v1/messages`) from one local endpoint.
|
|
53
|
+
- **Multi-Provider**: Route GitHub Copilot, the built-in `codex` provider, and third-party providers (Kimi, DeepSeek, DashScope, OpenRouter, OpenCode Go, or a custom provider) behind the same gateway. GitHub Copilot is optional — with at least one enabled provider, the server starts in provider-only mode without a GitHub token.
|
|
54
|
+
- **Coding Agent Ready**: First-class setups for Claude Code, OpenCode, and Codex, including the interactive `--claude-code` launcher and a merged model catalog for Codex.
|
|
55
|
+
- **Streaming & WebSocket**: SSE streaming on all three client-facing protocols. Upstream Copilot Responses traffic selects WebSocket or HTTP from each model's advertised endpoints; streamed Responses traffic for the built-in `codex` provider uses WebSocket by default and uses HTTP when `useResponsesApiWebSocket` is disabled.
|
|
56
|
+
- **Desktop App**: Electron GUI with GitHub Copilot sign-in, Codex OAuth, provider configuration, token usage, logs, and one-click start/stop.
|
|
122
57
|
|
|
123
|
-
##
|
|
58
|
+
## Compatibility
|
|
124
59
|
|
|
125
|
-
-
|
|
126
|
-
- Node.js if you plan to run the published CLI with `npx`
|
|
127
|
-
- GitHub account with Copilot subscription only if you want to use the GitHub Copilot provider
|
|
128
|
-
- An API key or OAuth login for at least one configured provider if you want to run without GitHub Copilot
|
|
60
|
+
Every client talks to the same local endpoint. The gateway routes each request to GitHub Copilot, the built-in `codex` provider, or a configured third-party provider, translating between protocols when the provider speaks a different one.
|
|
129
61
|
|
|
130
|
-
|
|
62
|
+
**Client / Protocol Matrix**
|
|
131
63
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
The project can be run from source in several ways:
|
|
141
|
-
|
|
142
|
-
### Development Mode
|
|
143
|
-
|
|
144
|
-
```sh
|
|
145
|
-
bun run dev start
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### Production Mode
|
|
149
|
-
|
|
150
|
-
```sh
|
|
151
|
-
bun run start start
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
> The trailing `start` is the CLI subcommand passed to `src/main.ts`, not a typo: `bun run dev start` runs watch mode, `bun run start start` runs production.
|
|
155
|
-
|
|
156
|
-
## Using with npx
|
|
157
|
-
|
|
158
|
-
You can run the project directly using npx:
|
|
159
|
-
|
|
160
|
-
> [!IMPORTANT]
|
|
161
|
-
> Token usage storage uses Node's built-in `node:sqlite` module when running with `npx`. It is enabled on Node.js >= 22.13.0. On Node.js < 22.13.0, the CLI still starts, but token usage storage is disabled.
|
|
162
|
-
>
|
|
163
|
-
> If you want token usage storage without upgrading Node.js, run the published CLI with Bun instead: `bunx --bun @jeffreycao/copilot-api@latest start`.
|
|
164
|
-
|
|
165
|
-
```sh
|
|
166
|
-
npx @jeffreycao/copilot-api@latest start
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
With options:
|
|
170
|
-
|
|
171
|
-
```sh
|
|
172
|
-
npx @jeffreycao/copilot-api@latest start --port 8080
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
For authentication or provider configuration only:
|
|
176
|
-
|
|
177
|
-
```sh
|
|
178
|
-
npx @jeffreycao/copilot-api@latest auth
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
To run without GitHub Copilot, configure at least one provider first, then start the server normally:
|
|
182
|
-
|
|
183
|
-
```sh
|
|
184
|
-
npx @jeffreycao/copilot-api@latest auth login --provider dashscope
|
|
185
|
-
npx @jeffreycao/copilot-api@latest start
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
## Using with Docker
|
|
189
|
-
|
|
190
|
-
Build the image:
|
|
191
|
-
|
|
192
|
-
```sh
|
|
193
|
-
docker build -t copilot-api .
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
Run the container with a bind mount so auth data survives restarts:
|
|
197
|
-
|
|
198
|
-
```sh
|
|
199
|
-
mkdir -p ./copilot-data
|
|
200
|
-
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
This stores GitHub auth data, provider config, and other gateway state in `./copilot-data` on the host, mapped to `/root/.local/share/copilot-api` in the container.
|
|
204
|
-
|
|
205
|
-
Or pass a GitHub token directly:
|
|
206
|
-
|
|
207
|
-
```sh
|
|
208
|
-
docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## Electron Desktop App
|
|
212
|
-
|
|
213
|
-
If you prefer a GUI, this repository also includes an Electron desktop app in `desktop/`. It supports GitHub Copilot sign-in, OpenAI Codex OAuth, and API-key configuration for Kimi, DeepSeek, DashScope, OpenRouter, or a custom provider. After authorization or provider configuration, it can start and stop the local proxy with one click and shows the local endpoint, auth header, available models, usage, and logs in the app.
|
|
214
|
-
|
|
215
|
-
The settings screen also exposes `OAuth App`, `API Home`, `Enterprise URL`, verbose logging, and minimize-to-tray. Windows x64 (`.exe`), macOS Apple Silicon (`.dmg`), and Linux x64 (`.AppImage`) packages are published in GitHub Releases:
|
|
216
|
-
|
|
217
|
-
https://github.com/caozhiyuan/copilot-api/releases
|
|
218
|
-
|
|
219
|
-
On Linux, make the downloaded AppImage executable before launching it:
|
|
220
|
-
|
|
221
|
-
```sh
|
|
222
|
-
chmod +x Copilot-API-*-linux-x86_64.AppImage
|
|
223
|
-
./Copilot-API-*-linux-x86_64.AppImage
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
Download the installer for your platform, authorize or configure a provider inside the app, choose a port, start the server, then point your client at the local endpoint shown in the app. Packaged desktop builds use the bundled Electron runtime, so normal desktop usage does not require installing Node.js separately. Token usage history is enabled when that bundled runtime supports SQLite.
|
|
64
|
+
| Client | Chat Completions | Responses | Anthropic Messages | Recommended |
|
|
65
|
+
|---|:---:|:---:|:---:|---|
|
|
66
|
+
| Claude Code | — | — | ✅ Native / Adapter | Anthropic Messages |
|
|
67
|
+
| OpenCode | ✅ Native | ✅ Native / Adapter | ✅ Native / Adapter via `@ai-sdk/anthropic` | Anthropic Messages |
|
|
68
|
+
| Codex | — | ✅ Native / Adapter | — | Responses |
|
|
69
|
+
| OpenAI-compatible clients | ✅ Native | ✅ Native / Adapter | — | Chat Completions |
|
|
70
|
+
| Anthropic-compatible clients | — | — | ✅ Native / Adapter | Anthropic Messages |
|
|
227
71
|
|
|
228
|
-
|
|
72
|
+
**Providers and protocols.** Protocol support is model-specific. Chat Completions requires a native endpoint, while Responses and Messages can use supported adapters. The built-in `codex` provider uses Responses natively; third-party providers can use `anthropic`, `openai-compatible`, or `openai-responses`, with per-model overrides.
|
|
229
73
|
|
|
230
|
-
|
|
74
|
+
## Desktop App
|
|
231
75
|
|
|
232
|
-
|
|
76
|
+
Prefer a GUI? The Electron desktop app in `desktop/` covers GitHub Copilot sign-in, OpenAI Codex OAuth, and API-key configuration for Kimi, DeepSeek, DashScope, OpenRouter, or a custom provider — with one-click start/stop of the local server, and the local endpoint, auth header, available models, usage, and logs in one window.
|
|
233
77
|
|
|
234
78
|
<p align="center">
|
|
235
79
|
<img src="./docs/screenshots/desktop-dashboard.png" alt="Copilot API desktop app dashboard" width="49%" />
|
|
236
80
|
<img src="./docs/screenshots/desktop-token-usage.png" alt="Copilot API desktop app token usage view" width="49%" />
|
|
237
81
|
</p>
|
|
238
82
|
|
|
83
|
+
Windows x64 (`.exe`), macOS Apple Silicon (`.dmg`), and Linux x64 (`.AppImage`) packages are published in [GitHub Releases](https://github.com/caozhiyuan/copilot-api/releases). See [Electron Desktop App](#electron-desktop-app) for full setup and advanced configuration.
|
|
84
|
+
|
|
239
85
|
## Using with Claude Code
|
|
240
86
|
|
|
241
87
|
This AI gateway can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
|
|
@@ -440,6 +286,138 @@ When Codex uses the top-level GitHub Copilot route with `approvals_reviewer = "a
|
|
|
440
286
|
|
|
441
287
|
This mapping only applies to the top-level GitHub Copilot route. Provider-scoped routes do not use `modelMappings`, so the built-in `/codex` provider continues to handle `codex-auto-review` natively.
|
|
442
288
|
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Project Overview
|
|
292
|
+
|
|
293
|
+
A small AI gateway that can use GitHub Copilot, the built-in `codex` provider, or configured third-party providers such as DashScope. GitHub Copilot is optional: if no GitHub token is available, the server can still start in provider-only mode as long as at least one enabled provider is configured.
|
|
294
|
+
|
|
295
|
+
The gateway exposes OpenAI- and Anthropic-compatible APIs from one local endpoint, so tools like [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview), OpenCode, Codex, and OpenAI-compatible clients can share the same local server.
|
|
296
|
+
|
|
297
|
+
On the GitHub Copilot path, the gateway prefers Copilot's native Anthropic-style Messages API when available, preserving more Claude-native behavior for tool-heavy workflows.
|
|
298
|
+
|
|
299
|
+
## Important Notes
|
|
300
|
+
|
|
301
|
+
> [!IMPORTANT]
|
|
302
|
+
> **Before using, please be aware of the following:**
|
|
303
|
+
>
|
|
304
|
+
> 1. **Codex configuration:** When using with Codex, add the gateway provider to `~/.codex/config.toml`. See [Codex `config.toml` Reference](#codex-configtoml-reference).
|
|
305
|
+
>
|
|
306
|
+
> 2. **Claude Code configuration:** When using with Claude Code, please configure the model ID as `claude-opus-4-8[1m]`. Example claude `settings.json` see [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson).
|
|
307
|
+
>
|
|
308
|
+
> 3. **OpenCode configuration:** When using with OpenCode, configure `~/.config/opencode/opencode.json` with `@ai-sdk/anthropic`. See [Using with OpenCode](#using-with-opencode).
|
|
309
|
+
>
|
|
310
|
+
> 4. **Built-in `copilot`, `codex` and third-party providers:** Run `npx @jeffreycao/copilot-api@latest auth` and choose `copilot`, `codex`, `deepseek`, `custom`, or other providers.
|
|
311
|
+
>
|
|
312
|
+
> 5. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
|
|
313
|
+
|
|
314
|
+
## Prerequisites
|
|
315
|
+
|
|
316
|
+
- Bun (>= 1.2.x)
|
|
317
|
+
- Node.js if you plan to run the published CLI with `npx`
|
|
318
|
+
- GitHub account with Copilot subscription only if you want to use the GitHub Copilot provider
|
|
319
|
+
- An API key or OAuth login for at least one configured provider if you want to run without GitHub Copilot
|
|
320
|
+
|
|
321
|
+
## Installation
|
|
322
|
+
|
|
323
|
+
To install dependencies, run:
|
|
324
|
+
|
|
325
|
+
```sh
|
|
326
|
+
bun install
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## Running from Source
|
|
330
|
+
|
|
331
|
+
The project can be run from source in several ways:
|
|
332
|
+
|
|
333
|
+
### Development Mode
|
|
334
|
+
|
|
335
|
+
```sh
|
|
336
|
+
bun run dev start
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Production Mode
|
|
340
|
+
|
|
341
|
+
```sh
|
|
342
|
+
bun run start start
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
> The trailing `start` is the CLI subcommand passed to `src/main.ts`, not a typo: `bun run dev start` runs watch mode, `bun run start start` runs production.
|
|
346
|
+
|
|
347
|
+
## Using with npx
|
|
348
|
+
|
|
349
|
+
You can run the project directly using npx:
|
|
350
|
+
|
|
351
|
+
> [!IMPORTANT]
|
|
352
|
+
> Token usage storage uses Node's built-in `node:sqlite` module when running with `npx`. It is enabled on Node.js >= 22.13.0. On Node.js < 22.13.0, the CLI still starts, but token usage storage is disabled.
|
|
353
|
+
>
|
|
354
|
+
> If you want token usage storage without upgrading Node.js, run the published CLI with Bun instead: `bunx --bun @jeffreycao/copilot-api@latest start`.
|
|
355
|
+
|
|
356
|
+
```sh
|
|
357
|
+
npx @jeffreycao/copilot-api@latest start
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
With options:
|
|
361
|
+
|
|
362
|
+
```sh
|
|
363
|
+
npx @jeffreycao/copilot-api@latest start --port 8080
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
For authentication or provider configuration only:
|
|
367
|
+
|
|
368
|
+
```sh
|
|
369
|
+
npx @jeffreycao/copilot-api@latest auth
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
To run without GitHub Copilot, configure at least one provider first, then start the server normally:
|
|
373
|
+
|
|
374
|
+
```sh
|
|
375
|
+
npx @jeffreycao/copilot-api@latest auth login --provider dashscope
|
|
376
|
+
npx @jeffreycao/copilot-api@latest start
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Using with Docker
|
|
380
|
+
|
|
381
|
+
Build the image:
|
|
382
|
+
|
|
383
|
+
```sh
|
|
384
|
+
docker build -t copilot-api .
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Run the container with a bind mount so auth data survives restarts:
|
|
388
|
+
|
|
389
|
+
```sh
|
|
390
|
+
mkdir -p ./copilot-data
|
|
391
|
+
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
This stores GitHub auth data, provider config, and other gateway state in `./copilot-data` on the host, mapped to `/root/.local/share/copilot-api` in the container.
|
|
395
|
+
|
|
396
|
+
Or pass a GitHub token directly:
|
|
397
|
+
|
|
398
|
+
```sh
|
|
399
|
+
docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## Electron Desktop App
|
|
403
|
+
|
|
404
|
+
If you prefer a GUI, this repository also includes an Electron desktop app in `desktop/`. It supports GitHub Copilot sign-in, OpenAI Codex OAuth, and API-key configuration for Kimi, DeepSeek, DashScope, OpenRouter, or a custom provider. After authorization or provider configuration, it can start and stop the local proxy with one click and shows the local endpoint, auth header, available models, usage, and logs in the app.
|
|
405
|
+
|
|
406
|
+
The settings screen also exposes `OAuth App`, `API Home`, `Enterprise URL`, verbose logging, and minimize-to-tray. Windows x64 (`.exe`), macOS Apple Silicon (`.dmg`), and Linux x64 (`.AppImage`) packages are published in GitHub Releases:
|
|
407
|
+
|
|
408
|
+
https://github.com/caozhiyuan/copilot-api/releases
|
|
409
|
+
|
|
410
|
+
On Linux, make the downloaded AppImage executable before launching it:
|
|
411
|
+
|
|
412
|
+
```sh
|
|
413
|
+
chmod +x Copilot-API-*-linux-x86_64.AppImage
|
|
414
|
+
./Copilot-API-*-linux-x86_64.AppImage
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
Download the installer for your platform, authorize or configure a provider inside the app, choose a port, start the server, then point your client at the local endpoint shown in the app. Packaged desktop builds use the bundled Electron runtime, so normal desktop usage does not require installing Node.js separately. Token usage history is enabled when that bundled runtime supports SQLite.
|
|
418
|
+
|
|
419
|
+
The desktop app's Advanced Config page reads and writes the shared model mappings through `GET/POST /admin/config/model-mappings`. The same mappings apply across `POST /v1/messages`, `POST /v1/messages/count_tokens`, `POST /v1/responses`, and `POST /v1/chat/completions` instead of being split per interface. It uses `auth.adminApiKey` instead of the regular `auth.apiKeys`, and the app reads that key directly from `config.json` after the server has generated it on startup.
|
|
420
|
+
|
|
443
421
|
## GPT Tool Search
|
|
444
422
|
|
|
445
423
|
For GPT Responses models such as `gpt-5.4+`, this AI gateway can expose Responses `tool_search` through a small MCP bridge. The same bridge can be used by Claude Code and opencode, as long as the client loads MCP servers and sends Anthropic Messages traffic through this gateway.
|
|
@@ -661,7 +639,7 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
|
|
|
661
639
|
"useMessagesApi": true,
|
|
662
640
|
"useResponsesApiWebSocket": true,
|
|
663
641
|
"responsesTransport": {
|
|
664
|
-
"
|
|
642
|
+
"headersTimeoutMsV2": 300000,
|
|
665
643
|
"streamInactivityTimeoutMs": 300000,
|
|
666
644
|
"websocketOpenTimeoutMs": 30000,
|
|
667
645
|
"websocketPoolIdleTimeoutMs": 60000,
|
|
@@ -706,9 +684,9 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
|
|
|
706
684
|
- **Priority:** request `output_config.effort` > `modelReasoningEfforts[model]` > built-in default (`xhigh` for GPT-5.3+ models, otherwise `high`).
|
|
707
685
|
- **Forwarding:** the resolved value remains `output_config.effort` for the Copilot native Messages API and becomes `reasoning.effort` when translated to the Responses API.
|
|
708
686
|
- **Configuration values:** `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`.
|
|
709
|
-
- **useMessagesApi:** When `true`,
|
|
710
|
-
- **useResponsesApiWebSocket:** When `true`, Responses
|
|
711
|
-
- **responsesTransport:** Positive integer lifecycle and buffering limits for every upstream Responses transport. Invalid, zero, or negative values fall back to the defaults shown above. `
|
|
687
|
+
- **useMessagesApi:** When `true`, models that advertise Copilot's native `/v1/messages` endpoint use the Messages API. If Messages is disabled or unavailable for the selected model, the gateway uses Responses when that model advertises a Responses endpoint, then falls back to Chat Completions when supported. Set this to `false` to skip native Messages routing. Defaults to `true`.
|
|
688
|
+
- **useResponsesApiWebSocket:** When `true`, Copilot Responses requests use WebSocket for models that advertise `ws:/responses`; models that advertise only `/responses` use HTTP. Streamed Responses requests for the built-in `codex` provider use WebSocket whenever this setting is enabled, while non-streaming Codex requests always use HTTP. Set this to `false` to make Copilot use HTTP `/responses` where the selected model advertises it and to send streamed Codex Responses requests over HTTP. WebSocket failures are not retried automatically over HTTP. Defaults to `true`. If a proxy, VPN, or network blocks or destabilizes WebSocket traffic, disable this setting or switch networks.
|
|
689
|
+
- **responsesTransport:** Positive integer lifecycle and buffering limits for every upstream Responses transport. Invalid, zero, or negative values fall back to the defaults shown above. `headersTimeoutMsV2` covers connection setup through receipt of HTTP response headers; it is not a total generation deadline. `streamInactivityTimeoutMs` is reset by every HTTP body chunk or WebSocket message, allowing long generations to continue while they remain active. `websocketOpenTimeoutMs` limits the WebSocket handshake, while `websocketPoolIdleTimeoutMs` controls only completed, reusable pooled sockets. The byte and message limits bound queued WebSocket events; exceeding either limit fails that stream and invalidates its socket rather than dropping or reordering events.
|
|
712
690
|
- **useResponsesApiWebSearch:** When `true`, the server keeps Responses API tools with `type: "web_search"` and forwards them upstream. Set to `false` to strip those tools from `/responses` payloads. Defaults to `true`.
|
|
713
691
|
- **alphaSearchCodexPriority:** Defaults to `true`. Top-level alpha-search requests prefer the Codex alpha-search endpoint because it does not consume provider quota. If Codex is unavailable, or this setting is `false`, requests with a `provider/model` alias other than `codex/model` use that provider's `/v1/responses` endpoint, and requests without a provider prefix use GitHub Copilot Responses web search. The adapter recognizes every current Codex search command; unsupported `image_query` and `screenshot` operations return successful no-retry tool output.
|
|
714
692
|
- **alphaSearchModel:** Native Responses search model used when a Messages-backed Responses Lite model cannot run Responses web search directly. Defaults to `gpt-5-mini`; it may be a regular Copilot model or an `openai-responses` `provider/model` alias. Set it to an empty string to disable this redirect, in which case alpha-search requests for those models return an invalid-request error.
|
|
@@ -745,7 +723,7 @@ curl http://localhost:4141/admin/config/model-mappings \
|
|
|
745
723
|
|
|
746
724
|
## API Endpoints
|
|
747
725
|
|
|
748
|
-
The server exposes several OpenAI- and Anthropic-compatible endpoints. Requests can target GitHub Copilot, the built-in `codex` provider, or configured providers depending on the selected model and `provider/model` alias.
|
|
726
|
+
The server exposes several OpenAI- and Anthropic-compatible endpoints. Requests can target GitHub Copilot, the built-in `codex` provider, or configured providers depending on the selected model and `provider/model` alias. Every `/v1/...` endpoint below also supports a provider-scoped path in the form `/:provider/v1/...`; those variants are omitted from the tables.
|
|
749
727
|
|
|
750
728
|
### OpenAI Compatible Endpoints
|
|
751
729
|
|
|
@@ -758,33 +736,26 @@ These endpoints mimic the OpenAI API structure.
|
|
|
758
736
|
| `GET /v1/models` | `GET` | Lists Copilot models plus enabled provider models using `provider/model-id` IDs. Requests from Codex clients (`User-Agent` beginning with `codex`) are forwarded to the Codex Models upstream. |
|
|
759
737
|
| `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. |
|
|
760
738
|
|
|
761
|
-
### Codex Backend
|
|
739
|
+
### Codex Backend Endpoints
|
|
762
740
|
|
|
763
|
-
These endpoints require an active Codex login
|
|
741
|
+
These endpoints implement Codex backend APIs. Top-level image requests require an active Codex login; alpha search can use either the Codex backend or a Responses web-search adapter.
|
|
764
742
|
|
|
765
743
|
| Endpoint | Method | Description |
|
|
766
744
|
| -------------------------------------------------------------- | ------ | --------------------------------------------------------------- |
|
|
767
|
-
| `POST /
|
|
768
|
-
| `POST /
|
|
769
|
-
| `POST /
|
|
745
|
+
| `POST /v1/alpha/search` | `POST` | Routes Codex alpha-search requests to the Codex backend, or handles supported commands locally and through Responses web search. |
|
|
746
|
+
| `POST /v1/images/generations` | `POST` | Forwards a JSON image generation request to the Codex Images upstream. When the request omits `Content-Type`, the gateway defaults it to `application/json`. |
|
|
747
|
+
| `POST /v1/images/edits` | `POST` | Forwards an image edit request to the Codex Images upstream. Send this request as `multipart/form-data` and let the HTTP client generate the `boundary`; the gateway preserves the incoming content type and streams the upload body. |
|
|
770
748
|
|
|
771
|
-
For
|
|
749
|
+
For requests routed to the Codex backend, the gateway replaces client authorization and account headers with the active Codex login and preserves compatible request metadata. Responses-backed alpha search instead follows the selected Copilot or provider route.
|
|
772
750
|
|
|
773
751
|
### Anthropic Compatible Endpoints
|
|
774
752
|
|
|
775
|
-
These endpoints are designed to be compatible with the Anthropic Messages API.
|
|
753
|
+
These endpoints are designed to be compatible with the Anthropic Messages API.
|
|
776
754
|
|
|
777
755
|
| Endpoint | Method | Description |
|
|
778
756
|
| -------------------------------- | ------ | ------------------------------------------------------------ |
|
|
779
757
|
| `POST /v1/messages` | `POST` | Creates a model response for a given conversation. Supports `provider/model` aliases for configured providers, including translation through `openai-compatible` providers. |
|
|
780
758
|
| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. Supports `provider/model` aliases for configured providers. |
|
|
781
|
-
| `POST /:provider/v1/messages` | `POST` | Proxies Anthropic Messages requests to the configured Anthropic provider, translates them through an OpenAI-compatible provider, or translates them through an OpenAI Responses provider. |
|
|
782
|
-
| `GET /:provider/models`<br>`GET /:provider/v1/models` | `GET` | Proxies model listing requests to the configured provider. For `codex`, returns the built-in catalog by default; Codex clients (`User-Agent` starting with `codex`) are forwarded to the Codex Models upstream. |
|
|
783
|
-
| `POST /:provider/v1/messages/count_tokens` | `POST` | Calculates tokens locally for provider route requests. |
|
|
784
|
-
| `POST /:provider/responses`<br>`POST /:provider/v1/responses` | `POST` | Proxies OpenAI Responses requests to a configured `openai-responses` provider (including `codex`). |
|
|
785
|
-
| `POST /:provider/alpha/search`<br>`POST /:provider/v1/alpha/search` | `POST` | Proxies alpha-search requests. For `codex`, forwards to the Codex Alpha Search upstream; for other providers, forwards to `{baseUrl}/v1/alpha/search`. |
|
|
786
|
-
| `POST /:provider/images/generations`<br>`POST /:provider/v1/images/generations` | `POST` | Proxies image generation. For `codex`, uses the Codex Images upstream; for other providers, forwards to `{baseUrl}/v1/images/generations` (15-minute timeout). |
|
|
787
|
-
| `POST /:provider/images/edits`<br>`POST /:provider/v1/images/edits` | `POST` | Proxies image edits. For `codex`, uses the Codex Images upstream; for other providers, forwards multipart/streamed bodies to `{baseUrl}/v1/images/edits` (15-minute timeout). |
|
|
788
759
|
|
|
789
760
|
### Usage Monitoring Endpoints
|
|
790
761
|
|