@nick3/copilot-api 1.9.2 → 1.10.4
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 +114 -89
- package/README.zh-CN.md +114 -86
- package/dist/{account-MllYSdRC.js → account-COtMmvzU.js} +20 -24
- package/dist/account-COtMmvzU.js.map +1 -0
- package/dist/admin/assets/index-CBMFCvqO.css +1 -0
- package/dist/admin/assets/index-DG4TRVMu.js +110 -0
- package/dist/admin/index.html +2 -2
- package/dist/{auth-DZoQA-kn.js → auth-B0y-2njL.js} +103 -112
- package/dist/auth-B0y-2njL.js.map +1 -0
- package/dist/{check-usage-DEbsehjH.js → check-usage-DdevqHE5.js} +6 -7
- package/dist/{check-usage-DEbsehjH.js.map → check-usage-DdevqHE5.js.map} +1 -1
- package/dist/{debug-BJfZVBB7.js → debug-BMo6ltbp.js} +6 -6
- package/dist/debug-BMo6ltbp.js.map +1 -0
- package/dist/{get-copilot-token-4mCKt94e.js → get-copilot-token-8Rm-rVsp.js} +3 -4
- package/dist/{get-copilot-token-4mCKt94e.js.map → get-copilot-token-8Rm-rVsp.js.map} +1 -1
- package/dist/main.js +6 -7
- package/dist/main.js.map +1 -1
- package/dist/{paths-DGlr310R.js → paths-CclKwouX.js} +3 -5
- package/dist/{paths-DGlr310R.js.map → paths-CclKwouX.js.map} +1 -1
- package/dist/{poll-access-token-Dvk6Ho0R.js → poll-access-token-BAgM2-7k.js} +65 -21
- package/dist/poll-access-token-BAgM2-7k.js.map +1 -0
- package/dist/{accounts-manager-BM66oT38.js → proxy-BwmADhKh.js} +494 -52
- package/dist/proxy-BwmADhKh.js.map +1 -0
- package/dist/request-outbound-BJjWS_jF.js +2 -0
- package/dist/{request-outbound-qyTeXbzy.js → request-outbound-Pu1kp2x8.js} +16 -9
- package/dist/request-outbound-Pu1kp2x8.js.map +1 -0
- package/dist/{server-DR9ZR_MN.js → server-DxQsi1x2.js} +2106 -935
- package/dist/server-DxQsi1x2.js.map +1 -0
- package/dist/{start-DDhYUFQR.js → start-8QHzPrcg.js} +11 -60
- package/dist/start-8QHzPrcg.js.map +1 -0
- package/package.json +20 -7
- package/dist/account-MllYSdRC.js.map +0 -1
- package/dist/accounts-manager-BM66oT38.js.map +0 -1
- package/dist/admin/assets/index-8eGib92I.js +0 -107
- package/dist/admin/assets/index-B2qj1asn.css +0 -1
- package/dist/auth-DZoQA-kn.js.map +0 -1
- package/dist/debug-BJfZVBB7.js.map +0 -1
- package/dist/poll-access-token-Dvk6Ho0R.js.map +0 -1
- package/dist/request-outbound-DhI9-SrV.js +0 -4
- package/dist/request-outbound-qyTeXbzy.js.map +0 -1
- package/dist/server-DR9ZR_MN.js.map +0 -1
- package/dist/start-DDhYUFQR.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,11 +21,6 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
21
21
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
|
-
> [!NOTE]
|
|
25
|
-
> [opencode](https://github.com/sst/opencode) already ships with a built-in GitHub Copilot provider, so you may not need this project for basic usage. This proxy is still useful if you want OpenCode to talk to Copilot through `@ai-sdk/anthropic`, preserve Anthropic Messages semantics for tool use, prefer the native Messages API over Chat Completions API for Claude-family models, use gpt phase-aware commentary, or optimize premium requests.
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
24
|
## Important Notes
|
|
30
25
|
|
|
31
26
|
> [!IMPORTANT]
|
|
@@ -69,7 +64,7 @@ Compared with routing everything through plain Chat Completions compatibility, t
|
|
|
69
64
|
- **Opencode OAuth Support**: Use opencode GitHub Copilot authentication by setting `COPILOT_API_OAUTH_APP=opencode` environment variable or using `--oauth-app=opencode` command line option.
|
|
70
65
|
- **GitHub Enterprise Support**: Connect to GHE.com by setting `COPILOT_API_ENTERPRISE_URL` environment variable (e.g., `company.ghe.com`) or using `--enterprise-url=company.ghe.com` command line option.
|
|
71
66
|
- **Custom Data Directory**: Change the default data directory (where tokens and config are stored) by setting `COPILOT_API_HOME` environment variable or using `--api-home=/path/to/dir` command line option.
|
|
72
|
-
- **Multi-Provider
|
|
67
|
+
- **Multi-Provider Messages Proxy Routes**: Add global provider configs and call external Anthropic-compatible or OpenAI-compatible APIs via `/:provider/v1/messages` and `/:provider/v1/models`, or send `model: "provider/model"` to the top-level `/v1/messages` API.
|
|
73
68
|
- **Accurate Claude Token Counting**: Optionally forward `/v1/messages/count_tokens` requests for Claude models to Anthropic's free token counting endpoint for exact counts instead of GPT tokenizer estimation.
|
|
74
69
|
- **GPT Context Management**: Configurable context compaction for long-running GPT conversations via `responsesApiContextManagementModels`, reducing unnecessary premium requests when approaching token limits. See [Configuration](#configuration-configjson) for details.
|
|
75
70
|
|
|
@@ -131,6 +126,7 @@ When an Anthropic API key is configured, the proxy forwards Claude model token c
|
|
|
131
126
|
## Prerequisites
|
|
132
127
|
|
|
133
128
|
- Bun (>= 1.2.x)
|
|
129
|
+
- Node.js if you plan to run the published CLI with `npx`
|
|
134
130
|
- GitHub account with Copilot subscription (individual, business, or enterprise)
|
|
135
131
|
|
|
136
132
|
## Installation
|
|
@@ -324,7 +320,7 @@ The `auth` command has three subcommands for managing multiple accounts:
|
|
|
324
320
|
| --force | Skip confirmation prompt | false | -f |
|
|
325
321
|
| --verbose | Enable verbose logging | false | -v |
|
|
326
322
|
|
|
327
|
-
The `<target>` can be either the account ID (GitHub
|
|
323
|
+
The `<target>` can be either the account ID (GitHub login) or a 1-based index.
|
|
328
324
|
|
|
329
325
|
### Debug Command Options
|
|
330
326
|
|
|
@@ -365,6 +361,7 @@ The `<target>` can be either the account ID (GitHub username) or a 1-based index
|
|
|
365
361
|
"modelRefreshIntervalHours": 24,
|
|
366
362
|
"sessionAffinityRetentionDays": 7,
|
|
367
363
|
"useMessagesApi": true,
|
|
364
|
+
"useResponsesApiWebSocket": true,
|
|
368
365
|
"useResponsesApiWebSearch": true,
|
|
369
366
|
"logLevel": "info"
|
|
370
367
|
}
|
|
@@ -400,16 +397,54 @@ The `<target>` can be either the account ID (GitHub username) or a 1-based index
|
|
|
400
397
|
"topP": 0.95
|
|
401
398
|
}
|
|
402
399
|
}
|
|
400
|
+
},
|
|
401
|
+
"dashscope": {
|
|
402
|
+
"type": "openai-compatible",
|
|
403
|
+
"enabled": true,
|
|
404
|
+
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode",
|
|
405
|
+
"apiKey": "sk-your-dashscope-key",
|
|
406
|
+
"models": {
|
|
407
|
+
"qwen3.6-plus": {
|
|
408
|
+
"temperature": 1,
|
|
409
|
+
"topP": 0.95,
|
|
410
|
+
"topK": 20,
|
|
411
|
+
"extraBody": {
|
|
412
|
+
"preserve_thinking": true
|
|
413
|
+
},
|
|
414
|
+
"contextCache": true
|
|
415
|
+
},
|
|
416
|
+
"glm-5.1": {
|
|
417
|
+
"temperature": 0.7,
|
|
418
|
+
"topP": 0.95,
|
|
419
|
+
"contextCache": true,
|
|
420
|
+
"extraBody": {
|
|
421
|
+
"preserve_thinking": true
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
403
425
|
}
|
|
404
426
|
}
|
|
405
427
|
}
|
|
406
428
|
```
|
|
407
|
-
- **
|
|
429
|
+
- **providers:** Global upstream provider map. Each provider key (for example `custom`) becomes a route prefix (`/custom/v1/messages`). Supports `type: "anthropic"` and `type: "openai-compatible"`. Top-level Anthropic clients can also use `model: "custom/model-id"` with `/v1/messages` and `/v1/messages/count_tokens`; the proxy strips the `custom/` prefix before forwarding upstream. `GET /v1/models` does not aggregate provider models; use `GET /custom/v1/models` for provider model lists.
|
|
430
|
+
- `enabled` defaults to `true` if omitted.
|
|
431
|
+
- `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`.
|
|
432
|
+
- `apiKey` is used as the upstream credential value.
|
|
433
|
+
- `authType` (optional): Controls how `apiKey` is sent upstream. Supports `x-api-key` and `authorization`. Anthropic providers default to `x-api-key`; OpenAI-compatible providers default to `authorization`. When set to `authorization`, the proxy sends `Authorization: Bearer <apiKey>`.
|
|
434
|
+
- `adjustInputTokens` (optional): When `true`, the proxy will adjust the `input_tokens` in the usage response by subtracting `cache_read_input_tokens` and `cache_creation_input_tokens`.
|
|
435
|
+
- `models` (optional): Per-model configuration map. Each key is a model ID (matching the model name in requests), and the value is:
|
|
436
|
+
- `temperature` (optional): Default temperature value used when the request does not specify one.
|
|
437
|
+
- `topP` (optional): Default top_p value used when the request does not specify one.
|
|
438
|
+
- `topK` (optional): Default top_k value used when the request does not specify one.
|
|
439
|
+
- `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`.
|
|
440
|
+
- `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.
|
|
441
|
+
- `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.
|
|
442
|
+
- `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.
|
|
443
|
+
- **responsesApiContextManagementModels:** List of GPT model IDs that should receive Responses API `context_management` compaction instructions. Defaults to `[]`, so you need to opt in explicitly. A good starting point is `["gpt-5-mini", "gpt-5.3-codex", "gpt-5.4-mini", "gpt-5.4"]`. When enabled, the request includes `context_management` in the body and keeps only the latest compaction carrier on follow-up turns. Server-side compaction appears to begin when usage approaches roughly 90% of the model's `maxPromptTokens`, making it useful for long-running GPT-family tasks without additional premium requests.
|
|
408
444
|
- **smallModel:** Fallback model used for tool-less warmup messages, compact/background requests, and other short housekeeping turns (for example from Claude Code or OpenCode) to avoid spending premium requests; defaults to `gpt-5-mini`. If original names are blocked and this points to an aliased target, it resolves to the preferred alias.
|
|
409
445
|
- **accountAffinity:** Enable sticky account routing based on session identity. When enabled, requests from the same session for the same model are routed to the account that last handled them successfully. Applies to both free and premium models. Defaults to `true`. Set to `false` to use sequential routing for all models.
|
|
410
|
-
- **apiKey (deprecated):** Legacy single-key field kept for migration compatibility. Prefer `auth.apiKeys`. When `auth.apiKeys` is empty, the server falls back to `COPILOT_API_KEY` and then `apiKey`.
|
|
411
|
-
- **
|
|
412
|
-
- **modelAliases:** Map of `alias -> { target, allowOriginal? }` (legacy string values are still accepted). Alias keys are normalized (trim + lowercase) and must be non-empty; aliases cannot map to themselves (case-insensitive), and conflicting normalized aliases are rejected. `allowOriginal` overrides the global default per alias. If multiple aliases map to the same target, original names are allowed when any alias sets `allowOriginal: true` (allow-wins). Admin UI/API rejects blocked keys (`__proto__`, `constructor`, `prototype`). Aliases can be used in downstream requests.
|
|
446
|
+
- **apiKey (deprecated):** Legacy single-key field kept for migration compatibility. Prefer `auth.apiKeys`. When `auth.apiKeys` is empty, the server falls back to `COPILOT_API_KEY` and then `apiKey`.- **modelReasoningEfforts:** Per-model `reasoning.effort` sent to the Copilot Responses API. Allowed values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`. If a model isn’t listed, `high` is used by default.
|
|
447
|
+
- **modelAliases:** Map of `alias -> { target, allowOriginal? }` (legacy string values are still accepted). Alias keys are normalized (trim + lowercase) and must be non-empty; aliases cannot map to themselves (case-insensitive), and conflicting normalized aliases are rejected. `allowOriginal` overrides the global default per alias. If multiple aliases map to the same target, original names are allowed when any alias sets `allowOriginal: true` (allow-wins). Admin UI/API rejects blocked keys (`__proto__`, `constructor`, `prototype`). Aliases can be used in downstream requests, and targets may be configured `provider/model` aliases for top-level `/v1/messages` and `/v1/messages/count_tokens` routing.
|
|
413
448
|
- **allowOriginalModelNamesForAliases:** Global default for aliases that omit `allowOriginal`. When `false` (default), targets are blocked unless an alias explicitly allows them; when `true`, targets are allowed unless all aliases explicitly block them.
|
|
414
449
|
- **useFunctionApplyPatch:** When `true` (default), `POST /v1/responses` converts a `tools` entry with `{ "type": "custom", "name": "apply_patch" }` into an OpenAI-style `function` tool (with a parameter schema) for upstream compatibility. Set to `false` to leave custom tools untouched.
|
|
415
450
|
- **forceAgent:** When `true`, `POST /v1/responses` treats a request as agent-initiated if **any** input item has `role: "assistant"`. When `false` (default), only the **last** input item is checked.
|
|
@@ -418,6 +453,7 @@ The `<target>` can be either the account ID (GitHub username) or a 1-based index
|
|
|
418
453
|
- **modelRefreshIntervalHours:** Interval for refreshing account model lists in the background. Set to `0` to disable refresh. Defaults to `24`.
|
|
419
454
|
- **sessionAffinityRetentionDays:** Number of days to retain session affinity bindings. Defaults to `7`.
|
|
420
455
|
- **useMessagesApi:** When `true` (default), Claude-family models that support Copilot's native `/v1/messages` endpoint may use the Messages API path. Set to `false` to skip the Messages API candidate and fall back to `/responses` (if supported) or `/chat/completions`.
|
|
456
|
+
- **useResponsesApiWebSocket:** When `true` (default), Responses API requests use Copilot's WebSocket transport for models that advertise `ws:/responses`; models that only advertise `/responses` continue to use HTTP. Set to `false` to disable WebSocket routing.
|
|
421
457
|
- **useResponsesApiWebSearch:** When `true` (default), `/v1/responses` keeps tools with `type: "web_search"` and forwards them upstream. Set to `false` to strip them before the Copilot request is sent.
|
|
422
458
|
- **logLevel:** Controls handler file-log verbosity under `logs/*.log`. Allowed values: `error`, `warn`, `info`, `debug`. Defaults to `info`. Set it to `debug` when you need payload- or stream-level diagnostics written into file logs.
|
|
423
459
|
- **anthropicApiKey:** Optional Anthropic API key used for accurate Claude token counting (see [Accurate Claude Token Counting](#accurate-claude-token-counting) below). Can also be set via the `ANTHROPIC_API_KEY` environment variable. If not set, token counting falls back to GPT tokenizer estimation.
|
|
@@ -465,10 +501,10 @@ These endpoints are designed to be compatible with the Anthropic Messages API.
|
|
|
465
501
|
|
|
466
502
|
| Endpoint | Method | Description |
|
|
467
503
|
| -------------------------------- | ------ | ------------------------------------------------------------ |
|
|
468
|
-
| `POST /v1/messages` | `POST` | Creates a model response for a given conversation.
|
|
469
|
-
| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. |
|
|
470
|
-
| `POST /:provider/v1/messages` | `POST` | Proxies Anthropic Messages
|
|
471
|
-
| `GET /:provider/v1/models` | `GET` | Proxies
|
|
504
|
+
| `POST /v1/messages` | `POST` | Creates a model response for a given conversation. Supports `provider/model` aliases for configured providers. |
|
|
505
|
+
| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. Supports `provider/model` aliases for configured providers. |
|
|
506
|
+
| `POST /:provider/v1/messages` | `POST` | Proxies Anthropic Messages requests to the configured Anthropic or OpenAI-compatible provider. |
|
|
507
|
+
| `GET /:provider/v1/models` | `GET` | Proxies model listing requests to the configured provider. |
|
|
472
508
|
| `POST /:provider/v1/messages/count_tokens` | `POST` | Calculates tokens locally for provider route requests. |
|
|
473
509
|
|
|
474
510
|
### Usage Monitoring Endpoints
|
|
@@ -582,7 +618,7 @@ npx @nick3/copilot-api@latest auth ls -q
|
|
|
582
618
|
# Remove an account by index (1-based)
|
|
583
619
|
npx @nick3/copilot-api@latest auth rm 2
|
|
584
620
|
|
|
585
|
-
# Remove an account by ID (GitHub
|
|
621
|
+
# Remove an account by ID (GitHub login)
|
|
586
622
|
npx @nick3/copilot-api@latest auth rm octocat
|
|
587
623
|
|
|
588
624
|
# Show your Copilot usage/quota in the terminal (no server needed)
|
|
@@ -611,6 +647,9 @@ npx @nick3/copilot-api@latest --oauth-app=opencode start
|
|
|
611
647
|
|
|
612
648
|
# Combine multiple global options
|
|
613
649
|
npx @nick3/copilot-api@latest --api-home=/custom/path --oauth-app=opencode --enterprise-url=company.ghe.com start
|
|
650
|
+
|
|
651
|
+
# Run the published CLI with Bun instead of Node.js
|
|
652
|
+
bunx --bun @nick3/copilot-api@latest start
|
|
614
653
|
```
|
|
615
654
|
|
|
616
655
|
### Opencode OAuth Authentication
|
|
@@ -632,6 +671,65 @@ Or use inline environment variable:
|
|
|
632
671
|
COPILOT_API_OAUTH_APP=opencode npx @nick3/copilot-api@latest start
|
|
633
672
|
```
|
|
634
673
|
|
|
674
|
+
## Using with Claude Code
|
|
675
|
+
|
|
676
|
+
This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
|
|
677
|
+
|
|
678
|
+
There are two ways to configure Claude Code to use this proxy:
|
|
679
|
+
|
|
680
|
+
### Interactive Setup with `--claude-code` flag
|
|
681
|
+
|
|
682
|
+
To get started, run the `start` command with the `--claude-code` flag:
|
|
683
|
+
|
|
684
|
+
```sh
|
|
685
|
+
npx @nick3/copilot-api@latest start --claude-code
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
You will be prompted to select a primary model and a "small, fast" model for background tasks. After selecting the models, a command will be copied to your clipboard. This command sets the necessary environment variables for Claude Code to use the proxy.
|
|
689
|
+
|
|
690
|
+
Paste and run this command in a new terminal to launch Claude Code.
|
|
691
|
+
|
|
692
|
+
### Manual Configuration with `settings.json`
|
|
693
|
+
|
|
694
|
+
Alternatively, you can configure Claude Code by creating a `.claude/settings.json` file in your project's root directory. This file should contain the environment variables needed by Claude Code. This way you don't need to run the interactive setup every time.
|
|
695
|
+
|
|
696
|
+
Here is an example `.claude/settings.json` file:
|
|
697
|
+
|
|
698
|
+
```json
|
|
699
|
+
{
|
|
700
|
+
"env": {
|
|
701
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
702
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
703
|
+
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
704
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
705
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
706
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
707
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
708
|
+
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
709
|
+
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
710
|
+
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
711
|
+
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
712
|
+
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
713
|
+
},
|
|
714
|
+
"permissions": {
|
|
715
|
+
"deny": [
|
|
716
|
+
"WebSearch",
|
|
717
|
+
"mcp__ide__executeCode"
|
|
718
|
+
]
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
- Replace `ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL` according to your needs. After configuration, please install the claude code plugin [Plugin Integrations](#plugin-integrations). If configuring the claude model, it is recommended to set all model configurations the same, so as to remain consistent with github-copilot claude agent behavior.
|
|
724
|
+
- Setting CLAUDE_CODE_ATTRIBUTION_HEADER to 0 can prevent Claude code from adding billing and version information in system prompts, thereby avoiding prompt cache invalidation.
|
|
725
|
+
- Turning off CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION and CLAUDE_CODE_ENABLE_AWAY_SUMMARY can prevent quota from being consumed unnecessarily.
|
|
726
|
+
- Permissions deny WebSearch because the GitHub Copilot API does not support natie websearch (some gpt models support websearch, but the current project has not adapted websearch); it is recommended to install the mcp mcp_server_fetch tool or other search tools as alternatives..
|
|
727
|
+
- If using a non-Claude model, do not enable ENABLE_TOOL_SEARCH. If using the Claude model, can enable ENABLE_TOOL_SEARCH. The current Claude Code uses the client tool search mode. In this mode, loading defer tools requires an additional request each time.
|
|
728
|
+
|
|
729
|
+
You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
730
|
+
|
|
731
|
+
You can also read more about IDE integration here: [Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
732
|
+
|
|
635
733
|
## Using with OpenCode
|
|
636
734
|
|
|
637
735
|
OpenCode already has a direct GitHub Copilot provider. Use this section when you want OpenCode to point at this proxy through `@ai-sdk/anthropic` and reuse the agent behaviors described earlier in this README.
|
|
@@ -787,79 +885,6 @@ If you see:
|
|
|
787
885
|
- Windows: `%USERPROFILE%\.local\share\copilot-api\admin.sqlite`
|
|
788
886
|
- By default, the proxy keeps up to 14 days of logs and caps the DB at 200,000 rows (older entries are cleaned up automatically).
|
|
789
887
|
- For safety, the admin DB stores metadata only (no GitHub/Copilot tokens and no request/response content).
|
|
790
|
-
|
|
791
|
-
## Using with Claude Code
|
|
792
|
-
|
|
793
|
-
This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
|
|
794
|
-
|
|
795
|
-
There are two ways to configure Claude Code to use this proxy:
|
|
796
|
-
|
|
797
|
-
### Interactive Setup with `--claude-code` flag
|
|
798
|
-
|
|
799
|
-
To get started, run the `start` command with the `--claude-code` flag:
|
|
800
|
-
|
|
801
|
-
```sh
|
|
802
|
-
npx @nick3/copilot-api@latest start --claude-code
|
|
803
|
-
```
|
|
804
|
-
|
|
805
|
-
You will be prompted to select a primary model and a "small, fast" model for background tasks. After selecting the models, a command will be copied to your clipboard. This command sets the necessary environment variables for Claude Code to use the proxy.
|
|
806
|
-
|
|
807
|
-
Paste and run this command in a new terminal to launch Claude Code.
|
|
808
|
-
|
|
809
|
-
> **API Key note:** If request authentication is enabled (prefer `auth.apiKeys`; legacy `COPILOT_API_KEY`/`apiKey` also works), set `ANTHROPIC_AUTH_TOKEN` to one of the configured API keys.
|
|
810
|
-
|
|
811
|
-
### Manual Configuration with `settings.json`
|
|
812
|
-
|
|
813
|
-
Alternatively, you can configure Claude Code by creating a `.claude/settings.json` file in your project's root directory. This file should contain the environment variables needed by Claude Code. This way you don't need to run the interactive setup every time.
|
|
814
|
-
|
|
815
|
-
Here is an example `.claude/settings.json` file:
|
|
816
|
-
|
|
817
|
-
> **API Key note:** If request authentication is enabled, set `ANTHROPIC_AUTH_TOKEN` to one of your API keys so Claude Code can send `x-api-key`. If not enabled, any value works.
|
|
818
|
-
|
|
819
|
-
```json
|
|
820
|
-
{
|
|
821
|
-
"env": {
|
|
822
|
-
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
823
|
-
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
824
|
-
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
825
|
-
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
826
|
-
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
827
|
-
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
828
|
-
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
829
|
-
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
830
|
-
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
831
|
-
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
832
|
-
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
833
|
-
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
834
|
-
},
|
|
835
|
-
"permissions": {
|
|
836
|
-
"deny": [
|
|
837
|
-
"WebSearch",
|
|
838
|
-
"mcp__ide__executeCode"
|
|
839
|
-
]
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
```
|
|
843
|
-
|
|
844
|
-
- Replace `ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL` according to your needs. After configuration, please install the claude code plugin [Plugin Integrations](#plugin-integrations). If configuring the claude model, it is recommended to set all model configurations the same, so as to remain consistent with github-copilot claude agent behavior.
|
|
845
|
-
- Setting CLAUDE_CODE_ATTRIBUTION_HEADER to 0 can prevent Claude code from adding billing and version information in system prompts, thereby avoiding prompt cache invalidation.
|
|
846
|
-
- Turning off `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION` and `CLAUDE_CODE_ENABLE_AWAY_SUMMARY` can prevent quota from being consumed unnecessarily.
|
|
847
|
-
- Permissions deny `WebSearch` because the GitHub Copilot API does not currently support native web search in this project. You can keep `WebSearch` denied in Claude Code permissions or set `useResponsesApiWebSearch` to `false` in `config.json`. If you need search, use an alternative tool such as `mcp_server_fetch`.
|
|
848
|
-
- Please do not enable `ENABLE_TOOL_SEARCH`, as the current Claude Code uses the client tool search mode. In this mode, loading deferred tools requires an additional request each time, cache hit rates are affected, and it does not necessarily save tokens. Only server-side tool search can potentially save tokens. The current project still has compatibility issues with client tool search mode, which can also cause errors when used.
|
|
849
|
-
|
|
850
|
-
### CLAUDE.md or AGENTS.md Recommended Content
|
|
851
|
-
|
|
852
|
-
To add these reminders manually, include the following in `CLAUDE.md` for Claude Code, or `AGENTS.md` for opencode/codex:
|
|
853
|
-
|
|
854
|
-
```
|
|
855
|
-
- Prohibited from directly asking questions to users, MUST use question tool.
|
|
856
|
-
- Once you can confirm that the task is complete, MUST use question tool to make user confirm. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again, after try again, MUST use question tool to make user confirm again.
|
|
857
|
-
```
|
|
858
|
-
|
|
859
|
-
You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
860
|
-
|
|
861
|
-
You can also read more about IDE integration here: [Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
862
|
-
|
|
863
888
|
## Plugin Integrations
|
|
864
889
|
|
|
865
890
|
Plugin integrations are available for Claude Code and opencode.
|
package/README.zh-CN.md
CHANGED
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
- **支持 opencode OAuth**:可通过设置环境变量 `COPILOT_API_OAUTH_APP=opencode` 或使用命令行参数 `--oauth-app=opencode` 来启用 opencode GitHub Copilot 认证。
|
|
70
70
|
- **支持 GitHub Enterprise**:可通过设置环境变量 `COPILOT_API_ENTERPRISE_URL`(例如 `company.ghe.com`)或命令行参数 `--enterprise-url=company.ghe.com` 连接到 GHE.com。
|
|
71
71
|
- **自定义数据目录**:可通过环境变量 `COPILOT_API_HOME` 或命令行参数 `--api-home=/path/to/dir` 修改默认数据目录(存放 token 和配置)。
|
|
72
|
-
- **多 Provider
|
|
72
|
+
- **多 Provider Messages 代理路由**:可以添加全局 provider 配置,并通过 `/:provider/v1/messages` 与 `/:provider/v1/models` 调用外部 Anthropic 或 OpenAI 兼容 API,也可以把 `model` 写成 `"provider/model"` 后直接发到顶层 `/v1/messages`。
|
|
73
73
|
- **精确的 Claude Token 计数**:可以选择将 Claude 模型的 `/v1/messages/count_tokens` 请求转发到 Anthropic 的免费 token counting 端点,以获得精确计数,而不是依赖 GPT tokenizer 估算。
|
|
74
74
|
- **GPT 上下文管理**:可通过 `responsesApiContextManagementModels` 为长上下文 GPT 对话启用可配置的上下文压缩,在接近 token 限制时减少不必要的 Premium 请求。详见 [配置](#configuration-configjson)。
|
|
75
75
|
|
|
@@ -133,6 +133,7 @@
|
|
|
133
133
|
## 前置要求
|
|
134
134
|
|
|
135
135
|
- Bun(>= 1.2.x)
|
|
136
|
+
- 如果要通过 `npx` 运行已发布 CLI,需要 Node.js
|
|
136
137
|
- 已订阅 Copilot 的 GitHub 账号(个人版、Business 或 Enterprise)
|
|
137
138
|
|
|
138
139
|
## 安装
|
|
@@ -369,6 +370,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
|
|
|
369
370
|
"modelRefreshIntervalHours": 24,
|
|
370
371
|
"sessionAffinityRetentionDays": 7,
|
|
371
372
|
"useMessagesApi": true,
|
|
373
|
+
"useResponsesApiWebSocket": true,
|
|
372
374
|
"useResponsesApiWebSearch": true,
|
|
373
375
|
"logLevel": "info"
|
|
374
376
|
}
|
|
@@ -404,16 +406,54 @@ Copilot API 现在使用子命令结构,主要命令包括:
|
|
|
404
406
|
"topP": 0.95
|
|
405
407
|
}
|
|
406
408
|
}
|
|
409
|
+
},
|
|
410
|
+
"dashscope": {
|
|
411
|
+
"type": "openai-compatible",
|
|
412
|
+
"enabled": true,
|
|
413
|
+
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode",
|
|
414
|
+
"apiKey": "sk-your-dashscope-key",
|
|
415
|
+
"models": {
|
|
416
|
+
"qwen3.6-plus": {
|
|
417
|
+
"temperature": 1,
|
|
418
|
+
"topP": 0.95,
|
|
419
|
+
"topK": 20,
|
|
420
|
+
"extraBody": {
|
|
421
|
+
"preserve_thinking": true
|
|
422
|
+
},
|
|
423
|
+
"contextCache": true
|
|
424
|
+
},
|
|
425
|
+
"glm-5.1": {
|
|
426
|
+
"temperature": 0.7,
|
|
427
|
+
"topP": 0.95,
|
|
428
|
+
"contextCache": true,
|
|
429
|
+
"extraBody": {
|
|
430
|
+
"preserve_thinking": true
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
407
434
|
}
|
|
408
435
|
}
|
|
409
436
|
}
|
|
410
437
|
```
|
|
411
|
-
- **
|
|
438
|
+
- **providers:** 全局上游 provider 映射。每个 provider key(例如 `custom`)都会变成一个路由前缀(`/custom/v1/messages`)。支持 `type: "anthropic"` 和 `type: "openai-compatible"`。顶层 Anthropic 客户端也可以在 `/v1/messages` 和 `/v1/messages/count_tokens` 中使用 `model: "custom/model-id"`;代理会在转发上游前移除 `custom/` 前缀。`GET /v1/models` 不聚合 provider 模型;provider 模型列表请使用 `GET /custom/v1/models`。
|
|
439
|
+
- `enabled`:可选,若省略则默认为 `true`。
|
|
440
|
+
- `baseUrl`:provider API 的基础 URL,不要带结尾的 endpoint。Anthropic provider 不要带 `/v1/messages`;OpenAI 兼容 provider 不要带 `/v1/chat/completions`。
|
|
441
|
+
- `apiKey`:作为上游凭据值使用。
|
|
442
|
+
- `authType`:可选,控制 `apiKey` 如何发送到上游。支持 `x-api-key` 和 `authorization`。Anthropic provider 默认 `x-api-key`;OpenAI 兼容 provider 默认 `authorization`。当设置为 `authorization` 时,代理会发送 `Authorization: Bearer <apiKey>`。
|
|
443
|
+
- `adjustInputTokens`:可选,当为 `true` 时,代理会在 usage 响应里用 `input_tokens` 减去 `cache_read_input_tokens` 和 `cache_creation_input_tokens`。
|
|
444
|
+
- `models`:可选,按模型 ID 配置的映射。每个键为请求中的模型名,值支持:
|
|
445
|
+
- `temperature`:可选,当请求未指定时使用的默认温度。
|
|
446
|
+
- `topP`:可选,当请求未指定时使用的默认 `top_p`。
|
|
447
|
+
- `topK`:可选,当请求未指定时使用的默认 `top_k`。
|
|
448
|
+
- `extraBody`:可选,按模型合入上游请求体的动态字段;请求体显式同名字段优先。OpenAI 兼容 provider 可用它配置 `enable_thinking`、`preserve_thinking`、`reasoning_effort` 等字段。
|
|
449
|
+
- `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`。
|
|
450
|
+
- `supportPdf`:可选,控制该模型是否支持 PDF/document content。默认 `false`,不支持时会把 PDF 转成提示文本;设为 `true` 时会把 PDF/document 转成 OpenAI Chat Completions 的 file part。
|
|
451
|
+
- `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 的能力处理。
|
|
452
|
+
- **responsesApiContextManagementModels:** 需要启用 Responses API `context_management` 压缩指令的 GPT 模型 ID 列表。默认是 `[]`,需要你显式开启。一个不错的起点是 `["gpt-5-mini", "gpt-5.3-codex", "gpt-5.4-mini", "gpt-5.4"]`。启用后,请求体会带上 `context_management`,并在后续轮次中仅保留最新的压缩承载内容。实际压缩由服务端完成,看起来会在 usage 接近模型 `maxPromptTokens` 的约 90% 时开始,因此特别适合长任务场景,同时不会额外消耗 premium requests。
|
|
412
453
|
- **smallModel:** 用于无工具预热消息、compact/background 请求以及其他短小维护型轮次(例如 Claude Code 或 OpenCode 发出的 housekeeping 请求)的回退模型,用来避免消耗 premium requests;默认是 `gpt-5-mini`。如果原始模型名被屏蔽,而这里指向的是某个别名目标模型,则会解析为首选别名。
|
|
413
454
|
- **accountAffinity:** 是否根据 session 标识启用粘性账号路由。开启后,同一 session 针对同一模型的请求会优先路由到上次成功处理它的账号。该策略同时适用于免费模型和付费模型。默认值为 `true`。设为 `false` 则所有模型都改为顺序路由。
|
|
414
|
-
- **apiKey(已弃用):** 兼容迁移的旧单 key 字段。优先使用 `auth.apiKeys`。当 `auth.apiKeys` 为空时,服务端会回退到 `COPILOT_API_KEY`,再回退到 `apiKey`。
|
|
415
|
-
- **
|
|
416
|
-
- **modelAliases:** `alias -> { target, allowOriginal? }` 的映射(也仍然接受旧的字符串写法)。别名 key 会先做标准化(trim + lowercase),且不能为空;别名不能映射回自己(大小写不敏感),冲突的标准化别名会被拒绝。`allowOriginal` 可为单个别名覆盖全局默认值。如果多个别名映射到同一个 target,只要其中任意一个设置了 `allowOriginal: true`,原始模型名就会被允许(allow-wins)。Admin UI/API 会拒绝被屏蔽的键(`__proto__`、`constructor`、`prototype`)。下游请求可以直接使用这些别名。
|
|
455
|
+
- **apiKey(已弃用):** 兼容迁移的旧单 key 字段。优先使用 `auth.apiKeys`。当 `auth.apiKeys` 为空时,服务端会回退到 `COPILOT_API_KEY`,再回退到 `apiKey`。- **modelReasoningEfforts:** 按模型配置发送到 Copilot Responses API 的 `reasoning.effort`。可选值包括 `none`、`minimal`、`low`、`medium`、`high` 和 `xhigh`。若某模型未配置,则默认使用 `high`。
|
|
456
|
+
- **modelAliases:** `alias -> { target, allowOriginal? }` 的映射(也仍然接受旧的字符串写法)。别名 key 会先做标准化(trim + lowercase),且不能为空;别名不能映射回自己(大小写不敏感),冲突的标准化别名会被拒绝。`allowOriginal` 可为单个别名覆盖全局默认值。如果多个别名映射到同一个 target,只要其中任意一个设置了 `allowOriginal: true`,原始模型名就会被允许(allow-wins)。Admin UI/API 会拒绝被屏蔽的键(`__proto__`、`constructor`、`prototype`)。下游请求可以直接使用这些别名,target 也可以是 `provider/model` 形式,用于顶层 `/v1/messages` 与 `/v1/messages/count_tokens` 路由。
|
|
417
457
|
- **allowOriginalModelNamesForAliases:** 对未显式设置 `allowOriginal` 的别名所采用的全局默认值。当其为 `false`(默认)时,target 原名默认被屏蔽,除非某个别名显式允许;当其为 `true` 时,target 原名默认可用,除非所有别名都显式阻止。
|
|
418
458
|
- **useFunctionApplyPatch:** 当为 `true`(默认)时,`POST /v1/responses` 会把 `tools` 中形如 `{ "type": "custom", "name": "apply_patch" }` 的条目转换为 OpenAI 风格的 `function` 工具(带参数 schema),以便与上游更好兼容。设为 `false` 则保留自定义工具原样。
|
|
419
459
|
- **forceAgent:** 当为 `true` 时,只要 `POST /v1/responses` 的任一 input item 带有 `role: "assistant"`,就会把请求视为由 agent 发起;当为 `false`(默认)时,只检查最后一个 input item。
|
|
@@ -422,6 +462,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
|
|
|
422
462
|
- **modelRefreshIntervalHours:** 后台刷新账号模型列表的间隔小时数。设为 `0` 可关闭自动刷新。默认值为 `24`。
|
|
423
463
|
- **sessionAffinityRetentionDays:** session affinity 绑定的保留天数。默认值为 `7`。
|
|
424
464
|
- **useMessagesApi:** 当为 `true`(默认)时,支持 Copilot 原生 `/v1/messages` 端点的 Claude 系模型会走 Messages API 路径。设为 `false` 时,将跳过 Messages API 候选,回退到 `/responses`(如支持)或 `/chat/completions`。
|
|
465
|
+
- **useResponsesApiWebSocket:** 当为 `true`(默认)时,Responses API 请求会对声明了 `ws:/responses` 的模型使用 Copilot WebSocket transport;仅声明 `/responses` 的模型仍走 HTTP。设为 `false` 可禁用 WebSocket 路由。
|
|
425
466
|
- **useResponsesApiWebSearch:** 当为 `true`(默认)时,`/v1/responses` 会保留 `type: "web_search"` 的工具并转发到上游。设为 `false` 则会在发送 Copilot 请求之前将其剥离。
|
|
426
467
|
- **logLevel:** 控制 `logs/*.log` 下 handler 文件日志的详细级别。可选值:`error`、`warn`、`info`、`debug`。默认值为 `info`。如果你需要把 payload 级或 stream 级的调试内容写入文件日志,请显式设置为 `debug`。
|
|
427
468
|
- **anthropicApiKey:** 可选的 Anthropic API key,用于精确的 Claude token 计数(见下文 [精确的 Claude Token 计数](#accurate-claude-token-counting))。也可通过环境变量 `ANTHROPIC_API_KEY` 设置。未配置时会回退到 GPT tokenizer 估算。
|
|
@@ -469,10 +510,10 @@ curl http://localhost:4141/v1/models \
|
|
|
469
510
|
|
|
470
511
|
| 端点 | 方法 | 说明 |
|
|
471
512
|
| --- | --- | --- |
|
|
472
|
-
| `POST /v1/messages` | `POST` |
|
|
473
|
-
| `POST /v1/messages/count_tokens` | `POST` | 计算一组消息的 token
|
|
474
|
-
| `POST /:provider/v1/messages` | `POST` | 将 Anthropic Messages
|
|
475
|
-
| `GET /:provider/v1/models` | `GET` |
|
|
513
|
+
| `POST /v1/messages` | `POST` | 为给定对话创建模型响应。支持已配置 provider 的 `provider/model` 别名。 |
|
|
514
|
+
| `POST /v1/messages/count_tokens` | `POST` | 计算一组消息的 token 数。支持已配置 provider 的 `provider/model` 别名。 |
|
|
515
|
+
| `POST /:provider/v1/messages` | `POST` | 将 Anthropic Messages 请求代理到已配置的 Anthropic 或 OpenAI 兼容 provider。 |
|
|
516
|
+
| `GET /:provider/v1/models` | `GET` | 将模型列表请求代理到已配置的 provider。 |
|
|
476
517
|
| `POST /:provider/v1/messages/count_tokens` | `POST` | 为 provider 路由请求在本地计算 token 数。 |
|
|
477
518
|
|
|
478
519
|
### 使用量监控端点
|
|
@@ -616,6 +657,9 @@ npx @nick3/copilot-api@latest --oauth-app=opencode start
|
|
|
616
657
|
|
|
617
658
|
# 组合多个全局选项
|
|
618
659
|
npx @nick3/copilot-api@latest --api-home=/custom/path --oauth-app=opencode --enterprise-url=company.ghe.com start
|
|
660
|
+
|
|
661
|
+
# 用 Bun 而不是 Node.js 运行已发布 CLI
|
|
662
|
+
bunx --bun @nick3/copilot-api@latest start
|
|
619
663
|
```
|
|
620
664
|
|
|
621
665
|
### Opencode OAuth 认证
|
|
@@ -637,6 +681,67 @@ npx @nick3/copilot-api@latest auth
|
|
|
637
681
|
COPILOT_API_OAUTH_APP=opencode npx @nick3/copilot-api@latest start
|
|
638
682
|
```
|
|
639
683
|
|
|
684
|
+
## 与 Claude Code 一起使用
|
|
685
|
+
|
|
686
|
+
这个代理可以为 [Claude Code](https://docs.anthropic.com/en/claude-code) 提供后端能力。Claude Code 是 Anthropic 提供的实验性面向开发者的对话式 AI 助手。
|
|
687
|
+
|
|
688
|
+
有两种方式可以把 Claude Code 配置为使用这个代理:
|
|
689
|
+
|
|
690
|
+
### 通过 `--claude-code` 标志进行交互式配置
|
|
691
|
+
|
|
692
|
+
执行带 `--claude-code` 的 `start` 命令开始:
|
|
693
|
+
|
|
694
|
+
```sh
|
|
695
|
+
npx @nick3/copilot-api@latest start --claude-code
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
你会被提示选择一个主模型,以及一个用于后台任务的 “small, fast” 模型。选择完成后,会有一条命令被复制到剪贴板中。该命令会设置 Claude Code 使用该代理所需的环境变量。
|
|
699
|
+
|
|
700
|
+
在新的终端中粘贴并执行这条命令,即可启动 Claude Code。
|
|
701
|
+
|
|
702
|
+
<a id="manual-configuration-with-settingsjson"></a>
|
|
703
|
+
|
|
704
|
+
### 通过 `settings.json` 手动配置
|
|
705
|
+
|
|
706
|
+
另一种方式是在项目根目录中创建 `.claude/settings.json` 文件,并写入 Claude Code 所需的环境变量。这样你就不需要每次都运行交互式配置了。
|
|
707
|
+
|
|
708
|
+
下面是一个 `.claude/settings.json` 示例:
|
|
709
|
+
|
|
710
|
+
```json
|
|
711
|
+
{
|
|
712
|
+
"env": {
|
|
713
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
714
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
715
|
+
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
716
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
717
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
718
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
719
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
720
|
+
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
721
|
+
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
722
|
+
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
723
|
+
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
724
|
+
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
725
|
+
},
|
|
726
|
+
"permissions": {
|
|
727
|
+
"deny": [
|
|
728
|
+
"WebSearch",
|
|
729
|
+
"mcp__ide__executeCode"
|
|
730
|
+
]
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
- 请根据需要替换 `ANTHROPIC_MODEL`、`ANTHROPIC_DEFAULT_OPUS_MODEL`、`ANTHROPIC_DEFAULT_SONNET_MODEL` 和 `ANTHROPIC_DEFAULT_HAIKU_MODEL`。配置完成后,请安装 claude code 插件,见 [插件集成](#plugin-integrations)。如果你配置的是 Claude 模型,建议把这些模型配置都设为相同,以保持与 github-copilot claude agent 行为一致。
|
|
736
|
+
- 将 `CLAUDE_CODE_ATTRIBUTION_HEADER` 设为 `0` 可以阻止 Claude Code 在 system prompt 中附加计费和版本信息,从而避免 prompt cache 失效。
|
|
737
|
+
- 关闭 `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION` 和 `CLAUDE_CODE_ENABLE_AWAY_SUMMARY` 可以避免不必要地消耗额度。
|
|
738
|
+
- `permissions` 中禁止 `WebSearch`,因为 GitHub Copilot API 不支持原生 web search(部分 gpt 模型支持 websearch,但本项目目前尚未适配);建议安装 mcp 的 `mcp_server_fetch` 工具或其他搜索工具作为替代。
|
|
739
|
+
- 如果使用的不是 Claude 模型,请不要启用 `ENABLE_TOOL_SEARCH`。如果使用的是 Claude 模型,则可以启用 `ENABLE_TOOL_SEARCH`。当前 Claude Code 使用的是客户端 tool search 模式,在该模式下每次加载 defer tools 都需要额外请求一次。
|
|
740
|
+
|
|
741
|
+
更多选项见:[Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
742
|
+
|
|
743
|
+
也可以参考 IDE 集成说明:[Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
744
|
+
|
|
640
745
|
## 与 OpenCode 一起使用
|
|
641
746
|
|
|
642
747
|
OpenCode 已经内置了 GitHub Copilot provider。本节适用于你希望让 OpenCode 通过 `@ai-sdk/anthropic` 指向这个代理,并复用本 README 前面提到的 agent 行为时。
|
|
@@ -792,83 +897,6 @@ UI 会把 token 保存在 `sessionStorage` 中,并通过 `x-admin-token` 请
|
|
|
792
897
|
- Windows:`%USERPROFILE%\.local\share\copilot-api\admin.sqlite`
|
|
793
898
|
- 默认保留最多 14 天日志,数据库上限为 200,000 行(更旧的数据会自动清理)。
|
|
794
899
|
- 出于安全考虑,admin DB 只保存元数据,不保存 GitHub/Copilot token,也不保存请求/响应正文。
|
|
795
|
-
|
|
796
|
-
## 与 Claude Code 一起使用
|
|
797
|
-
|
|
798
|
-
这个代理可以为 [Claude Code](https://docs.anthropic.com/en/claude-code) 提供后端能力。Claude Code 是 Anthropic 提供的实验性面向开发者的对话式 AI 助手。
|
|
799
|
-
|
|
800
|
-
有两种方式可以把 Claude Code 配置为使用这个代理:
|
|
801
|
-
|
|
802
|
-
### 通过 `--claude-code` 标志进行交互式配置
|
|
803
|
-
|
|
804
|
-
执行带 `--claude-code` 的 `start` 命令开始:
|
|
805
|
-
|
|
806
|
-
```sh
|
|
807
|
-
npx @nick3/copilot-api@latest start --claude-code
|
|
808
|
-
```
|
|
809
|
-
|
|
810
|
-
你会被提示选择一个主模型,以及一个用于后台任务的 “small, fast” 模型。选择完成后,会有一条命令被复制到剪贴板中。该命令会设置 Claude Code 使用该代理所需的环境变量。
|
|
811
|
-
|
|
812
|
-
在新的终端中粘贴并执行这条命令,即可启动 Claude Code。
|
|
813
|
-
|
|
814
|
-
> **API Key 提示:** 如果启用了请求鉴权(推荐 `auth.apiKeys`;旧的 `COPILOT_API_KEY` / `apiKey` 也仍可用),请将 `ANTHROPIC_AUTH_TOKEN` 设置为其中一个可用 API key。
|
|
815
|
-
|
|
816
|
-
<a id="manual-configuration-with-settingsjson"></a>
|
|
817
|
-
|
|
818
|
-
### 通过 `settings.json` 手动配置
|
|
819
|
-
|
|
820
|
-
另一种方式是在项目根目录中创建 `.claude/settings.json` 文件,并写入 Claude Code 所需的环境变量。这样你就不需要每次都运行交互式配置了。
|
|
821
|
-
|
|
822
|
-
下面是一个 `.claude/settings.json` 示例:
|
|
823
|
-
|
|
824
|
-
> **API Key 提示:** 如果启用了请求鉴权,请将 `ANTHROPIC_AUTH_TOKEN` 设为你的某个 API key,这样 Claude Code 才能发送 `x-api-key`。如果未启用鉴权,则任意值都可以。
|
|
825
|
-
|
|
826
|
-
```json
|
|
827
|
-
{
|
|
828
|
-
"env": {
|
|
829
|
-
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
830
|
-
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
831
|
-
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
832
|
-
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
833
|
-
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
834
|
-
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
835
|
-
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
836
|
-
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
837
|
-
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
838
|
-
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
839
|
-
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
840
|
-
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
841
|
-
},
|
|
842
|
-
"permissions": {
|
|
843
|
-
"deny": [
|
|
844
|
-
"WebSearch",
|
|
845
|
-
"mcp__ide__executeCode"
|
|
846
|
-
]
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
```
|
|
850
|
-
|
|
851
|
-
- 请根据需要替换 `ANTHROPIC_MODEL`、`ANTHROPIC_DEFAULT_OPUS_MODEL`、`ANTHROPIC_DEFAULT_SONNET_MODEL` 和 `ANTHROPIC_DEFAULT_HAIKU_MODEL`。配置完成后,请安装 Claude Code 插件,见 [插件集成](#plugin-integrations)。如果你配置的是 Claude 模型,建议把这些模型配置尽量设为一致,以保持与 GitHub Copilot Claude agent 行为一致。
|
|
852
|
-
- 将 `CLAUDE_CODE_ATTRIBUTION_HEADER` 设为 `0` 可以阻止 Claude Code 在 system prompt 中附加计费和版本信息,从而避免 prompt cache 失效。
|
|
853
|
-
- 关闭 `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION` 和 `CLAUDE_CODE_ENABLE_AWAY_SUMMARY` 可以避免不必要地消耗额度。
|
|
854
|
-
- `permissions` 中默认禁止 `WebSearch`,因为当前项目下 GitHub Copilot API 还不支持原生 web search。你可以继续在 Claude Code 的 `permissions` 中拒绝 `WebSearch`,或在 `config.json` 中将 `useResponsesApiWebSearch` 设为 `false`。如果需要搜索能力,建议使用 `mcp_server_fetch` 等替代工具。
|
|
855
|
-
- 请不要启用 `ENABLE_TOOL_SEARCH`。Claude Code 当前使用的是客户端 tool search 模式;每次加载 deferred tools 都需要额外请求,会影响缓存命中率,而且本项目目前与该模式仍存在兼容性问题,启用后也可能引发错误。
|
|
856
|
-
|
|
857
|
-
<a id="claudemd-or-agentsmd-recommended-content"></a>
|
|
858
|
-
|
|
859
|
-
### CLAUDE.md 或 AGENTS.md 推荐内容
|
|
860
|
-
|
|
861
|
-
如果你想手动加入这些提醒,请在 Claude Code 的 `CLAUDE.md`,或 opencode/codex 的 `AGENTS.md` 中加入以下内容:
|
|
862
|
-
|
|
863
|
-
```
|
|
864
|
-
- Prohibited from directly asking questions to users, MUST use question tool.
|
|
865
|
-
- Once you can confirm that the task is complete, MUST use question tool to make user confirm. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again, after try again, MUST use question tool to make user confirm again.
|
|
866
|
-
```
|
|
867
|
-
|
|
868
|
-
更多选项见:[Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
869
|
-
|
|
870
|
-
也可以参考 IDE 集成说明:[Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
871
|
-
|
|
872
900
|
<a id="plugin-integrations"></a>
|
|
873
901
|
|
|
874
902
|
## 插件集成
|