From 9ba127c8985c289349745ebe90eb9db89b062686 Mon Sep 17 00:00:00 2001 From: yang-builds Date: Thu, 23 Apr 2026 00:05:46 +0800 Subject: [PATCH] feat: support hyphenated Claude model names (claude-sonnet-4-6, claude-opus-4-7, claude-haiku-4-5) Fix compatibility with Claude Code 2.1.x: translateModelName now converts hyphenated format (claude-sonnet-4-6) to dot notation (claude-sonnet-4.6) via regex instead of incorrectly truncating to claude-sonnet-4. Fixes: HTTP 400 errors and wrong model version display ('Sonnet 4' vs '4.6'). --- CHANGELOG.md | 21 + MAINTAINERS.md | 45 ++ README.md | 406 +++++------------- bun.lock | 1 + package.json | 20 +- src/routes/messages/non-stream-translation.ts | 11 +- 6 files changed, 184 insertions(+), 320 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 MAINTAINERS.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..76757806f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,21 @@ +# Changelog + +## v0.7.0-patch.1 (2026-04-22) + +**Fork 起点:** 基于 [ericc-ch/copilot-api v0.7.0](https://github.com/ericc-ch/copilot-api/releases/tag/v0.7.0) + +### Bug Fix + +**修复 Claude Code 2.1.x 新版模型名不兼容问题** + +- **文件:** `src/routes/messages/non-stream-translation.ts` +- **函数:** `translateModelName` +- **问题:** 原版将 `claude-sonnet-4-6` 截断为 `claude-sonnet-4`,被 GitHub Copilot 后端以 HTTP 400 拒绝;Claude Code 欢迎界面错误显示 "Sonnet 4" +- **修复:** 用正则 `^(claude-(?:sonnet|opus|haiku))-(\d+)-(\d+)$` 将连字符转换为点号,`claude-sonnet-4-6` → `claude-sonnet-4.6` +- **覆盖模型:** claude-sonnet-4-6、claude-opus-4-7、claude-haiku-4-5(及未来同格式新模型) + +--- + +## 上游版本 + +参见 [ericc-ch/copilot-api releases](https://github.com/ericc-ch/copilot-api/releases) diff --git a/MAINTAINERS.md b/MAINTAINERS.md new file mode 100644 index 000000000..18117672d --- /dev/null +++ b/MAINTAINERS.md @@ -0,0 +1,45 @@ +# 维护说明 + +## 同步上游更新 + +```bash +git fetch upstream +git log upstream/master --oneline | head -10 # 查看上游新提交 +git merge upstream/master +``` + +合并冲突大概率只在 `src/routes/messages/non-stream-translation.ts` 的 `translateModelName` 函数。 +解决冲突时,**保留本 fork 的 regex 版本**,丢弃上游的硬编码版本。 + +解决冲突后: + +```bash +bun install && bun run build +# 本地验证四条模型名 +curl -s -X POST http://localhost:4141/v1/messages \ + -H "Content-Type: application/json" \ + -d '{"model":"claude-sonnet-4-6","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}' | head -c 200 +``` + +## 发版流程 + +1. 更新 `package.json` 中的 `version`(遵循 `0.7.x-patch.y` 格式) +2. 更新 `CHANGELOG.md` +3. `bun run build` +4. `git commit -am "chore: release vX.Y.Z-patch.N"` +5. `git tag vX.Y.Z-patch.N && git push && git push --tags` +6. 在 GitHub 创建 Release,附上 CHANGELOG 内容 +7. `npm publish --access public` + +## 新模型支持 + +当 Anthropic 发布新模型(如 claude-sonnet-5-0)时: +- 检查 `translateModelName` 中的正则 `^(claude-(?:sonnet|opus|haiku))-(\d+)-(\d+)$` +- 确认新命名格式是否匹配。若 Anthropic 引入全新系列名(非 sonnet/opus/haiku),在正则的 `(?:sonnet|opus|haiku)` 中添加新名称即可 + +## Patch 文件位置 + +| 文件 | 改动说明 | +|------|---------| +| `src/routes/messages/non-stream-translation.ts` | `translateModelName` 函数(核心 patch) | +| `package.json` | name / version / contributors / publishConfig | diff --git a/README.md b/README.md index 0d36c13c9..e72407659 100644 --- a/README.md +++ b/README.md @@ -1,351 +1,143 @@ -# Copilot API Proxy +# copilot-api · 解决 Claude Code 新版模型名不兼容 -> [!WARNING] -> This is a reverse-engineered proxy of GitHub Copilot API. It is not supported by GitHub, and may break unexpectedly. Use at your own risk. +[![npm version](https://img.shields.io/npm/v/@yang-builds/copilot-api?label=%40yang-builds%2Fcopilot-api)](https://www.npmjs.com/package/@yang-builds/copilot-api) +[![npm downloads](https://img.shields.io/npm/dm/@yang-builds/copilot-api)](https://www.npmjs.com/package/@yang-builds/copilot-api) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) +[![Fork of ericc-ch/copilot-api](https://img.shields.io/badge/fork%20of-ericc--ch%2Fcopilot--api-orange)](https://github.com/ericc-ch/copilot-api) -> [!WARNING] -> **GitHub Security Notice:** -> Excessive automated or scripted use of Copilot (including rapid or bulk requests, such as via automated tools) may trigger GitHub's abuse-detection systems. -> You may receive a warning from GitHub Security, and further anomalous activity could result in temporary suspension of your Copilot access. -> -> GitHub prohibits use of their servers for excessive automated bulk activity or any activity that places undue burden on their infrastructure. -> -> Please review: -> -> - [GitHub Acceptable Use Policies](https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies#4-spam-and-inauthentic-activity-on-github) -> - [GitHub Copilot Terms](https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot) -> -> Use this proxy responsibly to avoid account restrictions. - -[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E519XS7W) +> **Fork 说明:** 本仓库基于 [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api) v0.7.0,仅修复 Claude Code 2.1.x 新版模型名格式不兼容问题,其余功能与原版 100% 一致。 --- -**Note:** If you are using [opencode](https://github.com/sst/opencode), you do not need this project. Opencode supports GitHub Copilot provider out of the box. - ---- - -## Project Overview - -A reverse-engineered proxy for the GitHub Copilot API that exposes it as an OpenAI and Anthropic compatible service. This allows you to use GitHub Copilot with any tool that supports the OpenAI Chat Completions API or the Anthropic Messages API, including to power [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview). - -## Features - -- **OpenAI & Anthropic Compatibility**: Exposes GitHub Copilot as an OpenAI-compatible (`/v1/chat/completions`, `/v1/models`, `/v1/embeddings`) and Anthropic-compatible (`/v1/messages`) API. -- **Claude Code Integration**: Easily configure and launch [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) to use Copilot as its backend with a simple command-line flag (`--claude-code`). -- **Usage Dashboard**: A web-based dashboard to monitor your Copilot API usage, view quotas, and see detailed statistics. -- **Rate Limit Control**: Manage API usage with rate-limiting options (`--rate-limit`) and a waiting mechanism (`--wait`) to prevent errors from rapid requests. -- **Manual Request Approval**: Manually approve or deny each API request for fine-grained control over usage (`--manual`). -- **Token Visibility**: Option to display GitHub and Copilot tokens during authentication and refresh for debugging (`--show-token`). -- **Flexible Authentication**: Authenticate interactively or provide a GitHub token directly, suitable for CI/CD environments. -- **Support for Different Account Types**: Works with individual, business, and enterprise GitHub Copilot plans. - -## Demo - -https://github.com/user-attachments/assets/7654b383-669d-4eb9-b23c-06d7aefee8c5 - -## Prerequisites - -- Bun (>= 1.2.x) -- GitHub account with Copilot subscription (individual, business, or enterprise) - -## Installation - -To install dependencies, run: - -```sh -bun install -``` - -## Using with Docker - -Build image - -```sh -docker build -t copilot-api . -``` - -Run the container - -```sh -# Create a directory on your host to persist the GitHub token and related data -mkdir -p ./copilot-data - -# Run the container with a bind mount to persist the token -# This ensures your authentication survives container restarts - -docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api -``` - -> **Note:** -> The GitHub token and related data will be stored in `copilot-data` on your host. This is mapped to `/root/.local/share/copilot-api` inside the container, ensuring persistence across restarts. - -### Docker with Environment Variables - -You can pass the GitHub token directly to the container using environment variables: +## 你遇到的问题是这个吗? -```sh -# Build with GitHub token -docker build --build-arg GH_TOKEN=your_github_token_here -t copilot-api . +| 症状 | 根本原因 | 本 fork 的修复 | +|------|----------|---------------| +| Claude Code 2.1.x 启动时提示 `API Error: 400 Bad Request` | Claude Code 前端用 `claude-sonnet-4-6`(连字符)做模型显示映射,原版 `translateModelName` 将其错误截断为 `claude-sonnet-4`,被 GitHub Copilot 后端拒绝 | 正则 `^(claude-(?:sonnet\|opus\|haiku))-(\d+)-(\d+)$` 将连字符格式正确转换为 `claude-sonnet-4.6`(点号格式) | +| 欢迎界面显示 "Sonnet 4" 而非 "Sonnet 4.6" / "Opus 4.7" | 同上:模型名被截断导致后端返回了低版本模型 | 同上 | -# Run with GitHub token -docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api +**受影响版本组合:** `copilot-api 0.7.0` + `Claude Code ≥ 2.1.x`(使用 Sonnet 4.6 / Opus 4.7 / Haiku 4.5) -# Run with additional options -docker run -p 4141:4141 -e GH_TOKEN=your_token copilot-api start --verbose --port 4141 -``` - -### Docker Compose Example - -```yaml -version: "3.8" -services: - copilot-api: - build: . - ports: - - "4141:4141" - environment: - - GH_TOKEN=your_github_token_here - restart: unless-stopped -``` - -The Docker image includes: - -- Multi-stage build for optimized image size -- Non-root user for enhanced security -- Health check for container monitoring -- Pinned base image version for reproducible builds - -## Using with npx - -You can run the project directly using npx: +--- -```sh -npx copilot-api@latest start -``` +## 一键安装与使用 -With options: +```bash +# 安装 +npm install -g @yang-builds/copilot-api -```sh -npx copilot-api@latest start --port 8080 +# 启动代理(默认 4141 端口) +copilot-api start ``` -For authentication only: +然后在 `~/.claude/settings.json` 中配置: -```sh -npx copilot-api@latest auth +```json +{ + "env": { + "ANTHROPIC_BASE_URL": "http://localhost:4141", + "ANTHROPIC_AUTH_TOKEN": "no-key", + "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5", + "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6", + "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-7" + } +} ``` -## Command Structure - -Copilot API now uses a subcommand structure with these main commands: - -- `start`: Start the Copilot API server. This command will also handle authentication if needed. -- `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. -- `check-usage`: Show your current GitHub Copilot usage and quota information directly in the terminal (no server required). -- `debug`: Display diagnostic information including version, runtime details, file paths, and authentication status. Useful for troubleshooting and support. - -## Command Line Options - -### Start Command Options - -The following command line options are available for the `start` command: - -| Option | Description | Default | Alias | -| -------------- | ----------------------------------------------------------------------------- | ---------- | ----- | -| --port | Port to listen on | 4141 | -p | -| --verbose | Enable verbose logging | false | -v | -| --account-type | Account type to use (individual, business, enterprise) | individual | -a | -| --manual | Enable manual request approval | false | none | -| --rate-limit | Rate limit in seconds between requests | none | -r | -| --wait | Wait instead of error when rate limit is hit | false | -w | -| --github-token | Provide GitHub token directly (must be generated using the `auth` subcommand) | none | -g | -| --claude-code | Generate a command to launch Claude Code with Copilot API config | false | -c | -| --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none | -| --proxy-env | Initialize proxy from environment variables | false | none | +> **注意:** 模型名使用连字符格式(`claude-sonnet-4-6`),这正是 Claude Code 前端的显示映射键名,本 fork 会自动转换为后端所需的点号格式。 -### Auth Command Options +启动 Claude Code 后欢迎界面应显示 **"claude-sonnet-4.6"**,说明一切正常。 -| Option | Description | Default | Alias | -| ------------ | ------------------------- | ------- | ----- | -| --verbose | Enable verbose logging | false | -v | -| --show-token | Show GitHub token on auth | false | none | - -### Debug Command Options - -| Option | Description | Default | Alias | -| ------ | ------------------------- | ------- | ----- | -| --json | Output debug info as JSON | false | none | - -## API Endpoints - -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. - -### OpenAI Compatible Endpoints - -These endpoints mimic the OpenAI API structure. - -| Endpoint | Method | Description | -| --------------------------- | ------ | --------------------------------------------------------- | -| `POST /v1/chat/completions` | `POST` | Creates a model response for the given chat conversation. | -| `GET /v1/models` | `GET` | Lists the currently available models. | -| `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. | - -### Anthropic Compatible Endpoints - -These endpoints are designed to be compatible with the Anthropic Messages API. - -| Endpoint | Method | Description | -| -------------------------------- | ------ | ------------------------------------------------------------ | -| `POST /v1/messages` | `POST` | Creates a model response for a given conversation. | -| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. | - -### Usage Monitoring Endpoints - -New endpoints for monitoring your Copilot usage and quotas. - -| Endpoint | Method | Description | -| ------------ | ------ | ------------------------------------------------------------ | -| `GET /usage` | `GET` | Get detailed Copilot usage statistics and quota information. | -| `GET /token` | `GET` | Get the current Copilot token being used by the API. | - -## Example Usage - -Using with npx: - -```sh -# Basic usage with start command -npx copilot-api@latest start - -# Run on custom port with verbose logging -npx copilot-api@latest start --port 8080 --verbose - -# Use with a business plan GitHub account -npx copilot-api@latest start --account-type business - -# Use with an enterprise plan GitHub account -npx copilot-api@latest start --account-type enterprise - -# Enable manual approval for each request -npx copilot-api@latest start --manual - -# Set rate limit to 30 seconds between requests -npx copilot-api@latest start --rate-limit 30 - -# Wait instead of error when rate limit is hit -npx copilot-api@latest start --rate-limit 30 --wait - -# Provide GitHub token directly -npx copilot-api@latest start --github-token ghp_YOUR_TOKEN_HERE - -# Run only the auth flow -npx copilot-api@latest auth - -# Run auth flow with verbose logging -npx copilot-api@latest auth --verbose - -# Show your Copilot usage/quota in the terminal (no server needed) -npx copilot-api@latest check-usage - -# Display debug information for troubleshooting -npx copilot-api@latest debug - -# Display debug information in JSON format -npx copilot-api@latest debug --json +--- -# Initialize proxy from environment variables (HTTP_PROXY, HTTPS_PROXY, etc.) -npx copilot-api@latest start --proxy-env +## 与上游的差异 + +| 文件 | 改动内容 | +|------|---------| +| `src/routes/messages/non-stream-translation.ts` | `translateModelName` 函数:从硬编码截断改为正则转换,支持所有 `claude-{family}-{major}-{minor}` 格式 | +| `package.json` | name 改为 `@yang-builds/copilot-api`,version 改为 `0.7.0-patch.1`,加入 contributors | + +**代码差异(核心改动):** + +```diff + function translateModelName(model: string): string { +- // Subagent requests use a specific model number which Copilot doesn't support +- if (model.startsWith("claude-sonnet-4-")) { +- return model.replace(/^claude-sonnet-4-.*/, "claude-sonnet-4") +- } else if (model.startsWith("claude-opus-")) { +- return model.replace(/^claude-opus-4-.*/, "claude-opus-4") +- } ++ // Claude Code uses hyphenated model names (e.g. claude-sonnet-4-6) for display mapping, ++ // but GitHub Copilot backend requires dot notation (e.g. claude-sonnet-4.6). ++ const m = model.match(/^(claude-(?:sonnet|opus|haiku))-(\d+)-(\d+)$/) ++ if (m) return `${m[1]}-${m[2]}.${m[3]}` + return model + } ``` -## Using the Usage Viewer - -After starting the server, a URL to the Copilot Usage Dashboard will be displayed in your console. This dashboard is a web interface for monitoring your API usage. +--- -1. Start the server. For example, using npx: - ```sh - npx copilot-api@latest start - ``` -2. The server will output a URL to the usage viewer. Copy and paste this URL into your browser. It will look something like this: - `https://ericc-ch.github.io/copilot-api?endpoint=http://localhost:4141/usage` - - If you use the `start.bat` script on Windows, this page will open automatically. +## 完整使用说明 -The dashboard provides a user-friendly interface to view your Copilot usage data: +### 前提条件 -- **API Endpoint URL**: The dashboard is pre-configured to fetch data from your local server endpoint via the URL query parameter. You can change this URL to point to any other compatible API endpoint. -- **Fetch Data**: Click the "Fetch" button to load or refresh the usage data. The dashboard will automatically fetch data on load. -- **Usage Quotas**: View a summary of your usage quotas for different services like Chat and Completions, displayed with progress bars for a quick overview. -- **Detailed Information**: See the full JSON response from the API for a detailed breakdown of all available usage statistics. -- **URL-based Configuration**: You can also specify the API endpoint directly in the URL using a query parameter. This is useful for bookmarks or sharing links. For example: - `https://ericc-ch.github.io/copilot-api?endpoint=http://your-api-server/usage` +- Node.js ≥ 18(推荐)或 Bun ≥ 1.2.x +- GitHub Copilot 有效订阅 -## Using with Claude Code +### CLI 选项 -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. +| 选项 | 说明 | 默认值 | +|------|------|--------| +| `--port` | 监听端口 | `4141` | +| `--verbose` | 输出详细日志 | `false` | +| `--manual-approval` | 每次请求需手动批准 | `false` | +| `--disable-telemetry` | 禁用遥测 | `false` | -There are two ways to configure Claude Code to use this proxy: +### API 端点 -### Interactive Setup with `--claude-code` flag +| 端点 | 说明 | +|------|------| +| `POST /v1/messages` | Anthropic 兼容接口(供 Claude Code 使用) | +| `POST /v1/chat/completions` | OpenAI 兼容接口 | +| `GET /v1/models` | 列出可用模型 | -To get started, run the `start` command with the `--claude-code` flag: +--- -```sh -npx copilot-api@latest start --claude-code -``` +## 常见问题 -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. +**Q: 能切回官方 copilot-api 吗?** +A: 可以,随时 `npm i -g copilot-api` 切回。本 fork 只修复了模型名转换,功能完全兼容。 -Paste and run this command in a new terminal to launch Claude Code. +**Q: Anthropic 发布新模型(比如 Sonnet 5.0)还能用吗?** +A: 只要新模型命名遵循 `claude-{family}-{major}-{minor}` 格式,正则会自动覆盖,无需改代码。 -### Manual Configuration with `settings.json` +**Q: 为什么还是出现 API Error 400?** +A: 另一个常见原因:Claude Code 的 MCP 插件(如 `chrome-devtools-mcp`)注入了包含 JSON Schema Draft 2020-12 字段的 tools,被 GitHub Copilot 后端拒绝。解决方法:在 `~/.claude/settings.json` 中将该插件设为 `false`。 -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. +--- -Here is an example `.claude/settings.json` file: +## 同步上游更新 -```json -{ - "env": { - "ANTHROPIC_BASE_URL": "http://localhost:4141", - "ANTHROPIC_AUTH_TOKEN": "dummy", - "ANTHROPIC_MODEL": "gpt-4.1", - "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1", - "ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1", - "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4.1", - "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1", - "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" - }, - "permissions": { - "deny": [ - "WebSearch" - ] - } -} +```bash +git fetch upstream +git merge upstream/master +# 冲突区大概率只在 src/routes/messages/non-stream-translation.ts 的 translateModelName 函数 +# 解决冲突时保留本 fork 的 regex 版本 +bun install && bun run build ``` -You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables) - -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) - -## Running from Source - -The project can be run from source in several ways: +--- -### Development Mode +## 致谢 -```sh -bun run dev -``` +- 原作者 **[@ericc-ch](https://github.com/ericc-ch)**,原始项目 [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api) +- 如果原项目对你有帮助,请给原作者的 [ko-fi](https://ko-fi.com/ericc) 支持一下 -### Production Mode +> [!WARNING] +> This is a reverse-engineered proxy of GitHub Copilot API. It is not supported by GitHub, and may break unexpectedly. Use at your own risk. -```sh -bun run start -``` +--- -## Usage Tips +## License -- To avoid hitting GitHub Copilot's rate limits, you can use the following flags: - - `--manual`: Enables manual approval for each request, giving you full control over when requests are sent. - - `--rate-limit `: 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. - - `--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. -- 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. +MIT © Erick Christian (原作者) · Fork maintained by [yang-builds](https://github.com/yang-builds) diff --git a/bun.lock b/bun.lock index 20e895e7f..9ece87578 100644 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "copilot-api", diff --git a/package.json b/package.json index a5adbb8e7..71e730b50 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,25 @@ { - "name": "copilot-api", - "version": "0.7.0", - "description": "Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Usable with Claude Code!", + "name": "@yang-builds/copilot-api", + "version": "0.7.0-patch.1", + "description": "Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Fork of ericc-ch/copilot-api with fix for Claude Code new model name incompatibility (claude-sonnet-4-6, claude-opus-4-7, claude-haiku-4-5).", "keywords": [ "proxy", "github-copilot", "openai-compatible" ], - "homepage": "https://github.com/ericc-ch/copilot-api", - "bugs": "https://github.com/ericc-ch/copilot-api/issues", + "homepage": "https://github.com/yang-builds/copilot-api", + "bugs": "https://github.com/yang-builds/copilot-api/issues", "repository": { "type": "git", - "url": "git+https://github.com/ericc-ch/copilot-api.git" + "url": "git+https://github.com/yang-builds/copilot-api.git" }, "author": "Erick Christian ", + "contributors": [ + "yang-builds " + ], + "publishConfig": { + "access": "public" + }, "type": "module", "bin": { "copilot-api": "./dist/main.js" @@ -65,4 +71,4 @@ "tsdown": "^0.15.6", "typescript": "^5.9.3" } -} +} \ No newline at end of file diff --git a/src/routes/messages/non-stream-translation.ts b/src/routes/messages/non-stream-translation.ts index dc41e6382..c743c5861 100644 --- a/src/routes/messages/non-stream-translation.ts +++ b/src/routes/messages/non-stream-translation.ts @@ -47,12 +47,11 @@ export function translateToOpenAI( } function translateModelName(model: string): string { - // Subagent requests use a specific model number which Copilot doesn't support - if (model.startsWith("claude-sonnet-4-")) { - return model.replace(/^claude-sonnet-4-.*/, "claude-sonnet-4") - } else if (model.startsWith("claude-opus-")) { - return model.replace(/^claude-opus-4-.*/, "claude-opus-4") - } + // Claude Code uses hyphenated model names (e.g. claude-sonnet-4-6) for display mapping, + // but GitHub Copilot backend requires dot notation (e.g. claude-sonnet-4.6). + // This regex converts hyphenated minor versions to dot notation for all Claude model families. + const m = model.match(/^(claude-(?:sonnet|opus|haiku))-(\d+)-(\d+)$/) + if (m) return `${m[1]}-${m[2]}.${m[3]}` return model }