@jeffreycao/copilot-api 1.12.8 → 1.13.0
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 +107 -62
- package/README.zh-CN.md +107 -62
- package/dist/auth-BwQ7Vhzt.js +2 -0
- package/dist/{auth-BMROoous.js → auth-DcYySZhC.js} +151 -8
- package/dist/auth-DcYySZhC.js.map +1 -0
- package/dist/{config-B71_S_hQ.js → config-CQxppJtD.js} +5 -1
- package/dist/config-CQxppJtD.js.map +1 -0
- package/dist/{debug-TyT2u9dt.js → debug-IUKehQot.js} +2 -2
- package/dist/{debug-TyT2u9dt.js.map → debug-IUKehQot.js.map} +1 -1
- package/dist/electron-fetch-DPhDE6JE.js +22 -0
- package/dist/electron-fetch-DPhDE6JE.js.map +1 -0
- package/dist/main.js +6 -25
- package/dist/main.js.map +1 -1
- package/dist/{mcp-CTb-DbQH.js → mcp-BseuqgHR.js} +2 -2
- package/dist/{mcp-CTb-DbQH.js.map → mcp-BseuqgHR.js.map} +1 -1
- package/dist/{server-DQXpAOIW.js → server-7U9OZLf0.js} +451 -93
- package/dist/server-7U9OZLf0.js.map +1 -0
- package/dist/{start-BW-kr6B8.js → start-Dq2b9vPm.js} +69 -58
- package/dist/start-Dq2b9vPm.js.map +1 -0
- package/dist/{tls-CaLAeSaF.js → tls-BniQ6Rel.js} +1 -1
- package/dist/{tls-CaLAeSaF.js.map → tls-BniQ6Rel.js.map} +1 -1
- package/dist/{token-fpw8tAQS.js → token-CFArcYwb.js} +8 -6
- package/dist/token-CFArcYwb.js.map +1 -0
- package/dist/{tool-search-D3SN0jX-.js → tool-search-OX6iPJ9D.js} +1 -1
- package/dist/{tool-search-D3SN0jX-.js.map → tool-search-OX6iPJ9D.js.map} +1 -1
- package/package.json +1 -1
- package/pages/index.html +68 -14
- package/dist/auth-BMROoous.js.map +0 -1
- package/dist/check-usage-7Dxi5XkE.js +0 -43
- package/dist/check-usage-7Dxi5XkE.js.map +0 -1
- package/dist/config-B71_S_hQ.js.map +0 -1
- package/dist/server-DQXpAOIW.js.map +0 -1
- package/dist/start-BW-kr6B8.js.map +0 -1
- package/dist/token-fpw8tAQS.js.map +0 -1
package/README.md
CHANGED
|
@@ -9,27 +9,27 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
9
9
|
>
|
|
10
10
|
> 1. **Claude Code configuration:** When using with Claude Code, please configure the model ID as `claude-opus-4-6` or `claude-opus-4.6`. Example claude `settings.json` see [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson).
|
|
11
11
|
>
|
|
12
|
-
> 2. **
|
|
13
|
-
> ```sh
|
|
14
|
-
> npx @jeffreycao/copilot-api@latest --oauth-app=opencode start
|
|
15
|
-
> ```
|
|
12
|
+
> 2. **Built-in `copilot`, `codex` and third-party providers:** Run `npx @jeffreycao/copilot-api@latest auth` and choose `copilot`, `codex`, `deepseek`, `custom`, or other providers.
|
|
16
13
|
>
|
|
17
|
-
> 3. **
|
|
18
|
-
>
|
|
19
|
-
> 4. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
|
|
14
|
+
> 3. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
|
|
20
15
|
|
|
21
16
|
---
|
|
22
17
|
|
|
23
18
|
## Project Overview
|
|
24
19
|
|
|
25
|
-
A
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
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.
|
|
26
23
|
|
|
27
24
|
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
25
|
|
|
29
26
|
## Features
|
|
30
27
|
|
|
31
28
|
- **OpenAI and Anthropic compatibility**: Serve `/v1/responses`, `/v1/chat/completions`, `/v1/models`, `/v1/embeddings`, and `/v1/messages` from one local gateway.
|
|
29
|
+
- **Copilot is optional**: Use GitHub Copilot when credentials are present, or run the server with only configured providers.
|
|
32
30
|
- **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.
|
|
31
|
+
- **Standalone third-party providers**: Configure providers such as DashScope, DeepSeek, OpenRouter, or a custom provider and start the gateway without a GitHub Copilot login.
|
|
32
|
+
- **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.
|
|
33
33
|
- **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.
|
|
34
34
|
- **Claude Code and OpenCode integration**: Works with Claude Code and OpenCode, including direct Anthropic-compatible usage through `@ai-sdk/anthropic`.
|
|
35
35
|
- **Flexible auth and deployment options**: Supports interactive login or direct tokens, individual/business/enterprise plans, GitHub Enterprise, opencode OAuth, and custom data directories.
|
|
@@ -41,7 +41,8 @@ On the GitHub Copilot path, the gateway prefers Copilot's native Anthropic-style
|
|
|
41
41
|
|
|
42
42
|
- Bun (>= 1.2.x)
|
|
43
43
|
- Node.js if you plan to run the published CLI with `npx`
|
|
44
|
-
- GitHub account with Copilot subscription
|
|
44
|
+
- GitHub account with Copilot subscription only if you want to use the GitHub Copilot provider
|
|
45
|
+
- An API key or OAuth login for at least one configured provider if you want to run without GitHub Copilot
|
|
45
46
|
|
|
46
47
|
## Installation
|
|
47
48
|
|
|
@@ -76,21 +77,28 @@ With options:
|
|
|
76
77
|
npx @jeffreycao/copilot-api@latest start --port 8080
|
|
77
78
|
```
|
|
78
79
|
|
|
79
|
-
For authentication only:
|
|
80
|
+
For authentication or provider configuration only:
|
|
80
81
|
|
|
81
82
|
```sh
|
|
82
83
|
npx @jeffreycao/copilot-api@latest auth
|
|
83
84
|
```
|
|
84
85
|
|
|
86
|
+
To run without GitHub Copilot, configure at least one provider first, then start the server normally:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
npx @jeffreycao/copilot-api@latest auth login --provider dashscope
|
|
90
|
+
npx @jeffreycao/copilot-api@latest start
|
|
91
|
+
```
|
|
92
|
+
|
|
85
93
|
## Electron Desktop App
|
|
86
94
|
|
|
87
|
-
If you prefer a GUI, this repository also includes an Electron desktop app in `desktop/`. It supports GitHub Copilot sign-in or
|
|
95
|
+
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 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.
|
|
88
96
|
|
|
89
97
|
The settings screen also exposes `OAuth App`, `API Home`, `Enterprise URL`, verbose logging, and minimize-to-tray. Desktop packages are published in GitHub Releases:
|
|
90
98
|
|
|
91
99
|
https://github.com/caozhiyuan/copilot-api/releases
|
|
92
100
|
|
|
93
|
-
Download the installer for your platform,
|
|
101
|
+
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.
|
|
94
102
|
|
|
95
103
|
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.
|
|
96
104
|
|
|
@@ -118,7 +126,7 @@ mkdir -p ./copilot-data
|
|
|
118
126
|
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api
|
|
119
127
|
```
|
|
120
128
|
|
|
121
|
-
This stores GitHub auth data in `./copilot-data` on the host, mapped to `/root/.local/share/copilot-api` in the container.
|
|
129
|
+
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.
|
|
122
130
|
|
|
123
131
|
Or pass a GitHub token directly:
|
|
124
132
|
|
|
@@ -130,9 +138,8 @@ docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api
|
|
|
130
138
|
|
|
131
139
|
Copilot API now uses a subcommand structure with these main commands:
|
|
132
140
|
|
|
133
|
-
- `start`: Start the
|
|
134
|
-
- `auth`: Run
|
|
135
|
-
- `check-usage`: Show your current GitHub Copilot usage and quota information directly in the terminal (no server required).
|
|
141
|
+
- `start`: Start the gateway server. If a GitHub token is available, the server starts with Copilot enabled. If no GitHub token is available, it starts in provider-only mode when at least one enabled provider exists; otherwise it guides you through provider setup.
|
|
142
|
+
- `auth`: Run provider login or configuration without starting the server. Use it for GitHub Copilot login, Codex OAuth, or third-party provider API key setup.
|
|
136
143
|
- `debug`: Display diagnostic information including version, runtime details, file paths, and authentication status. Useful for troubleshooting and support.
|
|
137
144
|
|
|
138
145
|
## Command Line Options
|
|
@@ -155,7 +162,6 @@ The following command line options are available for the `start` command:
|
|
|
155
162
|
| -------------- | ----------------------------------------------------------------------------- | ---------- | ----- |
|
|
156
163
|
| --port | Port to listen on | 4141 | -p |
|
|
157
164
|
| --verbose | Enable verbose logging | false | -v |
|
|
158
|
-
| --account-type | Account type to use (individual, business, enterprise) | individual | -a |
|
|
159
165
|
| --manual | Enable manual request approval | false | none |
|
|
160
166
|
| --rate-limit | Rate limit in seconds between requests | none | -r |
|
|
161
167
|
| --wait | Wait instead of error when rate limit is hit | false | -w |
|
|
@@ -168,11 +174,15 @@ The following command line options are available for the `start` command:
|
|
|
168
174
|
|
|
169
175
|
| Option | Description | Default | Alias |
|
|
170
176
|
| ------------ | ------------------------- | ------- | ----- |
|
|
171
|
-
| --provider | Provider to log in with or configure (`copilot`, `codex`, or `custom`) | prompt | none |
|
|
177
|
+
| --provider | Provider to log in with or configure (`copilot`, `codex`, `deepseek`, `dashscope`, `openrouter`, or `custom`) | prompt | none |
|
|
172
178
|
| --verbose | Enable verbose logging | false | -v |
|
|
173
179
|
| --show-token | Show GitHub token on auth | false | none |
|
|
174
180
|
|
|
175
|
-
Use `copilot-api auth login --provider
|
|
181
|
+
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.
|
|
182
|
+
|
|
183
|
+
Use `copilot-api auth login --provider deepseek`, `--provider dashscope`, or `--provider openrouter` to add or update those common third-party providers from the CLI. DeepSeek and DashScope prompt for masked `apiKey`, provider `type` (default `openai-compatible`), and `baseUrl` with the provider default prefilled. OpenRouter prompts for masked `apiKey` and prefilled `baseUrl` only, and writes `type: "anthropic"`. After a provider is configured and enabled, `copilot-api start` can run without any GitHub token.
|
|
184
|
+
|
|
185
|
+
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`.
|
|
176
186
|
|
|
177
187
|
### Debug Command Options
|
|
178
188
|
|
|
@@ -190,39 +200,7 @@ Use `copilot-api auth login --provider custom` to add or update a third-party pr
|
|
|
190
200
|
"apiKeys": [],
|
|
191
201
|
"adminApiKey": "<auto-generated-on-startup>"
|
|
192
202
|
},
|
|
193
|
-
"providers": {
|
|
194
|
-
"custom": {
|
|
195
|
-
"type": "anthropic",
|
|
196
|
-
"enabled": true,
|
|
197
|
-
"baseUrl": "your-base-url",
|
|
198
|
-
"apiKey": "sk-your-provider-key",
|
|
199
|
-
"authType": "x-api-key"
|
|
200
|
-
},
|
|
201
|
-
"dashscope": {
|
|
202
|
-
"type": "openai-compatible",
|
|
203
|
-
"enabled": true,
|
|
204
|
-
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode",
|
|
205
|
-
"apiKey": "sk-your-dashscope-key",
|
|
206
|
-
"models": {
|
|
207
|
-
"qwen3.6-plus": {
|
|
208
|
-
"temperature": 1,
|
|
209
|
-
"topP": 0.95,
|
|
210
|
-
"topK": 20,
|
|
211
|
-
"extraBody": {
|
|
212
|
-
"preserve_thinking": true
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
"glm-5.1": {
|
|
216
|
-
"temperature": 0.7,
|
|
217
|
-
"topP": 0.95,
|
|
218
|
-
"contextCache": true,
|
|
219
|
-
"extraBody": {
|
|
220
|
-
"preserve_thinking": true
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
},
|
|
203
|
+
"providers": {},
|
|
226
204
|
"modelMappings": {},
|
|
227
205
|
"extraPrompts": {
|
|
228
206
|
"gpt-5-mini": "<built-in exploration prompt>",
|
|
@@ -254,19 +232,75 @@ Use `copilot-api auth login --provider custom` to add or update a third-party pr
|
|
|
254
232
|
- **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/*`.
|
|
255
233
|
- **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.
|
|
256
234
|
- **extraPrompts:** Map of `model -> prompt` appended to the first system prompt when translating Anthropic-style requests to Copilot. Use this to inject guardrails or guidance per model. Missing default entries are auto-added without overwriting your custom prompts. The built-in prompts for `gpt-5.3-codex` and `gpt-5.4` enable phase-aware commentary, which lets the model emit a short user-facing progress update before tools or deeper reasoning.
|
|
257
|
-
- **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. `GET /v1/models` does not aggregate provider models; use `GET /dashscope/v1/models` for provider model lists.
|
|
235
|
+
- **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. `openai-compatible` providers support both chat and Messages flows: `/v1/chat/completions` is proxied to upstream `/v1/chat/completions`, while `/v1/messages` and `/:provider/v1/messages` are translated to upstream chat completions and translated back to Anthropic Messages responses. `GET /v1/models` does not aggregate provider models; use `GET /dashscope/v1/models` for provider model lists.
|
|
258
236
|
- `enabled` defaults to `true` if omitted.
|
|
259
237
|
- `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`.
|
|
260
238
|
- `apiKey` is used as the upstream credential value and is required for regular providers.
|
|
261
239
|
- `authType` (optional): Controls how `apiKey` is sent upstream. Supports `x-api-key` and `authorization` for regular providers. Anthropic providers default to `x-api-key`; OpenAI-compatible and OpenAI Responses providers default to `authorization`. When set to `authorization`, the proxy sends `Authorization: Bearer <apiKey>`. `oauth2` is reserved for the built-in `codex` provider and is written automatically by `auth login --provider codex`.
|
|
240
|
+
- `pricingCurrency` (optional): Provider-level currency used for token cost calculation, for example `USD` or `CNY`. Quick providers default to `CNY` for DashScope and DeepSeek, and `USD` for Codex/OpenRouter. Costs are grouped by currency and are not exchange-rate converted.
|
|
262
241
|
- `models` (optional): Per-model configuration map. Each key is a model ID (matching the model name in requests), and the value is:
|
|
263
242
|
- `temperature` (optional): Default temperature value used when the request does not specify one.
|
|
264
243
|
- `topP` (optional): Default top_p value used when the request does not specify one.
|
|
265
244
|
- `topK` (optional): Default top_k value used when the request does not specify one.
|
|
266
245
|
- `extraBody` (optional): Dynamic fields merged into the upstream request body for that model. Request body fields with the same name take precedence. OpenAI-compatible providers can use this for fields such as `enable_thinking`, `preserve_thinking`, `reasoning_effort`. `thinking_budget` is a special OpenAI-compatible provider override: when configured in `extraBody`, it is forced after Anthropic `thinking.budget_tokens` translation and overrides the request-derived budget.
|
|
246
|
+
- `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.
|
|
267
247
|
- `contextCache` (optional): Defaults to `true` for 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.
|
|
268
248
|
- `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.
|
|
269
249
|
- `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. This provider default does not change the Copilot main flow, which continues to support array + image and not PDF.
|
|
250
|
+
|
|
251
|
+
Example DashScope model settings:
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"providers": {
|
|
255
|
+
"dashscope": {
|
|
256
|
+
"type": "openai-compatible",
|
|
257
|
+
"enabled": true,
|
|
258
|
+
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode",
|
|
259
|
+
"apiKey": "sk-your-dashscope-key",
|
|
260
|
+
"pricingCurrency": "CNY",
|
|
261
|
+
"models": {
|
|
262
|
+
"qwen3.6-plus": {
|
|
263
|
+
"temperature": 1,
|
|
264
|
+
"topP": 0.95,
|
|
265
|
+
"topK": 20,
|
|
266
|
+
"extraBody": {
|
|
267
|
+
"preserve_thinking": true
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
"glm-5.1": {
|
|
271
|
+
"temperature": 0.7,
|
|
272
|
+
"topP": 0.95,
|
|
273
|
+
"contextCache": true,
|
|
274
|
+
"pricing": {
|
|
275
|
+
"tiers": [
|
|
276
|
+
{
|
|
277
|
+
"maxInputTokens": 32000,
|
|
278
|
+
"input": 6,
|
|
279
|
+
"cachedInput": 1.2,
|
|
280
|
+
"explicitCachedInput": 0.6,
|
|
281
|
+
"cacheCreationInput": 7.5,
|
|
282
|
+
"output": 24
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
"maxInputTokens": 200000,
|
|
286
|
+
"input": 8,
|
|
287
|
+
"cachedInput": 1.6,
|
|
288
|
+
"explicitCachedInput": 0.8,
|
|
289
|
+
"cacheCreationInput": 10,
|
|
290
|
+
"output": 28
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
},
|
|
294
|
+
"extraBody": {
|
|
295
|
+
"preserve_thinking": true
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
Built-in token prices cover Codex GPT models in USD, DashScope `qwen3.7-max`, `qwen3.7-plus`, `glm-5.1`, `glm-5.2` in CNY, and DeepSeek `deepseek-v4-flash`, `deepseek-v4-pro`, `deepseek-chat`, `deepseek-reasoner` in CNY. User `pricing` entries override built-ins. For DashScope, cached tokens are charged as explicit cache reads when the upstream usage includes `cache_creation_input_tokens`; otherwise `cachedInput` is used as the implicit cache read price. For DeepSeek, `prompt_cache_hit_tokens` map to cached input and `prompt_cache_miss_tokens` map to regular input.
|
|
270
304
|
- **smallModel:** Fallback model used for tool-less warmup messages (e.g., Claude Code probe requests); defaults to gpt-5-mini.
|
|
271
305
|
- **useResponsesApiContextManagement:** When `true`, the proxy adds Responses API `context_management` compaction instructions. Defaults to `true`. Set it to `false` to disable this globally. When enabled, the request includes `context_management` in the body and keeps only the latest compaction carrier on follow-up turns. This is especially useful for long-running tasks.
|
|
272
306
|
- **modelResponsesApiCompactThresholds:** Per-model Responses API `compact_threshold` overrides used when the proxy adds `context_management`. These values take precedence over the fallback threshold from `resolveResponsesCompactThreshold` (`max_prompt_tokens * ratio`, or the default fallback). Defaults set `gpt-5.4` and `gpt-5.5` to `217600` (`272000 * 0.8`). Models not listed continue to use the normal fallback logic.
|
|
@@ -306,7 +340,7 @@ curl http://localhost:4141/admin/config/model-mappings \
|
|
|
306
340
|
|
|
307
341
|
## API Endpoints
|
|
308
342
|
|
|
309
|
-
The server exposes several
|
|
343
|
+
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.
|
|
310
344
|
|
|
311
345
|
### OpenAI Compatible Endpoints
|
|
312
346
|
|
|
@@ -315,7 +349,7 @@ These endpoints mimic the OpenAI API structure.
|
|
|
315
349
|
| Endpoint | Method | Description |
|
|
316
350
|
| --------------------------- | ------ | ---------------------------------------------------------------- |
|
|
317
351
|
| `POST /v1/responses` | `POST` | OpenAI Most advanced interface for generating model responses. Supports `provider/model` aliases for `openai-responses` providers. |
|
|
318
|
-
| `POST /v1/chat/completions` | `POST` | Creates a model response for the given chat conversation. Supports `provider/model` aliases for `openai-compatible` providers. |
|
|
352
|
+
| `POST /v1/chat/completions` | `POST` | Creates a model response for the given chat conversation. Supports `provider/model` aliases for `openai-compatible` providers and can be used without Copilot when the target provider is configured. |
|
|
319
353
|
| `GET /v1/models` | `GET` | Lists the currently available models. |
|
|
320
354
|
| `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. |
|
|
321
355
|
|
|
@@ -325,9 +359,9 @@ These endpoints are designed to be compatible with the Anthropic Messages API.
|
|
|
325
359
|
|
|
326
360
|
| Endpoint | Method | Description |
|
|
327
361
|
| -------------------------------- | ------ | ------------------------------------------------------------ |
|
|
328
|
-
| `POST /v1/messages` | `POST` | Creates a model response for a given conversation. Supports `provider/model` aliases for configured providers. |
|
|
362
|
+
| `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. |
|
|
329
363
|
| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. Supports `provider/model` aliases for configured providers. |
|
|
330
|
-
| `POST /:provider/v1/messages` | `POST` | Proxies Anthropic Messages requests to the configured Anthropic, OpenAI-compatible, or OpenAI Responses provider. |
|
|
364
|
+
| `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. |
|
|
331
365
|
| `GET /:provider/v1/models` | `GET` | Proxies model listing requests to the configured provider. |
|
|
332
366
|
| `POST /:provider/v1/messages/count_tokens` | `POST` | Calculates tokens locally for provider route requests. |
|
|
333
367
|
|
|
@@ -363,8 +397,9 @@ npx @jeffreycao/copilot-api@latest start --port 8080 --verbose
|
|
|
363
397
|
# Run the auth flow
|
|
364
398
|
npx @jeffreycao/copilot-api@latest auth login
|
|
365
399
|
|
|
366
|
-
#
|
|
367
|
-
npx @jeffreycao/copilot-api@latest
|
|
400
|
+
# Configure a third-party provider, then run without GitHub Copilot
|
|
401
|
+
npx @jeffreycao/copilot-api@latest auth login --provider dashscope
|
|
402
|
+
npx @jeffreycao/copilot-api@latest start
|
|
368
403
|
|
|
369
404
|
# Print debug information as JSON
|
|
370
405
|
npx @jeffreycao/copilot-api@latest debug --json
|
|
@@ -373,6 +408,18 @@ npx @jeffreycao/copilot-api@latest debug --json
|
|
|
373
408
|
bunx --bun @jeffreycao/copilot-api@latest start
|
|
374
409
|
```
|
|
375
410
|
|
|
411
|
+
OpenAI-compatible provider examples after configuring `dashscope`:
|
|
412
|
+
|
|
413
|
+
```sh
|
|
414
|
+
curl http://localhost:4141/v1/chat/completions \
|
|
415
|
+
-H "content-type: application/json" \
|
|
416
|
+
-d '{"model":"dashscope/qwen3.6-plus","messages":[{"role":"user","content":"hello"}]}'
|
|
417
|
+
|
|
418
|
+
curl http://localhost:4141/dashscope/v1/messages \
|
|
419
|
+
-H "content-type: application/json" \
|
|
420
|
+
-d '{"model":"qwen3.6-plus","max_tokens":1024,"messages":[{"role":"user","content":"hello"}]}'
|
|
421
|
+
```
|
|
422
|
+
|
|
376
423
|
## Using with Claude Code
|
|
377
424
|
|
|
378
425
|
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.
|
|
@@ -410,8 +457,7 @@ Here is an example `.claude/settings.json` file:
|
|
|
410
457
|
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
411
458
|
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
412
459
|
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
413
|
-
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0"
|
|
414
|
-
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
460
|
+
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0"
|
|
415
461
|
},
|
|
416
462
|
"permissions": {
|
|
417
463
|
"deny": [
|
|
@@ -710,7 +756,6 @@ bun run start start
|
|
|
710
756
|
- `--manual`: Enables manual approval for each request, giving you full control over when requests are sent.
|
|
711
757
|
- `--rate-limit <seconds>`: Enforces a minimum time interval between requests. For example, `copilot-api start --rate-limit 30` will ensure there's at least a 30-second gap between requests.
|
|
712
758
|
- `--wait`: Use this with `--rate-limit`. It makes the server wait for the cooldown period to end instead of rejecting the request with an error. This is useful for clients that don't automatically retry on rate limit errors.
|
|
713
|
-
- If you have a GitHub business or enterprise plan account with Copilot, use the `--account-type` flag (e.g., `--account-type business`). See the [official documentation](https://docs.github.com/en/enterprise-cloud@latest/copilot/managing-copilot/managing-github-copilot-in-your-organization/managing-access-to-github-copilot-in-your-organization/managing-github-copilot-access-to-your-organizations-network#configuring-copilot-subscription-based-network-routing-for-your-enterprise-or-organization) for more details.
|
|
714
759
|
|
|
715
760
|
### CLAUDE.md or AGENTS.md Recommended Content
|
|
716
761
|
|