xiaodcs-copilot-api 2.2.1-recovery.3 → 2.3.9-public.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 +267 -231
- package/README.zh-CN.md +284 -245
- package/dist/{auth-CJdxH3tJ.js → auth-BiVetBYt.js} +109 -18
- package/dist/auth-Bu4MXadr.js +2 -0
- package/dist/{config-DIbnay2m.js → config-SytZjLq8.js} +70 -14
- package/dist/{debug-BIyGtnTl.js → debug-BFadhEB4.js} +1 -1
- package/dist/main.js +3 -3
- package/dist/{models-nmZd7gqg.js → models-YMUf33c-.js} +1 -1
- package/dist/{server-CV9EwA3m.js → server-CFQmvoAJ.js} +708 -403
- package/dist/{start-CUt3ctAM.js → start-FFVCi8su.js} +8 -6
- package/dist/{token-D7IovfGe.js → token-D9svRIYW.js} +82 -15
- package/package.json +8 -5
- package/pages/index.html +167 -23
- package/dist/auth-B-TIl8we.js +0 -2
package/README.md
CHANGED
|
@@ -1,97 +1,44 @@
|
|
|
1
|
-
# Copilot API
|
|
1
|
+
# Copilot API
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
>
|
|
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>
|
|
12
|
+
|
|
13
|
+
> **XiaoDcs package channels:** `xiaodcs-copilot-api-edge` and
|
|
14
|
+
> `xiaodcs-copilot-api` are currently built from the same Edge source. Only the
|
|
15
|
+
> npm identity and executable name differ, so either package runs the same
|
|
16
|
+
> gateway code. The original MIT-licensed project is
|
|
6
17
|
> [caozhiyuan/copilot-api](https://github.com/caozhiyuan/copilot-api).
|
|
7
18
|
|
|
8
19
|
<p align="center">
|
|
9
|
-
<a href="https://www.npmjs.com/package/xiaodcs-copilot-api"><img src="https://img.shields.io/npm/v/xiaodcs-copilot-api.svg" alt="npm version"></a>
|
|
20
|
+
<a href="https://www.npmjs.com/package/xiaodcs-copilot-api-edge"><img src="https://img.shields.io/npm/v/xiaodcs-copilot-api-edge.svg" alt="npm version"></a>
|
|
21
|
+
<a href="https://www.npmjs.com/package/xiaodcs-copilot-api"><img src="https://img.shields.io/npm/v/xiaodcs-copilot-api.svg" alt="ordinary npm version"></a>
|
|
10
22
|
<a href="https://github.com/caozhiyuan/copilot-api/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
|
|
11
23
|
<a href="https://github.com/caozhiyuan/copilot-api/stargazers"><img src="https://img.shields.io/github/stars/caozhiyuan/copilot-api.svg" alt="GitHub stars"></a>
|
|
12
24
|
<a href="https://bun.sh"><img src="https://img.shields.io/badge/Bun-%3E%3D1.2.x-orange.svg" alt="Bun >= 1.2.x"></a>
|
|
13
25
|
<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>
|
|
14
26
|
</p>
|
|
15
27
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- [Copilot API Proxy](#copilot-api-proxy)
|
|
21
|
-
- [Table of Contents](#table-of-contents)
|
|
22
|
-
- [Important Notes](#important-notes)
|
|
23
|
-
- [Project Overview](#project-overview)
|
|
24
|
-
- [Quick Start](#quick-start)
|
|
25
|
-
- [Features](#features)
|
|
26
|
-
- [Prerequisites](#prerequisites)
|
|
27
|
-
- [Installation](#installation)
|
|
28
|
-
- [Running from Source](#running-from-source)
|
|
29
|
-
- [Development Mode](#development-mode)
|
|
30
|
-
- [Production Mode](#production-mode)
|
|
31
|
-
- [Using with npx](#using-with-npx)
|
|
32
|
-
- [Using with Docker](#using-with-docker)
|
|
33
|
-
- [Electron Desktop App](#electron-desktop-app)
|
|
34
|
-
- [Desktop App Screenshots](#desktop-app-screenshots)
|
|
35
|
-
- [Using with Claude Code](#using-with-claude-code)
|
|
36
|
-
- [Interactive Setup with `--claude-code` flag](#interactive-setup-with---claude-code-flag)
|
|
37
|
-
- [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson)
|
|
38
|
-
- [Using with OpenCode](#using-with-opencode)
|
|
39
|
-
- [Minimal setup](#minimal-setup)
|
|
40
|
-
- [Using with Codex](#using-with-codex)
|
|
41
|
-
- [Codex `config.toml` Reference](#codex-configtoml-reference)
|
|
42
|
-
- [GPT Tool Search](#gpt-tool-search)
|
|
43
|
-
- [Plugin Integrations](#plugin-integrations)
|
|
44
|
-
- [Claude Code plugin integration (marketplace-based)](#claude-code-plugin-integration-marketplace-based)
|
|
45
|
-
- [Opencode plugin](#opencode-plugin)
|
|
46
|
-
- [Using the Usage Viewer](#using-the-usage-viewer)
|
|
47
|
-
- [Usage Viewer Screenshot](#usage-viewer-screenshot)
|
|
48
|
-
- [Command Structure](#command-structure)
|
|
49
|
-
- [Command Line Options](#command-line-options)
|
|
50
|
-
- [Global Options](#global-options)
|
|
51
|
-
- [Start Command Options](#start-command-options)
|
|
52
|
-
- [Auth Command Options](#auth-command-options)
|
|
53
|
-
- [Debug Command Options](#debug-command-options)
|
|
54
|
-
- [Configuration (config.json)](#configuration-configjson)
|
|
55
|
-
- [API Authentication](#api-authentication)
|
|
56
|
-
- [API Endpoints](#api-endpoints)
|
|
57
|
-
- [OpenAI Compatible Endpoints](#openai-compatible-endpoints)
|
|
58
|
-
- [Codex Backend Proxy Endpoints](#codex-backend-proxy-endpoints)
|
|
59
|
-
- [Anthropic Compatible Endpoints](#anthropic-compatible-endpoints)
|
|
60
|
-
- [Usage Monitoring Endpoints](#usage-monitoring-endpoints)
|
|
61
|
-
- [Admin / Configuration Endpoints](#admin--configuration-endpoints)
|
|
62
|
-
- [Example Usage](#example-usage)
|
|
63
|
-
- [Usage Tips](#usage-tips)
|
|
64
|
-
- [CLAUDE.md or AGENTS.md Recommended Content](#claudemd-or-agentsmd-recommended-content)
|
|
65
|
-
|
|
66
|
-
## Important Notes
|
|
67
|
-
|
|
68
|
-
> [!IMPORTANT]
|
|
69
|
-
> **Before using, please be aware of the following:**
|
|
70
|
-
>
|
|
71
|
-
> 1. **Codex configuration:** When using with Codex, add the gateway provider to `~/.codex/config.toml`. See [Codex `config.toml` Reference](#codex-configtoml-reference).
|
|
72
|
-
>
|
|
73
|
-
> 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).
|
|
74
|
-
>
|
|
75
|
-
> 3. **OpenCode configuration:** When using with OpenCode, configure `~/.config/opencode/opencode.json` with `@ai-sdk/anthropic`. See [Using with OpenCode](#using-with-opencode).
|
|
76
|
-
>
|
|
77
|
-
> 4. **Built-in `copilot`, `codex` and third-party providers:** Run `npx xiaodcs-copilot-api@latest auth` and choose `copilot`, `codex`, `deepseek`, `custom`, or other providers.
|
|
78
|
-
>
|
|
79
|
-
> 5. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## Project Overview
|
|
84
|
-
|
|
85
|
-
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.
|
|
86
|
-
|
|
87
|
-
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.
|
|
88
|
-
|
|
89
|
-
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.
|
|
28
|
+
<p align="center">
|
|
29
|
+
English | <a href="./README.zh-CN.md">简体中文</a>
|
|
30
|
+
</p>
|
|
90
31
|
|
|
91
32
|
## Quick Start
|
|
92
33
|
|
|
93
34
|
The fastest way to get a working gateway:
|
|
94
35
|
|
|
36
|
+
```sh
|
|
37
|
+
npx xiaodcs-copilot-api-edge@latest start
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The ordinary package name is an equivalent compatibility channel:
|
|
41
|
+
|
|
95
42
|
```sh
|
|
96
43
|
npx xiaodcs-copilot-api@latest start
|
|
97
44
|
```
|
|
@@ -99,7 +46,7 @@ npx xiaodcs-copilot-api@latest start
|
|
|
99
46
|
The server listens on `http://localhost:4141` by default. Optionally authenticate with GitHub Copilot or configure a third-party provider first:
|
|
100
47
|
|
|
101
48
|
```sh
|
|
102
|
-
npx xiaodcs-copilot-api@latest auth login
|
|
49
|
+
npx xiaodcs-copilot-api-edge@latest auth login
|
|
103
50
|
```
|
|
104
51
|
|
|
105
52
|
Verify the gateway is up:
|
|
@@ -113,134 +60,41 @@ curl http://localhost:4141/v1/models
|
|
|
113
60
|
|
|
114
61
|
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).
|
|
115
62
|
|
|
116
|
-
##
|
|
117
|
-
|
|
118
|
-
- **OpenAI and Anthropic compatibility**: Serve `/v1/responses`, `/v1/chat/completions`, `/v1/models`, `/v1/embeddings`, and `/v1/messages` from one local gateway.
|
|
119
|
-
- **Copilot is optional**: Use GitHub Copilot when credentials are present, or run the server with only configured providers.
|
|
120
|
-
- **One gateway for Copilot, `codex`, and external providers**: Route GitHub Copilot, the built-in `codex` provider, and configured third-party providers behind the same endpoint.
|
|
121
|
-
- **Standalone third-party providers**: Configure providers such as DashScope, DeepSeek, OpenRouter, or a custom provider and start the gateway without a GitHub Copilot login.
|
|
122
|
-
- **OpenAI-compatible providers on chat and Messages APIs**: `openai-compatible` providers can serve top-level `/v1/chat/completions` through `model: "provider/model"` and Anthropic-style `/v1/messages` through request/response translation.
|
|
123
|
-
- **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.
|
|
124
|
-
- **Claude Code and OpenCode integration**: Works with Claude Code and OpenCode, including direct Anthropic-compatible usage through `@ai-sdk/anthropic`.
|
|
125
|
-
- **Flexible auth and deployment options**: Supports interactive login or direct tokens, individual/business/enterprise plans, GitHub Enterprise, opencode OAuth, and custom data directories.
|
|
126
|
-
- **Multi-provider routing**: Expose provider-specific `/:provider/...` routes or use `model: "provider/model"` on the top-level API.
|
|
63
|
+
## Highlights
|
|
127
64
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
- An API key or OAuth login for at least one configured provider if you want to run without GitHub Copilot
|
|
134
|
-
|
|
135
|
-
## Installation
|
|
136
|
-
|
|
137
|
-
To install dependencies, run:
|
|
138
|
-
|
|
139
|
-
```sh
|
|
140
|
-
bun install
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Running from Source
|
|
144
|
-
|
|
145
|
-
The project can be run from source in several ways:
|
|
65
|
+
- **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.
|
|
66
|
+
- **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.
|
|
67
|
+
- **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.
|
|
68
|
+
- **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.
|
|
69
|
+
- **Desktop App**: Electron GUI with GitHub Copilot sign-in, Codex OAuth, provider configuration, token usage, logs, and one-click start/stop.
|
|
146
70
|
|
|
147
|
-
|
|
71
|
+
## Compatibility
|
|
148
72
|
|
|
149
|
-
|
|
150
|
-
bun run dev start
|
|
151
|
-
```
|
|
73
|
+
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.
|
|
152
74
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
```sh
|
|
156
|
-
bun run start start
|
|
157
|
-
```
|
|
75
|
+
**Client / Protocol Matrix**
|
|
158
76
|
|
|
159
|
-
|
|
77
|
+
| Client | Chat Completions | Responses | Anthropic Messages | Recommended |
|
|
78
|
+
|---|:---:|:---:|:---:|---|
|
|
79
|
+
| Claude Code | — | — | ✅ Native / Adapter | Anthropic Messages |
|
|
80
|
+
| OpenCode | ✅ Native | ✅ Native / Adapter | ✅ Native / Adapter via `@ai-sdk/anthropic` | Anthropic Messages |
|
|
81
|
+
| Codex | — | ✅ Native / Adapter | — | Responses |
|
|
82
|
+
| OpenAI-compatible clients | ✅ Native | ✅ Native / Adapter | — | Chat Completions |
|
|
83
|
+
| Anthropic-compatible clients | — | — | ✅ Native / Adapter | Anthropic Messages |
|
|
160
84
|
|
|
161
|
-
|
|
85
|
+
**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.
|
|
162
86
|
|
|
163
|
-
|
|
87
|
+
## Desktop App
|
|
164
88
|
|
|
165
|
-
|
|
166
|
-
> 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.
|
|
167
|
-
>
|
|
168
|
-
> If you want token usage storage without upgrading Node.js, run the published CLI with Bun instead: `bunx --bun xiaodcs-copilot-api@latest start`.
|
|
169
|
-
|
|
170
|
-
```sh
|
|
171
|
-
npx xiaodcs-copilot-api@latest start
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
With options:
|
|
175
|
-
|
|
176
|
-
```sh
|
|
177
|
-
npx xiaodcs-copilot-api@latest start --port 8080
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
For authentication or provider configuration only:
|
|
181
|
-
|
|
182
|
-
```sh
|
|
183
|
-
npx xiaodcs-copilot-api@latest auth
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
To run without GitHub Copilot, configure at least one provider first, then start the server normally:
|
|
187
|
-
|
|
188
|
-
```sh
|
|
189
|
-
npx xiaodcs-copilot-api@latest auth login --provider dashscope
|
|
190
|
-
npx xiaodcs-copilot-api@latest start
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Using with Docker
|
|
194
|
-
|
|
195
|
-
Build the image:
|
|
196
|
-
|
|
197
|
-
```sh
|
|
198
|
-
docker build -t copilot-api .
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
Run the container with a bind mount so auth data survives restarts:
|
|
202
|
-
|
|
203
|
-
```sh
|
|
204
|
-
mkdir -p ./copilot-data
|
|
205
|
-
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
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.
|
|
209
|
-
|
|
210
|
-
Or pass a GitHub token directly:
|
|
211
|
-
|
|
212
|
-
```sh
|
|
213
|
-
docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## Electron Desktop App
|
|
217
|
-
|
|
218
|
-
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.
|
|
219
|
-
|
|
220
|
-
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:
|
|
221
|
-
|
|
222
|
-
https://github.com/caozhiyuan/copilot-api/releases
|
|
223
|
-
|
|
224
|
-
On Linux, make the downloaded AppImage executable before launching it:
|
|
225
|
-
|
|
226
|
-
```sh
|
|
227
|
-
chmod +x Copilot-API-*-linux-x86_64.AppImage
|
|
228
|
-
./Copilot-API-*-linux-x86_64.AppImage
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
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.
|
|
232
|
-
|
|
233
|
-
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.
|
|
234
|
-
|
|
235
|
-
### Desktop App Screenshots
|
|
236
|
-
|
|
237
|
-
Main dashboard, token usage breakdown in the bundled Electron app:
|
|
89
|
+
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.
|
|
238
90
|
|
|
239
91
|
<p align="center">
|
|
240
92
|
<img src="./docs/screenshots/desktop-dashboard.png" alt="Copilot API desktop app dashboard" width="49%" />
|
|
241
93
|
<img src="./docs/screenshots/desktop-token-usage.png" alt="Copilot API desktop app token usage view" width="49%" />
|
|
242
94
|
</p>
|
|
243
95
|
|
|
96
|
+
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.
|
|
97
|
+
|
|
244
98
|
## Using with Claude Code
|
|
245
99
|
|
|
246
100
|
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.
|
|
@@ -252,7 +106,7 @@ There are two ways to configure Claude Code to use this AI gateway:
|
|
|
252
106
|
To get started, run the `start` command with the `--claude-code` flag:
|
|
253
107
|
|
|
254
108
|
```sh
|
|
255
|
-
npx xiaodcs-copilot-api@latest start --claude-code
|
|
109
|
+
npx xiaodcs-copilot-api-edge@latest start --claude-code
|
|
256
110
|
```
|
|
257
111
|
|
|
258
112
|
You will no longer be prompted to pick models manually. The gateway automatically detects the latest available model for each Claude Code size tier — opus maps to the newest Opus model, sonnet to the newest Sonnet model, and haiku to the newest Haiku model — and generates a command that sets `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL` accordingly. Any tier without a matching model available is omitted. The command is copied to your clipboard and sets the environment variables needed for Claude Code to use the gateway.
|
|
@@ -321,8 +175,8 @@ OpenCode already has a direct GitHub Copilot provider. Use this section when you
|
|
|
321
175
|
Start the AI gateway with the OpenCode OAuth app:
|
|
322
176
|
|
|
323
177
|
```sh
|
|
324
|
-
npx xiaodcs-copilot-api@latest auth --oauth-app=opencode
|
|
325
|
-
npx xiaodcs-copilot-api@latest start
|
|
178
|
+
npx xiaodcs-copilot-api-edge@latest auth --oauth-app=opencode
|
|
179
|
+
npx xiaodcs-copilot-api-edge@latest start
|
|
326
180
|
```
|
|
327
181
|
|
|
328
182
|
Then point OpenCode at the gateway with `@ai-sdk/anthropic`.
|
|
@@ -404,6 +258,7 @@ base_url = "http://localhost:4141"
|
|
|
404
258
|
env_key = "GITHUB_COPILOT_API_KEY"
|
|
405
259
|
requires_openai_auth = true
|
|
406
260
|
supports_websockets = false
|
|
261
|
+
supports_standalone_web_search = true
|
|
407
262
|
wire_api = "responses"
|
|
408
263
|
request_max_retries = 3
|
|
409
264
|
stream_max_retries = 3
|
|
@@ -413,6 +268,7 @@ stream_idle_timeout_ms = 300000
|
|
|
413
268
|
remote_compaction_v2 = true
|
|
414
269
|
# optional: set false only when the model does not support tool_search
|
|
415
270
|
apps = false
|
|
271
|
+
standalone_web_search = true
|
|
416
272
|
|
|
417
273
|
[analytics]
|
|
418
274
|
enabled = false
|
|
@@ -422,8 +278,62 @@ enabled = false
|
|
|
422
278
|
> `name` must be set to `"OpenAI"`.
|
|
423
279
|
>
|
|
424
280
|
> For third-party models that do not support `tool_search`, we recommend disabling features.apps. Otherwise, each prompt may consume an additional 20,000 or more tokens.
|
|
281
|
+
>
|
|
282
|
+
> `supports_standalone_web_search` and `[features] standalone_web_search` must both be enabled to expose the standalone `web.run` search tool.
|
|
283
|
+
|
|
284
|
+
When Copilot exposes both a base Responses model and an exact `-fast` sibling
|
|
285
|
+
(for example, `gpt-5.6-sol` and `gpt-5.6-sol-fast`), the gateway presents them
|
|
286
|
+
to Codex as one model with a native **Fast** service tier. Selecting Fast makes
|
|
287
|
+
Codex send `service_tier: "priority"`; the gateway routes that request to the
|
|
288
|
+
paired Fast model and removes the unsupported field before forwarding it to
|
|
289
|
+
GitHub Copilot. The raw `/v1/models` endpoint continues to list both model IDs.
|
|
290
|
+
To make Fast the default for new Codex turns, add this top-level setting:
|
|
291
|
+
|
|
292
|
+
```toml
|
|
293
|
+
service_tier = "fast"
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### If Codex Is Not Signed In to a GPT Account
|
|
297
|
+
|
|
298
|
+
```toml
|
|
299
|
+
[model_providers.copilot_api]
|
|
300
|
+
name = "OpenAI"
|
|
301
|
+
base_url = "http://localhost:4141"
|
|
302
|
+
requires_openai_auth = false
|
|
303
|
+
supports_websockets = false
|
|
304
|
+
supports_standalone_web_search = true
|
|
305
|
+
wire_api = "responses"
|
|
306
|
+
request_max_retries = 3
|
|
307
|
+
stream_max_retries = 3
|
|
308
|
+
stream_idle_timeout_ms = 300000
|
|
309
|
+
|
|
310
|
+
[features]
|
|
311
|
+
standalone_web_search = true
|
|
312
|
+
|
|
313
|
+
[model_providers.copilot_api.auth]
|
|
314
|
+
command = "powershell.exe"
|
|
315
|
+
args = [
|
|
316
|
+
"-NoProfile",
|
|
317
|
+
"-NonInteractive",
|
|
318
|
+
"-Command",
|
|
319
|
+
"[Console]::Out.Write($env:GITHUB_COPILOT_API_KEY)"
|
|
320
|
+
]
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
macOS, replace the `auth` block with:
|
|
425
324
|
|
|
426
|
-
|
|
325
|
+
```toml
|
|
326
|
+
[model_providers.copilot_api.auth]
|
|
327
|
+
command = "/bin/zsh"
|
|
328
|
+
args = [
|
|
329
|
+
"-c",
|
|
330
|
+
"printf '%s' \"$GITHUB_COPILOT_API_KEY\""
|
|
331
|
+
]
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Without this configuration, Codex cannot fetch `/v1/models` while not signed in to a GPT account, so custom models are unavailable in the model picker.
|
|
335
|
+
|
|
336
|
+
When a Codex client (`User-Agent` starts with `codex`) requests the top-level `GET /v1/models`, the gateway merges native Codex models with models available through the Messages adapter. The latter advertise `use_responses_lite: true`, except DeepSeek models, which use `use_responses_lite: false` and `tool_mode: null`. For other models, `/v1/responses` uses **Responses → Messages** for Anthropic providers, while OpenAI-compatible providers and Chat-only Copilot models reuse the existing Messages route for **Responses → Messages → Chat Completions**, then translate streaming or JSON results back to Responses.
|
|
427
337
|
|
|
428
338
|
The merged catalog is what Codex shows in its model picker, including the models exposed by your configured providers:
|
|
429
339
|
|
|
@@ -445,6 +355,138 @@ When Codex uses the top-level GitHub Copilot route with `approvals_reviewer = "a
|
|
|
445
355
|
|
|
446
356
|
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.
|
|
447
357
|
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## Project Overview
|
|
361
|
+
|
|
362
|
+
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.
|
|
363
|
+
|
|
364
|
+
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.
|
|
365
|
+
|
|
366
|
+
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.
|
|
367
|
+
|
|
368
|
+
## Important Notes
|
|
369
|
+
|
|
370
|
+
> [!IMPORTANT]
|
|
371
|
+
> **Before using, please be aware of the following:**
|
|
372
|
+
>
|
|
373
|
+
> 1. **Codex configuration:** When using with Codex, add the gateway provider to `~/.codex/config.toml`. See [Codex `config.toml` Reference](#codex-configtoml-reference).
|
|
374
|
+
>
|
|
375
|
+
> 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).
|
|
376
|
+
>
|
|
377
|
+
> 3. **OpenCode configuration:** When using with OpenCode, configure `~/.config/opencode/opencode.json` with `@ai-sdk/anthropic`. See [Using with OpenCode](#using-with-opencode).
|
|
378
|
+
>
|
|
379
|
+
> 4. **Built-in `copilot`, `codex` and third-party providers:** Run `npx xiaodcs-copilot-api-edge@latest auth` and choose `copilot`, `codex`, `deepseek`, `custom`, or other providers.
|
|
380
|
+
>
|
|
381
|
+
> 5. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
|
|
382
|
+
|
|
383
|
+
## Prerequisites
|
|
384
|
+
|
|
385
|
+
- Bun (>= 1.2.x)
|
|
386
|
+
- Node.js if you plan to run the published CLI with `npx`
|
|
387
|
+
- GitHub account with Copilot subscription only if you want to use the GitHub Copilot provider
|
|
388
|
+
- An API key or OAuth login for at least one configured provider if you want to run without GitHub Copilot
|
|
389
|
+
|
|
390
|
+
## Installation
|
|
391
|
+
|
|
392
|
+
To install dependencies, run:
|
|
393
|
+
|
|
394
|
+
```sh
|
|
395
|
+
bun install
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Running from Source
|
|
399
|
+
|
|
400
|
+
The project can be run from source in several ways:
|
|
401
|
+
|
|
402
|
+
### Development Mode
|
|
403
|
+
|
|
404
|
+
```sh
|
|
405
|
+
bun run dev start
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### Production Mode
|
|
409
|
+
|
|
410
|
+
```sh
|
|
411
|
+
bun run start start
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
> 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.
|
|
415
|
+
|
|
416
|
+
## Using with npx
|
|
417
|
+
|
|
418
|
+
You can run the project directly using npx:
|
|
419
|
+
|
|
420
|
+
> [!IMPORTANT]
|
|
421
|
+
> 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.
|
|
422
|
+
>
|
|
423
|
+
> If you want token usage storage without upgrading Node.js, run the published CLI with Bun instead: `bunx --bun xiaodcs-copilot-api-edge@latest start`.
|
|
424
|
+
|
|
425
|
+
```sh
|
|
426
|
+
npx xiaodcs-copilot-api-edge@latest start
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
With options:
|
|
430
|
+
|
|
431
|
+
```sh
|
|
432
|
+
npx xiaodcs-copilot-api-edge@latest start --port 8080
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
For authentication or provider configuration only:
|
|
436
|
+
|
|
437
|
+
```sh
|
|
438
|
+
npx xiaodcs-copilot-api-edge@latest auth
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
To run without GitHub Copilot, configure at least one provider first, then start the server normally:
|
|
442
|
+
|
|
443
|
+
```sh
|
|
444
|
+
npx xiaodcs-copilot-api-edge@latest auth login --provider dashscope
|
|
445
|
+
npx xiaodcs-copilot-api-edge@latest start
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## Using with Docker
|
|
449
|
+
|
|
450
|
+
Build the image:
|
|
451
|
+
|
|
452
|
+
```sh
|
|
453
|
+
docker build -t copilot-api .
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Run the container with a bind mount so auth data survives restarts:
|
|
457
|
+
|
|
458
|
+
```sh
|
|
459
|
+
mkdir -p ./copilot-data
|
|
460
|
+
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
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.
|
|
464
|
+
|
|
465
|
+
Or pass a GitHub token directly:
|
|
466
|
+
|
|
467
|
+
```sh
|
|
468
|
+
docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## Electron Desktop App
|
|
472
|
+
|
|
473
|
+
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.
|
|
474
|
+
|
|
475
|
+
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:
|
|
476
|
+
|
|
477
|
+
https://github.com/caozhiyuan/copilot-api/releases
|
|
478
|
+
|
|
479
|
+
On Linux, make the downloaded AppImage executable before launching it:
|
|
480
|
+
|
|
481
|
+
```sh
|
|
482
|
+
chmod +x Copilot-API-*-linux-x86_64.AppImage
|
|
483
|
+
./Copilot-API-*-linux-x86_64.AppImage
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
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.
|
|
487
|
+
|
|
488
|
+
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.
|
|
489
|
+
|
|
448
490
|
## GPT Tool Search
|
|
449
491
|
|
|
450
492
|
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.
|
|
@@ -461,7 +503,7 @@ Add the tool search bridge to the MCP config used by Claude Code:
|
|
|
461
503
|
"tool_search": {
|
|
462
504
|
"type": "stdio",
|
|
463
505
|
"command": "npx",
|
|
464
|
-
"args": ["-y", "xiaodcs-copilot-api@latest", "mcp"]
|
|
506
|
+
"args": ["-y", "xiaodcs-copilot-api-edge@latest", "mcp"]
|
|
465
507
|
}
|
|
466
508
|
}
|
|
467
509
|
}
|
|
@@ -474,7 +516,7 @@ Add the tool search bridge to the MCP config used by opencode:
|
|
|
474
516
|
"mcp": {
|
|
475
517
|
"tool_search": {
|
|
476
518
|
"type": "local",
|
|
477
|
-
"command": ["npx", "-y", "xiaodcs-copilot-api@latest", "mcp"]
|
|
519
|
+
"command": ["npx", "-y", "xiaodcs-copilot-api-edge@latest", "mcp"]
|
|
478
520
|
}
|
|
479
521
|
}
|
|
480
522
|
}
|
|
@@ -554,7 +596,7 @@ After starting the server, a URL to the Copilot Usage Dashboard will be displaye
|
|
|
554
596
|
|
|
555
597
|
1. Start the server. For example, using npx:
|
|
556
598
|
```sh
|
|
557
|
-
npx xiaodcs-copilot-api@latest start
|
|
599
|
+
npx xiaodcs-copilot-api-edge@latest start
|
|
558
600
|
```
|
|
559
601
|
2. The server will output a URL to the usage viewer. Copy and paste this URL into your browser. It will look something like this:
|
|
560
602
|
`http://localhost:4141/usage-viewer?endpoint=http://localhost:4141/usage`
|
|
@@ -565,7 +607,7 @@ The dashboard provides a user-friendly interface to view your Copilot usage data
|
|
|
565
607
|
> Token usage history requires Bun or Node.js >= 22.13.0. On Node.js < 22.13.0, the server runs normally but token usage storage is disabled.
|
|
566
608
|
|
|
567
609
|
- **API Endpoint URL**: The dashboard is pre-configured to fetch data from your local server endpoint via a URL query parameter. You can manually switch this to any other compatible API endpoint.
|
|
568
|
-
- **
|
|
610
|
+
- **API Key Authentication**: If API Key authentication is enabled, enter a raw API key (sent as the `x-api-key` header) or `Authorization: Bearer <key>`. Credentials are remembered in the browser's local storage per endpoint origin, and switching to a different endpoint origin does not automatically send the previous credential.
|
|
569
611
|
- **Period Selector**: Choose from Day, Week, or Month time ranges. The URL query parameter updates automatically when you switch, making it easy to bookmark and share.
|
|
570
612
|
- **Fetch Data**: Click the "Refresh" button to load or refresh the usage data. The dashboard also fetches data automatically on page load.
|
|
571
613
|
- **Copilot Quotas**: View quota usage for services such as Chat and Completions via progress bars. Hover over a card to see used/remaining details.
|
|
@@ -626,10 +668,12 @@ The following command line options are available for the `start` command:
|
|
|
626
668
|
|
|
627
669
|
Use `copilot-api auth login --provider copilot` only when you want to enable the GitHub Copilot provider. Copilot is not required for `codex` or third-party provider-only usage.
|
|
628
670
|
|
|
629
|
-
Use `copilot-api auth login --provider deepseek`, `--provider dashscope`, `--provider openrouter`, `--provider opencode-go`, or `--provider kimi` to add or update those common third-party providers from the CLI. DeepSeek prompts for masked `apiKey`, provider `type` (default `anthropic`), and `baseUrl` defaulting to `https://api.deepseek.com/anthropic`. DashScope prompts for masked `apiKey`, provider `type` (default `openai-compatible`), and prefilled `baseUrl`. OpenRouter prompts for masked `apiKey` and prefilled `baseUrl` only, and writes `type: "anthropic"`. OpenCode Go prompts for masked `apiKey` and prefilled `baseUrl` only, and writes `type: "openai-compatible"` (baseUrl `https://opencode.ai/zen/go`). Kimi prompts for masked `apiKey
|
|
671
|
+
Use `copilot-api auth login --provider deepseek`, `--provider dashscope`, `--provider openrouter`, `--provider opencode-go`, or `--provider kimi` to add or update those common third-party providers from the CLI. DeepSeek prompts for masked `apiKey`, provider `type` (default `anthropic`), and `baseUrl` defaulting to `https://api.deepseek.com/anthropic`. DashScope prompts for masked `apiKey`, provider `type` (default `openai-compatible`), and prefilled `baseUrl`. OpenRouter prompts for masked `apiKey` and prefilled `baseUrl` only, and writes `type: "anthropic"`. OpenCode Go prompts for masked `apiKey` and prefilled `baseUrl` only, and writes `type: "openai-compatible"` (baseUrl `https://opencode.ai/zen/go`). Kimi prompts for masked `apiKey`, provider `type` (default `openai-compatible`), and `baseUrl` defaulting to `https://api.kimi.com/coding` (the same base URL serves both the Anthropic and OpenAI-compatible endpoints). OpenCode Go additionally routes built-in `qwen*` and `minimax*` models through Anthropic Messages and `gpt*`/`grok*`/`muse-spark*` models through OpenAI Responses; other models keep the OpenAI-compatible default. After a provider is configured and enabled, `copilot-api start` can run without any GitHub token.
|
|
630
672
|
|
|
631
673
|
Use `copilot-api auth login --provider custom` to add or update another third-party provider from the CLI. The command prompts for the provider name, supported type (`anthropic`, `openai-compatible`, or `openai-responses`), `baseUrl`, masked `apiKey`, and `authType`; `authType` may be left as the type default or set to `x-api-key` / `authorization`.
|
|
632
674
|
|
|
675
|
+
Gateway API keys live under `auth.apiKeys` in `config.json`. Manage them with `copilot-api auth keys` (one operation per invocation): add a key with `--add <key>`, remove one with `--remove <key>`, list all with `--list`, or clear them all with `--clear`. Clients authenticate with any configured key via `x-api-key` or `Authorization: Bearer`. When no keys are configured, `copilot-api start` starts with authentication bypassed and prints a startup info message.
|
|
676
|
+
|
|
633
677
|
### Debug Command Options
|
|
634
678
|
|
|
635
679
|
| Option | Description | Default | Alias |
|
|
@@ -684,7 +728,7 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
|
|
|
684
728
|
- **auth.adminApiKey:** Single admin key used only for `/admin/*` routes. If missing, the server generates a random key at startup and writes it back to `config.json`. Requests use the same `x-api-key` or `Authorization: Bearer` headers, but regular `auth.apiKeys` never grant access to `/admin/*`.
|
|
685
729
|
- **modelMappings:** Exact `sourceModel -> targetModel` rewrites shared by top-level `POST /v1/messages`, `POST /v1/messages/count_tokens`, `POST /v1/responses`, and `POST /v1/chat/completions` requests. Omit it or leave it as `{}` to disable rewrites. Both the source and target must be non-empty strings. Targets can be regular model IDs or `provider/model` aliases such as `dashscope/qwen3.6-plus`, and the rewrite happens before provider alias parsing. These mappings are not split per interface. The admin endpoints `GET/POST /admin/config/model-mappings` read and update only this field.
|
|
686
730
|
- **extraPrompts:** Map of `model -> prompt` appended to the first system prompt when translating Anthropic-style requests to Responses API. Use this to inject guardrails or guidance per model. Missing default entries are auto-added without overwriting your custom prompts. For GPT-5.3+ models (e.g. `gpt-5.3-codex`, `gpt-5.4`, `gpt-5.5`), a built-in commentary prompt is used as fallback when not explicitly configured. The built-in prompts enable phase-aware commentary, which lets the model emit a short user-facing progress update before tools or deeper reasoning.
|
|
687
|
-
- **providers:** Global upstream provider map. Each provider key (for example `dashscope`) becomes a route prefix (`/dashscope/v1/messages`). Supports `type: "anthropic"`, `type: "openai-compatible"`, and `type: "openai-responses"`. Top-level clients can also use `model: "dashscope/model-id"` with `/v1/messages`, `/v1/messages/count_tokens`, `/v1/responses`, and `/v1/chat/completions`; the gateway strips the `dashscope/` prefix before forwarding upstream. The `/v1/responses` route for `anthropic` and `openai-compatible` providers uses the Responses Lite → Messages adapter; `openai-compatible` providers then reuse the Messages → Chat translation. Codex clients (`User-Agent` starting with `codex`) also use the adapter for non-`gpt-*` models on `openai-responses` providers. `GET /v1/models` aggregates enabled provider models with `provider/model-id` IDs, while the top-level Codex-UA catalog also merges these adaptable models as `use_responses_lite` entries. Use `GET /dashscope/v1/models` for a single provider's raw model list.
|
|
731
|
+
- **providers:** Global upstream provider map. Each provider key (for example `dashscope`) becomes a route prefix (`/dashscope/v1/messages`). Supports `type: "anthropic"`, `type: "openai-compatible"`, and `type: "openai-responses"`. Top-level clients can also use `model: "dashscope/model-id"` with `/v1/messages`, `/v1/messages/count_tokens`, `/v1/responses`, and `/v1/chat/completions`; the gateway strips the `dashscope/` prefix before forwarding upstream. The `/v1/responses` route for `anthropic` and `openai-compatible` providers uses the Responses Lite → Messages adapter; `openai-compatible` providers then reuse the Messages → Chat translation. Codex clients (`User-Agent` starting with `codex`) also use the adapter for non-`gpt-*` models on `openai-responses` providers. `GET /v1/models` aggregates enabled provider models with `provider/model-id` IDs, while the top-level Codex-UA catalog also merges these adaptable models as `use_responses_lite` entries (except DeepSeek models, which use `use_responses_lite: false` and `tool_mode: null`). Use `GET /dashscope/v1/models` for a single provider's raw model list.
|
|
688
732
|
- `enabled` defaults to `true` if omitted.
|
|
689
733
|
- `baseUrl` should be provider API base URL without the final endpoint. For Anthropic providers, omit `/v1/messages`; for OpenAI-compatible providers, omit `/v1/chat/completions`; for OpenAI Responses providers, omit `/v1/responses`.
|
|
690
734
|
- `apiKey` is used as the upstream credential value and is required for regular providers.
|
|
@@ -698,7 +742,7 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
|
|
|
698
742
|
- `pricing` (optional): Per-model token prices, in the provider `pricingCurrency`, per 1M tokens. Supported fields are `input`, `output`, `cachedInput` (implicit cache read), `explicitCachedInput` (explicit cache read), and `cacheCreationInput`. Use `tiers` with `maxInputTokens` for input-size tiered pricing.
|
|
699
743
|
- `contextCache` (optional): Defaults to `true` for providers whose name is `dashscope` or whose `baseUrl` contains `aliyuncs.com`; defaults to `false` for other OpenAI-compatible providers. This enables Alibaba Cloud Model Studio/DashScope explicit context cache by injecting `cache_control: { "type": "ephemeral" }` on up to 4 content blocks using the Context Cache format. The cache breakpoint strategy matches opencode's main provider flow: the first 2 system messages plus the last 2 non-system messages. Marked string content is converted to text content part arrays for `system` / `user` / `assistant` / `tool` messages; existing array content is marked on the last part. Set this to `false` when the model already supports implicit caching, or when the upstream does not accept this explicit-cache extension field. Set this to `true` for non-DashScope providers that support the same explicit-cache extension. Applied on both `/v1/messages` and `/v1/chat/completions` routes.
|
|
700
744
|
- `supportPdf` (optional): Controls whether the model supports PDF/document content. Defaults to `false`; unsupported PDFs are converted to a text notice. Set it to `true` to send PDF/document blocks as OpenAI Chat Completions file parts.
|
|
701
|
-
- `toolContentSupportType` (optional): Tool result content capabilities for that model, as an array of `array`, `image`, and `pdf`. Provider routes default to string-only tool content when omitted. If `supportPdf` is `true` but this list does not include `pdf`, file parts in tool results are moved to user role messages.
|
|
745
|
+
- `toolContentSupportType` (optional): Tool result content capabilities for that model, as an array of `array`, `image`, and `pdf`. Provider routes default to string-only tool content when omitted. If `supportPdf` is `true` but this list does not include `pdf`, file parts in tool results are moved to user role messages. The Copilot main flow uses the same string-only default, because some Copilot models do not support array or image tool content either.
|
|
702
746
|
- `type` (optional): Per-model override of the provider protocol type. Supports `anthropic`, `openai-compatible`, and `openai-responses`. When set, the provider's `/v1/messages` route uses this model's type instead of the provider-level type for request routing, auth header resolution, and upstream endpoint selection. This is useful for providers like OpenCode Go whose upstream supports both OpenAI-compatible and Anthropic Messages APIs for different models. When the type is overridden, the auth header is resolved from the overridden type's default (Anthropic defaults to `x-api-key`; OpenAI-compatible/Responses default to `authorization`).
|
|
703
747
|
- `contextWindow` (optional): Context window token limit advertised when this model is merged into the Codex-UA model catalog; for example, `1000000` declares a 1M-token context window. Missing configured values use upstream metadata first, then the built-in non-GPT model catalog, then `256000`.
|
|
704
748
|
- `maxOutputTokens` (optional): Maximum output token limit advertised in the Codex-UA model catalog. Missing configured values use upstream metadata first, then the built-in non-GPT model catalog, where defaults are capped at `64000`, then `32000`.
|
|
@@ -712,9 +756,9 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
|
|
|
712
756
|
- **Priority:** request `output_config.effort` > `modelReasoningEfforts[model]` > built-in default (`xhigh` for GPT-5.3+ models, otherwise `high`).
|
|
713
757
|
- **Forwarding:** the resolved value remains `output_config.effort` for the Copilot native Messages API and becomes `reasoning.effort` when translated to the Responses API.
|
|
714
758
|
- **Configuration values:** `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`.
|
|
715
|
-
- **useMessagesApi:** When `true`,
|
|
716
|
-
- **useResponsesApiCompactionRecovery (experimental):** When `true`, successful remote Responses compactions enqueue a non-blocking, low-reasoning shadow-summary request and store only that summary under a hash of the opaque compaction item in the private `~/.local/share/copilot-api/compaction-recovery/cache.sqlite` directory. If Copilot later rejects that compaction
|
|
717
|
-
- **useResponsesApiWebSocket:** When `true`, Responses
|
|
759
|
+
- **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`.
|
|
760
|
+
- **useResponsesApiCompactionRecovery (experimental):** When `true`, successful remote Responses compactions enqueue a non-blocking, low-reasoning shadow-summary request and store only that summary under a hash of the opaque compaction item in the private `~/.local/share/copilot-api/compaction-recovery/cache.sqlite` directory. If Copilot later rejects that compaction or connection-bound history, HTTP requests progressively rebuild the request from cached summaries and visible messages. This option defaults to `false` because shadow summaries add one background model request and recovery is lossy. WebSocket errors are recovered on the client's next retry; automatic same-request recovery is HTTP-only.
|
|
761
|
+
- **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.
|
|
718
762
|
- **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.
|
|
719
763
|
- **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`.
|
|
720
764
|
- **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.
|
|
@@ -752,7 +796,7 @@ curl http://localhost:4141/admin/config/model-mappings \
|
|
|
752
796
|
|
|
753
797
|
## API Endpoints
|
|
754
798
|
|
|
755
|
-
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.
|
|
799
|
+
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.
|
|
756
800
|
|
|
757
801
|
### OpenAI Compatible Endpoints
|
|
758
802
|
|
|
@@ -765,33 +809,26 @@ These endpoints mimic the OpenAI API structure.
|
|
|
765
809
|
| `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. |
|
|
766
810
|
| `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. |
|
|
767
811
|
|
|
768
|
-
### Codex Backend
|
|
812
|
+
### Codex Backend Endpoints
|
|
769
813
|
|
|
770
|
-
These endpoints require an active Codex login
|
|
814
|
+
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.
|
|
771
815
|
|
|
772
816
|
| Endpoint | Method | Description |
|
|
773
817
|
| -------------------------------------------------------------- | ------ | --------------------------------------------------------------- |
|
|
774
|
-
| `POST /
|
|
775
|
-
| `POST /
|
|
776
|
-
| `POST /
|
|
818
|
+
| `POST /v1/alpha/search` | `POST` | Routes Codex alpha-search requests to the Codex backend, or handles supported commands locally and through Responses web search. |
|
|
819
|
+
| `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`. |
|
|
820
|
+
| `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. |
|
|
777
821
|
|
|
778
|
-
For
|
|
822
|
+
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.
|
|
779
823
|
|
|
780
824
|
### Anthropic Compatible Endpoints
|
|
781
825
|
|
|
782
|
-
These endpoints are designed to be compatible with the Anthropic Messages API.
|
|
826
|
+
These endpoints are designed to be compatible with the Anthropic Messages API.
|
|
783
827
|
|
|
784
828
|
| Endpoint | Method | Description |
|
|
785
829
|
| -------------------------------- | ------ | ------------------------------------------------------------ |
|
|
786
830
|
| `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. |
|
|
787
831
|
| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. Supports `provider/model` aliases for configured providers. |
|
|
788
|
-
| `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. |
|
|
789
|
-
| `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. |
|
|
790
|
-
| `POST /:provider/v1/messages/count_tokens` | `POST` | Calculates tokens locally for provider route requests. |
|
|
791
|
-
| `POST /:provider/responses`<br>`POST /:provider/v1/responses` | `POST` | Proxies OpenAI Responses requests to a configured `openai-responses` provider (including `codex`). |
|
|
792
|
-
| `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`. |
|
|
793
|
-
| `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). |
|
|
794
|
-
| `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). |
|
|
795
832
|
|
|
796
833
|
### Usage Monitoring Endpoints
|
|
797
834
|
|
|
@@ -800,7 +837,6 @@ New endpoints for monitoring your Copilot usage and quotas.
|
|
|
800
837
|
| Endpoint | Method | Description |
|
|
801
838
|
| ------------ | ------ | ------------------------------------------------------------ |
|
|
802
839
|
| `GET /usage` | `GET` | Get detailed Copilot usage statistics and quota information. |
|
|
803
|
-
| `GET /token` | `GET` | Get the current Copilot token being used by the API. |
|
|
804
840
|
|
|
805
841
|
### Admin / Configuration Endpoints
|
|
806
842
|
|
|
@@ -817,23 +853,23 @@ Common `npx` commands:
|
|
|
817
853
|
|
|
818
854
|
```sh
|
|
819
855
|
# Start the gateway
|
|
820
|
-
npx xiaodcs-copilot-api@latest start
|
|
856
|
+
npx xiaodcs-copilot-api-edge@latest start
|
|
821
857
|
|
|
822
858
|
# Start on a custom port with verbose logging
|
|
823
|
-
npx xiaodcs-copilot-api@latest start --port 8080 --verbose
|
|
859
|
+
npx xiaodcs-copilot-api-edge@latest start --port 8080 --verbose
|
|
824
860
|
|
|
825
861
|
# Run the auth flow
|
|
826
|
-
npx xiaodcs-copilot-api@latest auth login
|
|
862
|
+
npx xiaodcs-copilot-api-edge@latest auth login
|
|
827
863
|
|
|
828
864
|
# Configure a third-party provider, then run without GitHub Copilot
|
|
829
|
-
npx xiaodcs-copilot-api@latest auth login --provider dashscope
|
|
830
|
-
npx xiaodcs-copilot-api@latest start
|
|
865
|
+
npx xiaodcs-copilot-api-edge@latest auth login --provider dashscope
|
|
866
|
+
npx xiaodcs-copilot-api-edge@latest start
|
|
831
867
|
|
|
832
868
|
# Print debug information as JSON
|
|
833
|
-
npx xiaodcs-copilot-api@latest debug --json
|
|
869
|
+
npx xiaodcs-copilot-api-edge@latest debug --json
|
|
834
870
|
|
|
835
871
|
# Run the published CLI with Bun instead of Node.js
|
|
836
|
-
bunx --bun xiaodcs-copilot-api@latest start
|
|
872
|
+
bunx --bun xiaodcs-copilot-api-edge@latest start
|
|
837
873
|
```
|
|
838
874
|
|
|
839
875
|
OpenAI-compatible provider examples after configuring `dashscope`:
|