@jeffreycao/copilot-api 1.12.9 → 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 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. **Recommend for Opencode:** For opencode, prefer the opencode OAuth app. It matches opencode's built-in GitHub Copilot provider and avoids Terms of Service risk:
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. **Built-in `codex` provider:** Run `npx @jeffreycao/copilot-api@latest auth login --provider codex` once and the gateway will persist and refresh Codex OAuth credentials automatically.
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 reverse-engineered GitHub Copilot integration that also works as a small AI gateway. Besides Copilot, it can route the built-in `codex` provider and configured third-party providers such as DashScope behind OpenAI- and Anthropic-compatible APIs, so tools like [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) can use one local endpoint.
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 (individual, business, or enterprise)
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 manual token entry, 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.
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, sign in 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.
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 Copilot API server. This command will also handle authentication if needed.
134
- - `auth`: Run GitHub authentication flow without starting the server. This is typically used if you need to generate a token for use with the `--github-token` option, especially in non-interactive environments.
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 |
@@ -172,7 +178,9 @@ The following command line options are available for the `start` command:
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 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"`.
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.
176
184
 
177
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`.
178
186
 
@@ -224,16 +232,18 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
224
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/*`.
225
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.
226
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.
227
- - **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.
228
236
  - `enabled` defaults to `true` if omitted.
229
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`.
230
238
  - `apiKey` is used as the upstream credential value and is required for regular providers.
231
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.
232
241
  - `models` (optional): Per-model configuration map. Each key is a model ID (matching the model name in requests), and the value is:
233
242
  - `temperature` (optional): Default temperature value used when the request does not specify one.
234
243
  - `topP` (optional): Default top_p value used when the request does not specify one.
235
244
  - `topK` (optional): Default top_k value used when the request does not specify one.
236
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.
237
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.
238
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.
239
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.
@@ -247,6 +257,7 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
247
257
  "enabled": true,
248
258
  "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode",
249
259
  "apiKey": "sk-your-dashscope-key",
260
+ "pricingCurrency": "CNY",
250
261
  "models": {
251
262
  "qwen3.6-plus": {
252
263
  "temperature": 1,
@@ -260,6 +271,26 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
260
271
  "temperature": 0.7,
261
272
  "topP": 0.95,
262
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
+ },
263
294
  "extraBody": {
264
295
  "preserve_thinking": true
265
296
  }
@@ -269,6 +300,7 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
269
300
  }
270
301
  }
271
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.
272
304
  - **smallModel:** Fallback model used for tool-less warmup messages (e.g., Claude Code probe requests); defaults to gpt-5-mini.
273
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.
274
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.
@@ -308,7 +340,7 @@ curl http://localhost:4141/admin/config/model-mappings \
308
340
 
309
341
  ## API Endpoints
310
342
 
311
- The server exposes several endpoints to interact with the Copilot API. It provides OpenAI-compatible endpoints and now also includes support for Anthropic-compatible endpoints, allowing for greater flexibility with different tools and services.
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.
312
344
 
313
345
  ### OpenAI Compatible Endpoints
314
346
 
@@ -317,7 +349,7 @@ These endpoints mimic the OpenAI API structure.
317
349
  | Endpoint | Method | Description |
318
350
  | --------------------------- | ------ | ---------------------------------------------------------------- |
319
351
  | `POST /v1/responses` | `POST` | OpenAI Most advanced interface for generating model responses. Supports `provider/model` aliases for `openai-responses` providers. |
320
- | `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. |
321
353
  | `GET /v1/models` | `GET` | Lists the currently available models. |
322
354
  | `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. |
323
355
 
@@ -327,9 +359,9 @@ These endpoints are designed to be compatible with the Anthropic Messages API.
327
359
 
328
360
  | Endpoint | Method | Description |
329
361
  | -------------------------------- | ------ | ------------------------------------------------------------ |
330
- | `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. |
331
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. |
332
- | `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. |
333
365
  | `GET /:provider/v1/models` | `GET` | Proxies model listing requests to the configured provider. |
334
366
  | `POST /:provider/v1/messages/count_tokens` | `POST` | Calculates tokens locally for provider route requests. |
335
367
 
@@ -365,8 +397,9 @@ npx @jeffreycao/copilot-api@latest start --port 8080 --verbose
365
397
  # Run the auth flow
366
398
  npx @jeffreycao/copilot-api@latest auth login
367
399
 
368
- # Check Copilot usage without starting the server
369
- npx @jeffreycao/copilot-api@latest check-usage
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
370
403
 
371
404
  # Print debug information as JSON
372
405
  npx @jeffreycao/copilot-api@latest debug --json
@@ -375,6 +408,18 @@ npx @jeffreycao/copilot-api@latest debug --json
375
408
  bunx --bun @jeffreycao/copilot-api@latest start
376
409
  ```
377
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
+
378
423
  ## Using with Claude Code
379
424
 
380
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.
@@ -412,8 +457,7 @@ Here is an example `.claude/settings.json` file:
412
457
  "CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
413
458
  "CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
414
459
  "CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
415
- "CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
416
- "CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
460
+ "CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0"
417
461
  },
418
462
  "permissions": {
419
463
  "deny": [
@@ -712,7 +756,6 @@ bun run start start
712
756
  - `--manual`: Enables manual approval for each request, giving you full control over when requests are sent.
713
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.
714
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.
715
- - 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.
716
759
 
717
760
  ### CLAUDE.md or AGENTS.md Recommended Content
718
761
 
package/README.zh-CN.md CHANGED
@@ -9,27 +9,27 @@
9
9
  >
10
10
  > 1. **Claude Code 配置:** 与 Claude Code 搭配使用时,请将模型 ID 配置为 `claude-opus-4-6` 或 `claude-opus-4.6`。示例 claude `settings.json` 见 [通过 `settings.json` 手动配置](#manual-configuration-with-settingsjson)。
11
11
  >
12
- > 2. **推荐给 opencode 用户:** opencode 而言,优先使用 opencode OAuth app。它与 opencode 内置的 GitHub Copilot provider 行为一致,且没有 Terms of Service 风险:
13
- > ```sh
14
- > npx @jeffreycao/copilot-api@latest --oauth-app=opencode start
15
- > ```
12
+ > 2. **内置 `copilot`、`codex` 与第三方 provider:** 执行 `npx @jeffreycao/copilot-api@latest auth`,可选择 `copilot`、`codex`、`deepseek`、`custom` provider
16
13
  >
17
- > 3. **内置 `codex` provider:** 执行一次 `npx @jeffreycao/copilot-api@latest auth login --provider codex` 后,AI gateway 会自动持久化并刷新 Codex OAuth 凭据。
18
- >
19
- > 4. **注意事项:** README 顶部移除的 GitHub Copilot warning 见 [GitHub Copilot 安全提示](./NOTICE.md#github-copilot-security-notice)。
14
+ > 3. **注意事项:** README 顶部移除的 GitHub Copilot warning [GitHub Copilot 安全提示](./NOTICE.md#github-copilot-security-notice)。
20
15
 
21
16
  ---
22
17
 
23
18
  ## 项目概览
24
19
 
25
- 这个项目最初是一个通过逆向工程实现的 GitHub Copilot API 代理,但现在也可以看作一个小型 AI gateway。除了 Copilot,它还可以在同一个 OpenAI / Anthropic 兼容入口后面路由内置的 `codex` provider 和第三方 provider,例如 DashScope,让 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) 这类工具复用同一个本地端点。
20
+ 这是一个小型 AI gateway,可以使用 GitHub Copilot、内置 `codex` provider,也可以使用 DashScope 等已配置的第三方 provider。GitHub Copilot 现在是可选能力:如果本地没有 GitHub token,只要至少配置了一个启用中的 provider,服务仍可按 provider-only 模式启动。
21
+
22
+ AI gateway 会从同一个本地端点暴露 OpenAI / Anthropic 兼容 API,让 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview)、OpenCode、Codex 和 OpenAI 兼容客户端可以共用同一个本地服务。
26
23
 
27
24
  在 GitHub Copilot 路径上,AI gateway 会在可用时优先使用 Copilot 原生的 Anthropic 风格 Messages API,在重工具调用场景下保留更原生的 Claude 行为。
28
25
 
29
26
  ## 功能特性
30
27
 
31
28
  - **OpenAI 与 Anthropic 双兼容**:通过 `/v1/responses`、`/v1/chat/completions`、`/v1/models`、`/v1/embeddings` 和 `/v1/messages` 对外暴露同一个本地 AI gateway。
29
+ - **Copilot 可选**:有 GitHub 凭据时可以使用 GitHub Copilot,没有 GitHub 凭据时也可以只依赖已配置的 provider 运行。
32
30
  - **同一网关接入 Copilot、`codex` 与第三方 provider**:可统一路由 GitHub Copilot、内置 `codex` provider 和配置好的外部 provider。
31
+ - **第三方 provider 可独立启动**:配置 DashScope、DeepSeek、OpenRouter 或自定义 provider 后,不需要 GitHub Copilot 登录即可启动 AI gateway。
32
+ - **OpenAI 兼容 provider 同时支持 chat 和 Messages API**:`openai-compatible` provider 可通过顶层 `/v1/chat/completions` 搭配 `model: "provider/model"` 提供 Chat Completions,也可通过 `/v1/messages` 完成 Anthropic Messages 的请求/响应翻译。
33
33
  - **面向 Claude 的更原生 Copilot 路由**:优先使用原生 `/v1/messages`,保留 Claude 风格工具流,支持 Anthropic beta 能力、通过 Responses-capable 模型支持 Claude WebSearch,并保留 subagent / session 标记。
34
34
  - **Claude Code 与 OpenCode 集成**:兼容 Claude Code 与 OpenCode,也支持通过 `@ai-sdk/anthropic` 直接作为 Anthropic provider 使用。
35
35
  - **灵活的认证与部署选项**:支持交互式登录、直接 token、个人 / Business / Enterprise、GitHub Enterprise、opencode OAuth 和自定义数据目录。
@@ -41,7 +41,8 @@
41
41
 
42
42
  - Bun(>= 1.2.x)
43
43
  - 如果要通过 `npx` 运行已发布 CLI,需要 Node.js
44
- - 已订阅 Copilot 的 GitHub 账号(个人版、Business 或 Enterprise)
44
+ - 只有在使用 GitHub Copilot provider 时,才需要已订阅 Copilot 的 GitHub 账号
45
+ - 如果不使用 GitHub Copilot,需要至少一个已配置 provider 的 API key 或 OAuth 登录
45
46
 
46
47
  ## 安装
47
48
 
@@ -76,21 +77,28 @@ npx @jeffreycao/copilot-api@latest start
76
77
  npx @jeffreycao/copilot-api@latest start --port 8080
77
78
  ```
78
79
 
79
- 如果只想做认证:
80
+ 如果只想做认证或 provider 配置:
80
81
 
81
82
  ```sh
82
83
  npx @jeffreycao/copilot-api@latest auth
83
84
  ```
84
85
 
86
+ 如果要不依赖 GitHub Copilot 运行,先配置至少一个 provider,然后正常启动服务:
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 桌面应用
86
94
 
87
- 如果你更喜欢图形界面,仓库里还提供了位于 `desktop/` 的 Electron 桌面应用。它支持 GitHub Copilot 登录或手动填入 token,可以一键启动或停止本地代理,并在界面里直接查看本地端点、鉴权 Header、可用模型、额度和日志。
95
+ 如果你更喜欢图形界面,仓库里还提供了位于 `desktop/` 的 Electron 桌面应用。它支持 GitHub Copilot 登录、OpenAI Codex OAuth,以及 DeepSeek、DashScope、OpenRouter 或自定义 provider 的 API Key 配置。授权或配置 provider 后,可以一键启动或停止本地代理,并在界面里直接查看本地端点、鉴权 Header、可用模型、额度和日志。
88
96
 
89
97
  设置页还可以配置 `OAuth App`、`API Home`、`Enterprise URL`、详细日志以及最小化到托盘。桌面安装包发布在 GitHub Releases:
90
98
 
91
99
  https://github.com/caozhiyuan/copilot-api/releases
92
100
 
93
- 下载对应平台的安装包后,在应用内登录、选择端口并启动服务,再把你的客户端指向应用里显示的本地端点即可。发布版桌面应用使用随包内置的 Electron 运行时,正常使用不需要额外安装 Node.js;token usage 历史记录会在该内置运行时支持 SQLite 时启用。
101
+ 下载对应平台的安装包后,在应用内授权或配置 provider,选择端口并启动服务,再把你的客户端指向应用里显示的本地端点即可。发布版桌面应用使用随包内置的 Electron 运行时,正常使用不需要额外安装 Node.js;token usage 历史记录会在该内置运行时支持 SQLite 时启用。
94
102
 
95
103
  桌面应用里的高级配置页会通过 `GET/POST /admin/config/model-mappings` 读写这份共享的模型映射。同一份映射会统一作用于 `POST /v1/messages`、`POST /v1/messages/count_tokens`、`POST /v1/responses` 和 `POST /v1/chat/completions`,不再按接口区分。它使用的是 `auth.adminApiKey`,不是普通的 `auth.apiKeys`;应用会在服务启动并自动生成该 key 后,直接从 `config.json` 读取它来发起请求。
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
- 这会把宿主机上的 `./copilot-data` 映射到容器内的 `/root/.local/share/copilot-api`,用于持久化 GitHub 认证数据。
129
+ 这会把宿主机上的 `./copilot-data` 映射到容器内的 `/root/.local/share/copilot-api`,用于持久化 GitHub 认证数据、provider 配置和其他 gateway 状态。
122
130
 
123
131
  也可以直接通过环境变量传入 GitHub token:
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 现在使用子命令结构,主要命令包括:
132
140
 
133
- - `start`:启动 Copilot API 服务。如有需要,也会自动处理认证。
134
- - `auth`:仅执行 GitHub 认证流程,不启动服务。通常用于生成可与 `--github-token` 一起使用的 token,尤其适合非交互环境。
135
- - `check-usage`:直接在终端中显示当前 GitHub Copilot 用量与额度信息(无需启动服务)。
141
+ - `start`:启动 AI gateway 服务。如果已有 GitHub token,则启用 Copilot 路径;如果没有 GitHub token,但存在至少一个启用中的 provider,则按 provider-only 模式启动;如果两者都没有,会引导你配置 provider。
142
+ - `auth`:仅执行 provider 登录或配置流程,不启动服务。可用于 GitHub Copilot 登录、Codex OAuth,或第三方 provider API key 配置。
136
143
  - `debug`:显示诊断信息,包括版本、运行时详情、文件路径以及认证状态,便于排障与支持。
137
144
 
138
145
  ## 命令行选项
@@ -155,7 +162,6 @@ Copilot API 现在使用子命令结构,主要命令包括:
155
162
  | --- | --- | --- | --- |
156
163
  | --port | 监听端口 | 4141 | -p |
157
164
  | --verbose | 启用详细日志 | false | -v |
158
- | --account-type | 使用的账号类型(individual、business、enterprise) | individual | -a |
159
165
  | --manual | 启用手动请求审批 | false | 无 |
160
166
  | --rate-limit | 请求之间的速率限制秒数 | 无 | -r |
161
167
  | --wait | 达到速率限制时等待,而不是直接报错 | false | -w |
@@ -172,7 +178,9 @@ Copilot API 现在使用子命令结构,主要命令包括:
172
178
  | --verbose | 启用详细日志 | false | -v |
173
179
  | --show-token | 认证时显示 GitHub token | false | 无 |
174
180
 
175
- 使用 `copilot-api auth login --provider deepseek`、`--provider dashscope` 或 `--provider openrouter` 可以通过 CLI 快速新增或更新这些常用第三方 provider。DeepSeek 和 DashScope 会提示输入掩码显示的 `apiKey`、provider `type`(默认 `openai-compatible`)和预填默认值的 `baseUrl`。OpenRouter 只提示输入掩码显示的 `apiKey` 和预填默认值的 `baseUrl`,并固定写入 `type: "anthropic"`。
181
+ 只有在需要启用 GitHub Copilot provider 时,才需要执行 `copilot-api auth login --provider copilot`。使用 `codex` 或第三方 provider-only 模式不要求配置 Copilot。
182
+
183
+ 使用 `copilot-api auth login --provider deepseek`、`--provider dashscope` 或 `--provider openrouter` 可以通过 CLI 快速新增或更新这些常用第三方 provider。DeepSeek 和 DashScope 会提示输入掩码显示的 `apiKey`、provider `type`(默认 `openai-compatible`)和预填默认值的 `baseUrl`。OpenRouter 只提示输入掩码显示的 `apiKey` 和预填默认值的 `baseUrl`,并固定写入 `type: "anthropic"`。配置并启用 provider 后,`copilot-api start` 可在没有 GitHub token 的情况下启动。
176
184
 
177
185
  使用 `copilot-api auth login --provider custom` 可以通过 CLI 新增或更新其他第三方 provider。命令会依次提示输入 provider name、项目支持的 type(`anthropic`、`openai-compatible` 或 `openai-responses`)、`baseUrl`、掩码显示的 `apiKey` 和 `authType`;`authType` 可保持 type 默认值,也可选择 `x-api-key` / `authorization`。
178
186
 
@@ -226,16 +234,18 @@ Copilot API 现在使用子命令结构,主要命令包括:
226
234
  - **auth.adminApiKey:** 仅用于 `/admin/*` 路由的单个 admin key。若未配置,服务会在启动时自动生成一个随机 key,并回写到 `config.json`。它同样使用 `x-api-key` 或 `Authorization: Bearer` 这两种头,但普通 `auth.apiKeys` 不能访问 `/admin/*`。
227
235
  - **modelMappings:** 用于顶层 `POST /v1/messages`、`POST /v1/messages/count_tokens`、`POST /v1/responses` 和 `POST /v1/chat/completions` 请求的精确 `sourceModel -> targetModel` 重写映射,这几类接口共用同一份规则。省略该字段或保留为 `{}` 时,不会做模型重写。`source` 和 `target` 都必须是非空字符串。`target` 可以是普通模型 ID,也可以是 `provider/model` 形式的别名,例如 `dashscope/qwen3.6-plus`;重写发生在 provider alias 解析之前。这些映射不再按接口区分。`GET/POST /admin/config/model-mappings` 管理接口读写的也只有这个字段。
228
236
  - **extraPrompts:** `model -> prompt` 的映射。把 Anthropic 风格请求翻译给 Copilot 时,会将其附加到第一条 system prompt 后面。你可以借此为不同模型注入护栏或指引。缺失的默认项会自动补齐,但不会覆盖你自定义的 prompt。内置的 `gpt-5.3-codex` 和 `gpt-5.4` prompt 会启用带阶段感知的 commentary,让模型在工具调用或更深层推理前先发出简短的用户可见进度说明。
229
- - **providers:** 全局上游 provider 映射。每个 provider key(例如 `dashscope`)都会变成一个路由前缀(`/dashscope/v1/messages`)。支持 `type: "anthropic"`、`type: "openai-compatible"` 和 `type: "openai-responses"`。顶层客户端也可以在 `/v1/messages`、`/v1/messages/count_tokens`、`/v1/responses` 和 `/v1/chat/completions` 中使用 `model: "dashscope/model-id"`;AI gateway 会在转发上游前移除 `dashscope/` 前缀。`GET /v1/models` 不聚合 provider 模型;provider 模型列表请使用 `GET /dashscope/v1/models`。
237
+ - **providers:** 全局上游 provider 映射。每个 provider key(例如 `dashscope`)都会变成一个路由前缀(`/dashscope/v1/messages`)。支持 `type: "anthropic"`、`type: "openai-compatible"` 和 `type: "openai-responses"`。顶层客户端也可以在 `/v1/messages`、`/v1/messages/count_tokens`、`/v1/responses` 和 `/v1/chat/completions` 中使用 `model: "dashscope/model-id"`;AI gateway 会在转发上游前移除 `dashscope/` 前缀。`openai-compatible` provider 同时支持 chat 和 Messages 流程:`/v1/chat/completions` 会直连上游 `/v1/chat/completions`,而 `/v1/messages` 和 `/:provider/v1/messages` 会先翻译为上游 Chat Completions,再把响应翻译回 Anthropic Messages。`GET /v1/models` 不聚合 provider 模型;provider 模型列表请使用 `GET /dashscope/v1/models`。
230
238
  - `enabled`:可选,若省略则默认为 `true`。
231
239
  - `baseUrl`:provider API 的基础 URL,不要带结尾的 endpoint。Anthropic provider 不要带 `/v1/messages`;OpenAI 兼容 provider 不要带 `/v1/chat/completions`;OpenAI Responses provider 不要带 `/v1/responses`。
232
240
  - `apiKey`:作为上游凭据值使用;普通 provider 必须配置。
233
241
  - `authType`:可选,控制 `apiKey` 如何发送到上游。普通 provider 支持 `x-api-key` 和 `authorization`。Anthropic provider 默认 `x-api-key`;OpenAI 兼容和 OpenAI Responses provider 默认 `authorization`。当设置为 `authorization` 时,代理会发送 `Authorization: Bearer <apiKey>`。`oauth2` 仅保留给内置 `codex` provider,并由 `auth login --provider codex` 自动写入。
242
+ - `pricingCurrency`:可选,provider 维度的 token 费用币种,例如 `USD` 或 `CNY`。快捷 provider 默认 DashScope、DeepSeek 为 `CNY`,Codex/OpenRouter 为 `USD`。费用按币种分别汇总,不做汇率换算。
234
243
  - `models`:可选,按模型 ID 配置的映射。每个键为请求中的模型名,值支持:
235
244
  - `temperature`:可选,当请求未指定时使用的默认温度。
236
245
  - `topP`:可选,当请求未指定时使用的默认 `top_p`。
237
246
  - `topK`:可选,当请求未指定时使用的默认 `top_k`。
238
247
  - `extraBody`:可选,按模型合入上游请求体的动态字段;请求体显式同名字段优先。OpenAI 兼容 provider 可用它配置 `enable_thinking`、`preserve_thinking`、`reasoning_effort` 等字段。`thinking_budget` 是 OpenAI 兼容 provider 的特殊覆盖项:配置在 `extraBody` 后,会在 Anthropic `thinking.budget_tokens` 翻译之后强制写入,并覆盖请求派生出的预算值。
248
+ - `pricing`:可选,按模型配置 token 单价,币种使用 provider 的 `pricingCurrency`,单位为每 100 万 tokens。支持 `input`、`output`、`cachedInput`(隐式缓存读)、`explicitCachedInput`(显式缓存读)和 `cacheCreationInput`。如需按输入 token 总量分档,可用带 `maxInputTokens` 的 `tiers`。
239
249
  - `contextCache`:可选,OpenAI 兼容 provider 默认 `true`,用于启用阿里云百炼/DashScope 的显式缓存(explicit context cache),会按其 Context Cache 格式在最多 4 个 content block 上注入 `cache_control: { "type": "ephemeral" }`。缓存断点策略与 opencode 主链路保持一致:前 2 条 system 消息 + 最后 2 条非 system 消息。标记字符串 content 时会把 `system` / `user` / `assistant` / `tool` 消息转换为 text content part 数组;已有数组 content 则标记最后一个 part。如果模型本身已经支持隐式缓存,或上游不支持该显式缓存扩展字段,可在模型配置中设为 `false`。
240
250
  - `supportPdf`:可选,控制该模型是否支持 PDF/document content。默认 `false`,不支持时会把 PDF 转成提示文本;设为 `true` 时会把 PDF/document 转成 OpenAI Chat Completions 的 file part。
241
251
  - `toolContentSupportType`:可选,配置该模型的 tool result content 支持能力,值为 `array`、`image`、`pdf` 的数组。provider 侧未配置时默认只发送 string tool content。若 `supportPdf` 为 `true` 但这里不包含 `pdf`,tool result 里的 file part 会被转成 user role 消息。Copilot 主链路不使用这个 provider 默认,仍按 array + image 且不支持 PDF 的能力处理。
@@ -249,6 +259,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
249
259
  "enabled": true,
250
260
  "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode",
251
261
  "apiKey": "sk-your-dashscope-key",
262
+ "pricingCurrency": "CNY",
252
263
  "models": {
253
264
  "qwen3.6-plus": {
254
265
  "temperature": 1,
@@ -262,6 +273,26 @@ Copilot API 现在使用子命令结构,主要命令包括:
262
273
  "temperature": 0.7,
263
274
  "topP": 0.95,
264
275
  "contextCache": true,
276
+ "pricing": {
277
+ "tiers": [
278
+ {
279
+ "maxInputTokens": 32000,
280
+ "input": 6,
281
+ "cachedInput": 1.2,
282
+ "explicitCachedInput": 0.6,
283
+ "cacheCreationInput": 7.5,
284
+ "output": 24
285
+ },
286
+ {
287
+ "maxInputTokens": 200000,
288
+ "input": 8,
289
+ "cachedInput": 1.6,
290
+ "explicitCachedInput": 0.8,
291
+ "cacheCreationInput": 10,
292
+ "output": 28
293
+ }
294
+ ]
295
+ },
265
296
  "extraBody": {
266
297
  "preserve_thinking": true
267
298
  }
@@ -271,6 +302,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
271
302
  }
272
303
  }
273
304
  ```
305
+ 内置 token 价格覆盖 Codex GPT 模型(USD)、DashScope `qwen3.7-max`、`qwen3.7-plus`、`glm-5.1`、`glm-5.2`(CNY),以及 DeepSeek `deepseek-v4-flash`、`deepseek-v4-pro`、`deepseek-chat`、`deepseek-reasoner`(CNY)。用户配置的 `pricing` 优先于内置价格。DashScope 若上游 usage 中出现 `cache_creation_input_tokens` 字段,cached tokens 按显式缓存读价计费;否则 `cachedInput` 作为隐式缓存读价。DeepSeek 的 `prompt_cache_hit_tokens` 会归入 cached input,`prompt_cache_miss_tokens` 会归入普通 input。
274
306
  - **smallModel:** 无工具预热消息的回退模型(例如 Claude Code 的探测请求);默认是 `gpt-5-mini`。
275
307
  - **useResponsesApiContextManagement:** 当为 `true` 时,代理会为 Responses API 附加 `context_management` 压缩指令。默认值为 `true`。如需全局关闭,可设为 `false`。启用后,请求体会带上 `context_management`,并在后续轮次中仅保留最新的压缩承载内容,因此特别适合长任务场景。
276
308
  - **modelResponsesApiCompactThresholds:** 按模型覆盖 Responses API 的 `compact_threshold`,仅在代理自动附加 `context_management` 时使用。它的优先级高于 `resolveResponsesCompactThreshold` 基于 `max_prompt_tokens * ratio` 的兜底阈值。默认将 `gpt-5.4` 和 `gpt-5.5` 设为 `217600`(`272000 * 0.8`)。未列出的模型继续使用原有兜底逻辑。
@@ -310,7 +342,7 @@ curl http://localhost:4141/admin/config/model-mappings \
310
342
 
311
343
  ## API 端点
312
344
 
313
- 服务端提供多个端点来与 Copilot API 交互。它支持 OpenAI 兼容端点,也支持 Anthropic 兼容端点,因此可以更灵活地接入不同工具与服务。
345
+ 服务端提供多个 OpenAI / Anthropic 兼容端点。请求会根据所选模型和 `provider/model` 别名路由到 GitHub Copilot、内置 `codex` provider 或已配置的 provider。
314
346
 
315
347
  ### OpenAI 兼容端点
316
348
 
@@ -319,7 +351,7 @@ curl http://localhost:4141/admin/config/model-mappings \
319
351
  | 端点 | 方法 | 说明 |
320
352
  | --- | --- | --- |
321
353
  | `POST /v1/responses` | `POST` | OpenAI 中用于生成模型响应的高级接口。支持 `openai-responses` provider 的 `provider/model` 别名。 |
322
- | `POST /v1/chat/completions` | `POST` | 为给定聊天对话创建模型响应。支持 `openai-compatible` provider 的 `provider/model` 别名。 |
354
+ | `POST /v1/chat/completions` | `POST` | 为给定聊天对话创建模型响应。支持 `openai-compatible` provider 的 `provider/model` 别名;目标 provider 已配置时可在没有 Copilot 的情况下使用。 |
323
355
  | `GET /v1/models` | `GET` | 列出当前可用模型。 |
324
356
  | `POST /v1/embeddings` | `POST` | 创建表示输入文本的向量嵌入。 |
325
357
 
@@ -329,9 +361,9 @@ curl http://localhost:4141/admin/config/model-mappings \
329
361
 
330
362
  | 端点 | 方法 | 说明 |
331
363
  | --- | --- | --- |
332
- | `POST /v1/messages` | `POST` | 为给定对话创建模型响应。支持已配置 provider 的 `provider/model` 别名。 |
364
+ | `POST /v1/messages` | `POST` | 为给定对话创建模型响应。支持已配置 provider 的 `provider/model` 别名,包括通过 `openai-compatible` provider 做翻译。 |
333
365
  | `POST /v1/messages/count_tokens` | `POST` | 计算一组消息的 token 数。支持已配置 provider 的 `provider/model` 别名。 |
334
- | `POST /:provider/v1/messages` | `POST` | 将 Anthropic Messages 请求代理到已配置的 AnthropicOpenAI 兼容或 OpenAI Responses provider。 |
366
+ | `POST /:provider/v1/messages` | `POST` | 将 Anthropic Messages 请求代理到已配置的 Anthropic provider,或翻译到 OpenAI 兼容 / OpenAI Responses provider。 |
335
367
  | `GET /:provider/v1/models` | `GET` | 将模型列表请求代理到已配置的 provider。 |
336
368
  | `POST /:provider/v1/messages/count_tokens` | `POST` | 为 provider 路由请求在本地计算 token 数。 |
337
369
 
@@ -367,8 +399,9 @@ npx @jeffreycao/copilot-api@latest start --port 8080 --verbose
367
399
  # 执行认证流程
368
400
  npx @jeffreycao/copilot-api@latest auth login
369
401
 
370
- # 在终端中查看 Copilot 用量与额度(无需启动服务)
371
- npx @jeffreycao/copilot-api@latest check-usage
402
+ # 配置第三方 provider,然后不依赖 GitHub Copilot 启动
403
+ npx @jeffreycao/copilot-api@latest auth login --provider dashscope
404
+ npx @jeffreycao/copilot-api@latest start
372
405
 
373
406
  # 以 JSON 格式输出调试信息
374
407
  npx @jeffreycao/copilot-api@latest debug --json
@@ -377,6 +410,18 @@ npx @jeffreycao/copilot-api@latest debug --json
377
410
  bunx --bun @jeffreycao/copilot-api@latest start
378
411
  ```
379
412
 
413
+ 配置 `dashscope` 后的 OpenAI 兼容 provider 调用示例:
414
+
415
+ ```sh
416
+ curl http://localhost:4141/v1/chat/completions \
417
+ -H "content-type: application/json" \
418
+ -d '{"model":"dashscope/qwen3.6-plus","messages":[{"role":"user","content":"hello"}]}'
419
+
420
+ curl http://localhost:4141/dashscope/v1/messages \
421
+ -H "content-type: application/json" \
422
+ -d '{"model":"qwen3.6-plus","max_tokens":1024,"messages":[{"role":"user","content":"hello"}]}'
423
+ ```
424
+
380
425
  ## 与 Claude Code 一起使用
381
426
 
382
427
  这个 AI gateway 可以为 [Claude Code](https://docs.anthropic.com/en/claude-code) 提供后端能力。Claude Code 是 Anthropic 提供的实验性面向开发者的对话式 AI 助手。
@@ -416,8 +461,7 @@ npx @jeffreycao/copilot-api@latest start --claude-code
416
461
  "CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
417
462
  "CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
418
463
  "CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
419
- "CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
420
- "CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
464
+ "CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0"
421
465
  },
422
466
  "permissions": {
423
467
  "deny": [
@@ -718,7 +762,6 @@ bun run start start
718
762
  - `--manual`:为每个请求启用手动审批,让你完全控制何时发送请求。
719
763
  - `--rate-limit <seconds>`:强制请求之间至少保持一定秒数的间隔。例如 `copilot-api start --rate-limit 30` 会确保两次请求之间至少间隔 30 秒。
720
764
  - `--wait`:与 `--rate-limit` 配合使用。在命中速率限制时,服务会等待冷却结束,而不是直接返回错误。对于不会自动重试的客户端,这会很有帮助。
721
- - 如果你使用的是 GitHub Business 或 Enterprise 版 Copilot 账号,请使用 `--account-type` 参数(例如 `--account-type business`)。详见 [官方文档](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)。
722
765
 
723
766
  <a id="claudemd-or-agentsmd-recommended-content"></a>
724
767
 
@@ -0,0 +1,2 @@
1
+ import { t as auth } from "./auth-DcYySZhC.js";
2
+ export { auth };
@@ -1,5 +1,5 @@
1
- import { E as ensurePaths, T as PATHS, t as SUPPORTED_PROVIDER_TYPES, u as getRawProviderConfig, v as isSupportedProviderType, w as setProviderConfig, x as normalizeProviderBaseUrl } from "./config-B71_S_hQ.js";
2
- import { A as loginCodex, L as state, a as setupGitHubToken, n as persistCodexCredentials } from "./token-fpw8tAQS.js";
1
+ import { E as ensurePaths, T as PATHS, t as SUPPORTED_PROVIDER_TYPES, u as getRawProviderConfig, v as isSupportedProviderType, w as setProviderConfig, x as normalizeProviderBaseUrl } from "./config-CQxppJtD.js";
2
+ import { R as state, a as setupGitHubToken, j as loginCodex, n as persistCodexCredentials } from "./token-CFArcYwb.js";
3
3
  import { defineCommand } from "citty";
4
4
  import consola from "consola";
5
5
  //#region src/auth.ts
@@ -25,16 +25,19 @@ const QUICK_PROVIDER_CONFIGS = {
25
25
  deepseek: {
26
26
  type: "openai-compatible",
27
27
  baseUrl: "https://api.deepseek.com",
28
+ pricingCurrency: "CNY",
28
29
  editableType: true
29
30
  },
30
31
  dashscope: {
31
32
  type: "openai-compatible",
32
33
  baseUrl: "https://dashscope.aliyuncs.com/compatible-mode",
34
+ pricingCurrency: "CNY",
33
35
  editableType: true
34
36
  },
35
37
  openrouter: {
36
38
  type: "anthropic",
37
39
  baseUrl: "https://openrouter.ai/api",
40
+ pricingCurrency: "USD",
38
41
  editableType: false
39
42
  }
40
43
  };
@@ -222,6 +225,7 @@ function buildCustomProviderConfig(existingProviderConfig, options) {
222
225
  baseUrl: options.baseUrl,
223
226
  apiKey: options.apiKey,
224
227
  ...options.authType ? { authType: options.authType } : {},
228
+ pricingCurrency: options.pricingCurrency ?? existingProviderConfig.pricingCurrency,
225
229
  ...existingProviderConfig.models ? { models: existingProviderConfig.models } : {}
226
230
  };
227
231
  }
@@ -248,6 +252,7 @@ async function configureQuickProvider(providerName) {
248
252
  setProviderConfig(providerName, buildCustomProviderConfig(getRawProviderConfig(providerName) ?? {}, {
249
253
  apiKey,
250
254
  baseUrl,
255
+ pricingCurrency: defaultProviderConfig.pricingCurrency,
251
256
  type
252
257
  }));
253
258
  consola.success(`${AUTH_PROVIDER_LABELS[providerName]} provider '${providerName}' written to ${PATHS.CONFIG_PATH}`);
@@ -284,6 +289,11 @@ async function loginWithProvider(provider) {
284
289
  }
285
290
  await configureCustomProvider();
286
291
  }
292
+ async function runProviderSetup() {
293
+ const provider = await resolveProviderSelection(void 0);
294
+ consola.info(`Logging in with ${AUTH_PROVIDER_LABELS[provider]}`);
295
+ await loginWithProvider(provider);
296
+ }
287
297
  async function runAuthLogin(options) {
288
298
  (await import("./tls-BniQ6Rel.js")).enableSystemCACompat();
289
299
  if (options.verbose) {
@@ -326,6 +336,6 @@ const auth = defineCommand({
326
336
  }
327
337
  });
328
338
  //#endregion
329
- export { auth };
339
+ export { runAuthLogin as n, runProviderSetup as r, auth as t };
330
340
 
331
- //# sourceMappingURL=auth-15xzL-eW.js.map
341
+ //# sourceMappingURL=auth-DcYySZhC.js.map