@jeffreycao/copilot-api 1.15.2 → 1.16.1

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
@@ -1,13 +1,69 @@
1
1
  # Copilot API Proxy
2
2
 
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/@jeffreycao/copilot-api"><img src="https://img.shields.io/npm/v/@jeffreycao/copilot-api.svg" alt="npm version"></a>
5
+ <a href="https://github.com/caozhiyuan/copilot-api/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
6
+ <a href="https://github.com/caozhiyuan/copilot-api/stargazers"><img src="https://img.shields.io/github/stars/caozhiyuan/copilot-api.svg" alt="GitHub stars"></a>
7
+ <a href="https://bun.sh"><img src="https://img.shields.io/badge/Bun-%3E%3D1.2.x-orange.svg" alt="Bun >= 1.2.x"></a>
8
+ <a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node-%3E%3D22.13.0-green.svg" alt="Node >= 22.13.0"></a>
9
+ </p>
10
+
3
11
  English | [简体中文](./README.zh-CN.md)
4
12
 
13
+ ## Table of Contents
14
+
15
+ - [Copilot API Proxy](#copilot-api-proxy)
16
+ - [Table of Contents](#table-of-contents)
17
+ - [Important Notes](#important-notes)
18
+ - [Project Overview](#project-overview)
19
+ - [Quick Start](#quick-start)
20
+ - [Features](#features)
21
+ - [Prerequisites](#prerequisites)
22
+ - [Installation](#installation)
23
+ - [Running from Source](#running-from-source)
24
+ - [Development Mode](#development-mode)
25
+ - [Production Mode](#production-mode)
26
+ - [Using with npx](#using-with-npx)
27
+ - [Using with Docker](#using-with-docker)
28
+ - [Electron Desktop App](#electron-desktop-app)
29
+ - [Desktop App Screenshots](#desktop-app-screenshots)
30
+ - [Using with Claude Code](#using-with-claude-code)
31
+ - [Interactive Setup with `--claude-code` flag](#interactive-setup-with---claude-code-flag)
32
+ - [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson)
33
+ - [Using with OpenCode](#using-with-opencode)
34
+ - [Minimal setup](#minimal-setup)
35
+ - [Using with Codex](#using-with-codex)
36
+ - [Codex `config.toml` Reference](#codex-configtoml-reference)
37
+ - [GPT Tool Search](#gpt-tool-search)
38
+ - [Plugin Integrations](#plugin-integrations)
39
+ - [Claude Code plugin integration (marketplace-based)](#claude-code-plugin-integration-marketplace-based)
40
+ - [Opencode plugin](#opencode-plugin)
41
+ - [Using the Usage Viewer](#using-the-usage-viewer)
42
+ - [Usage Viewer Screenshot](#usage-viewer-screenshot)
43
+ - [Command Structure](#command-structure)
44
+ - [Command Line Options](#command-line-options)
45
+ - [Global Options](#global-options)
46
+ - [Start Command Options](#start-command-options)
47
+ - [Auth Command Options](#auth-command-options)
48
+ - [Debug Command Options](#debug-command-options)
49
+ - [Configuration (config.json)](#configuration-configjson)
50
+ - [API Authentication](#api-authentication)
51
+ - [API Endpoints](#api-endpoints)
52
+ - [OpenAI Compatible Endpoints](#openai-compatible-endpoints)
53
+ - [Codex Backend Proxy Endpoints](#codex-backend-proxy-endpoints)
54
+ - [Anthropic Compatible Endpoints](#anthropic-compatible-endpoints)
55
+ - [Usage Monitoring Endpoints](#usage-monitoring-endpoints)
56
+ - [Admin / Configuration Endpoints](#admin--configuration-endpoints)
57
+ - [Example Usage](#example-usage)
58
+ - [Usage Tips](#usage-tips)
59
+ - [CLAUDE.md or AGENTS.md Recommended Content](#claudemd-or-agentsmd-recommended-content)
60
+
5
61
  ## Important Notes
6
62
 
7
63
  > [!IMPORTANT]
8
64
  > **Before using, please be aware of the following:**
9
65
  >
10
- > 1. **Claude Code configuration:** When using with Claude Code, please configure the model ID as `claude-opus-4-8`. Example claude `settings.json` see [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson).
66
+ > 1. **Claude Code configuration:** When using with Claude Code, please configure the model ID as `claude-opus-4-8[1m]`. Example claude `settings.json` see [Manual Configuration with `settings.json`](#manual-configuration-with-settingsjson).
11
67
  >
12
68
  > 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.
13
69
  >
@@ -23,6 +79,31 @@ The gateway exposes OpenAI- and Anthropic-compatible APIs from one local endpoin
23
79
 
24
80
  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.
25
81
 
82
+ ## Quick Start
83
+
84
+ The fastest way to get a working gateway:
85
+
86
+ ```sh
87
+ npx @jeffreycao/copilot-api@latest start
88
+ ```
89
+
90
+ The server listens on `http://localhost:4141` by default. Optionally authenticate with GitHub Copilot or configure a third-party provider first:
91
+
92
+ ```sh
93
+ npx @jeffreycao/copilot-api@latest auth login
94
+ ```
95
+
96
+ Verify the gateway is up:
97
+
98
+ ```sh
99
+ curl http://localhost:4141/v1/models
100
+ ```
101
+
102
+ > [!NOTE]
103
+ > Token usage storage requires Node.js >= 22.13.0 or Bun. See [Using with npx](#using-with-npx) for details.
104
+
105
+ From here, jump to the guide for your client: [Claude Code](#using-with-claude-code), [OpenCode](#using-with-opencode), [Codex](#using-with-codex), or run it with [Docker](#using-with-docker).
106
+
26
107
  ## Features
27
108
 
28
109
  - **OpenAI and Anthropic compatibility**: Serve `/v1/responses`, `/v1/chat/completions`, `/v1/models`, `/v1/embeddings`, and `/v1/messages` from one local gateway.
@@ -50,12 +131,6 @@ To install dependencies, run:
50
131
  bun install
51
132
  ```
52
133
 
53
- To start the server directly from source:
54
-
55
- ```sh
56
- bun run start start
57
- ```
58
-
59
134
  ## Running from Source
60
135
 
61
136
  The project can be run from source in several ways:
@@ -72,6 +147,8 @@ bun run dev start
72
147
  bun run start start
73
148
  ```
74
149
 
150
+ > The trailing `start` is the CLI subcommand passed to `src/main.ts`, not a typo: `bun run dev start` runs watch mode, `bun run start start` runs production.
151
+
75
152
  ## Using with npx
76
153
 
77
154
  You can run the project directly using npx:
@@ -307,6 +384,7 @@ model_provider = "copilot_api"
307
384
  model_reasoning_summary = "auto"
308
385
  model_context_window = 272000
309
386
  model_auto_compact_token_limit = 244800
387
+ web_search = "live"
310
388
 
311
389
  [model_providers.copilot_api]
312
390
  name = "OpenAI"
@@ -387,7 +465,7 @@ The bridge uses direct tool selection, not query search. Its tool input is `name
387
465
 
388
466
  Plugin integrations are available for Claude Code and opencode.
389
467
 
390
- #### Claude Code plugin integration (marketplace-based)
468
+ ### Claude Code plugin integration (marketplace-based)
391
469
 
392
470
  The Claude Code integration is packaged as two plugins:
393
471
 
@@ -419,7 +497,7 @@ The `agent-inject` plugin also registers a `UserPromptSubmit` hook that returns
419
497
 
420
498
  The `tool-search` plugin bundles the same MCP bridge described in [GPT Tool Search](#gpt-tool-search), so Claude Code users do not need to add the `tool_search` server manually when they install that plugin.
421
499
 
422
- #### Opencode plugin
500
+ ### Opencode plugin
423
501
 
424
502
  The subagent marker producer is packaged as an opencode plugin located at `plugin/opencode/subagent-marker.js`.
425
503
 
@@ -585,60 +663,6 @@ Use `copilot-api auth login --provider custom` to add or update another third-pa
585
663
  - `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.
586
664
  - `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.
587
665
  - `type` (optional): Per-model override of the provider protocol type. Supports `anthropic`, `openai-compatible`, and `openai-responses`. When set, the provider's `/v1/messages` route uses this model's type instead of the provider-level type for request routing, auth header resolution, and upstream endpoint selection. This is useful for providers like OpenCode Go whose upstream supports both OpenAI-compatible and Anthropic Messages APIs for different models. When the type is overridden, the auth header is resolved from the overridden type's default (Anthropic defaults to `x-api-key`; OpenAI-compatible/Responses default to `authorization`).
588
-
589
- Example DashScope model settings:
590
- ```json
591
- {
592
- "providers": {
593
- "dashscope": {
594
- "type": "openai-compatible",
595
- "enabled": true,
596
- "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode",
597
- "apiKey": "sk-your-dashscope-key",
598
- "pricingCurrency": "CNY",
599
- "models": {
600
- "qwen3.7-plus": {
601
- "temperature": 1,
602
- "topP": 0.95,
603
- "topK": 20,
604
- "extraBody": {
605
- "preserve_thinking": true
606
- }
607
- },
608
- "glm-5.1": {
609
- "temperature": 0.7,
610
- "topP": 0.95,
611
- "contextCache": true,
612
- "pricing": {
613
- "tiers": [
614
- {
615
- "maxInputTokens": 32000,
616
- "input": 6,
617
- "cachedInput": 1.2,
618
- "explicitCachedInput": 0.6,
619
- "cacheCreationInput": 7.5,
620
- "output": 24
621
- },
622
- {
623
- "maxInputTokens": 200000,
624
- "input": 8,
625
- "cachedInput": 1.6,
626
- "explicitCachedInput": 0.8,
627
- "cacheCreationInput": 10,
628
- "output": 28
629
- }
630
- ]
631
- },
632
- "extraBody": {
633
- "preserve_thinking": true
634
- }
635
- }
636
- }
637
- }
638
- }
639
- }
640
- ```
641
- Built-in token prices cover Codex GPT models in USD, DashScope `qwen3.7-max`, `qwen3.7-plus`, `glm-5.1`, `glm-5.2`, and `kimi/kimi-k3` in CNY, DeepSeek `deepseek-v4-flash` and `deepseek-v4-pro` in CNY, OpenCode Go models (`hy3`, `gpt-5.6-luna`, `glm-5.2`, `grok-4.5`, `deepseek-v4-flash`, `deepseek-v4-pro`, `kimi-k2.7-code`, `kimi-k3`, `mimo-v2.5`, `mimo-v2.5-pro`, `qwen3.7-plus`, `qwen3.7-max`, `minimax-m2.7`, `minimax-m3`) in USD, and Kimi `k3` and `k3-256k` models in USD. 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.
642
666
  - **smallModel:** Fallback model used for tool-less warmup messages (e.g., Claude Code probe requests); defaults to gpt-5-mini. The gateway forces this small model on no-tool warmup or probe requests to avoid consuming premium requests. This behavior only applies to non-token-based-billing GitHub Copilot accounts (`token_based_billing` is false); for token-based-billing accounts the warmup small-model fallback is skipped since there is no premium-request quota to preserve.
643
667
  - **contextManagement:** Controls whether the proxy adds Responses API `context_management` compaction instructions. `messages` applies when Anthropic-style `/v1/messages` requests are translated to Responses API, including `openai-responses` provider message routes, and defaults to `true`. `responses` applies to native `/v1/responses` traffic, including `provider/model` aliases and the built-in `codex` provider, and defaults to `false`. Enable `responses` only after checking that your client supports context management compaction. When enabled, the request includes `context_management` in the body and keeps only the latest compaction carrier on follow-up turns. **Note:** Context management is forcibly disabled for GPT-5.6 and above models (e.g. `gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna`) because enabling it breaks prompt cache hits on those models. This override takes precedence over the `contextManagement` and `modelResponsesApiCompactThresholds` settings.
644
668
  - **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.
@@ -700,9 +724,9 @@ These endpoints mimic the OpenAI API structure.
700
724
 
701
725
  These endpoints require an active Codex login. Each endpoint is available both without a version prefix and under `/v1`.
702
726
 
703
- | Endpoint | Method | Description |
704
- | --- | --- | --- |
705
- | `POST /alpha/search`<br>`POST /v1/alpha/search` | `POST` | Transparently forwards the JSON body and query parameters to the Codex Alpha Search upstream. |
727
+ | Endpoint | Method | Description |
728
+ | -------------------------------------------------------------- | ------ | --------------------------------------------------------------- |
729
+ | `POST /alpha/search`<br>`POST /v1/alpha/search` | `POST` | Transparently forwards the JSON body and query parameters to the Codex Alpha Search upstream. |
706
730
  | `POST /images/generations`<br>`POST /v1/images/generations` | `POST` | Forwards a JSON image generation request to the Codex Images upstream. When the request omits `Content-Type`, the gateway defaults it to `application/json`. |
707
731
  | `POST /images/edits`<br>`POST /v1/images/edits` | `POST` | Forwards an image edit request to the Codex Images upstream. Send this request as `multipart/form-data` and let the HTTP client generate the `boundary`; the gateway preserves the incoming content type and streams the upload body. |
708
732
 
@@ -783,7 +807,7 @@ curl http://localhost:4141/dashscope/v1/messages \
783
807
 
784
808
  ### CLAUDE.md or AGENTS.md Recommended Content
785
809
 
786
- To add these reminders manually, include the following in `CLAUDE.md` for Claude Code, or `AGENTS.md` for opencode/codex:
810
+ Same reminders as `CLAUDE_PLUGIN_ENABLE_QUESTION_RULES=1` in the `agent-inject` plugin, for when you don't use that plugin. Add to `CLAUDE.md` (Claude Code) or `AGENTS.md` (opencode/codex):
787
811
 
788
812
  ```
789
813
  - Prohibited from directly asking questions to users, MUST use question tool.