Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f863e76
docs: Update warning message in README
ericc-ch Jun 17, 2025
e8e28ab
docs: fix ai writing
ericc-ch Jun 17, 2025
3aeaa8f
feat: better openai types
ericc-ch Jun 19, 2025
a8f5f22
feat: Add Anthropic API documentation and OpenAI mapping
ericc-ch Jun 20, 2025
6e0f213
refactor: Rename file and translate payload/response in one file
ericc-ch Jun 20, 2025
d3d0796
feat: Add Anthropic API translation and streaming support
ericc-ch Jun 20, 2025
95a4178
feat: Add support for "none" tool choice in Anthropic translation
ericc-ch Jun 20, 2025
6fb9c85
feat: Update Anthropic API documentation and types
ericc-ch Jun 20, 2025
4bf35ec
docs: Update mapping doc with latest API details and features
ericc-ch Jun 20, 2025
da1ad2e
chore: Updated dependencies hono and knip
ericc-ch Jun 20, 2025
44f733f
feat: Improve Anthropic message type handling and mapping
ericc-ch Jun 20, 2025
b94478e
feat: Add streaming support and examples for Anthropic messages API
ericc-ch Jun 20, 2025
7c175d6
feat: Translate OpenAI stream to Anthropic stream events
ericc-ch Jun 20, 2025
101f422
feat: Add message route and handler
ericc-ch Jun 20, 2025
2aab7d7
feat: Add Anthropic compatible endpoints
ericc-ch Jun 20, 2025
f8d1678
feat: Return available models from state
ericc-ch Jun 20, 2025
43dc70c
fix: Ensure models are cached before serving requests
ericc-ch Jun 20, 2025
f38b56f
docs: Update README with API endpoints, usage tips, and descriptions
ericc-ch Jun 20, 2025
8bce5dd
docs: Add CLAUDE.md for Claude Code guidance
ericc-ch Jun 20, 2025
7ddb97b
feat: Add Claude Code launch option and dependencies
ericc-ch Jun 20, 2025
bb390ba
feat: command generation, bc I cant spawn
ericc-ch Jun 20, 2025
6840eb8
feat: actual command gen
ericc-ch Jun 20, 2025
4d35806
feat: Add Claude Code integration and documentation
ericc-ch Jun 20, 2025
cf650c7
build: Add claude settings file
ericc-ch Jun 20, 2025
5a745a5
docs: Add instructions for Claude Code integration
ericc-ch Jun 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"ANTHROPIC_BASE_URL": "http://localhost:4141",
"ANTHROPIC_AUTH_TOKEN": "dummy",
"ANTHROPIC_MODEL": "gpt-4.1",
"ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1"
}
}
37 changes: 37 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Development Commands

- **Install dependencies**: `bun install`
- **Build**: `bun run build`
- **Dev server (watch)**: `bun run dev`
- **Production start**: `bun run start`
- **Lint**: `bun run lint`
- **Pre-commit lint/fix**: Runs automatically via git hooks (bunx eslint --fix)

## Architecture Overview

- **Entry point**: `src/main.ts` defines CLI subcommands (`start` and `auth`) for the Copilot API server and authentication flow.
- **Server**: `src/server.ts` sets up HTTP routes using Hono, maps OpenAI/Anthropic-compatible endpoints, and handles logging/cors.
- **Routes**: Handlers for chat completions, embeddings, models, and messages are under `src/routes/`, providing API endpoints compatible with OpenAI and Anthropic APIs.
- **Copilot communication**: `src/services/copilot/` contains methods for proxying requests (chat completions, model listing, embeddings) to the GitHub Copilot backend using user tokens.
- **Lib utilities**: `src/lib/` contains configuration, token, model caching, and error handling helpers.
- **Authentication**: `src/auth.ts` provides the CLI handler for authenticating with GitHub, managing required tokens, and persisting them locally.

## API Endpoints

- **OpenAI-compatible**:
- `POST /v1/chat/completions`
- `GET /v1/models`
- `POST /v1/embeddings`
- **Anthropic-compatible**:
- `POST /v1/messages`
- `POST /v1/messages/count_tokens`

## Other Notes

- Ensure Bun (>= 1.2.x) is installed for all scripts and local dev.
- Tokens and cache are handled automatically; manual authentication can be forced with the `auth` subcommand.
- No .cursorrules, .github/copilot-instructions.md, or .cursor/rules found, so follow typical TypeScript/Bun/ESLint conventions as seen in this codebase.
109 changes: 81 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copilot API
# Copilot API Proxy

⚠️ **EDUCATIONAL PURPOSE ONLY** ⚠️
This project is a reverse-engineered implementation of the GitHub Copilot API created for educational purposes only. It is not officially supported by GitHub and should not be used in production environments.
> [!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.

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E519XS7W)

## Project Overview

A wrapper around GitHub Copilot API to make it OpenAI compatible, making it usable for other tools like AI assistants, local interfaces, and development utilities.
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).

## Demo

Expand All @@ -16,7 +16,7 @@ https://github.com/user-attachments/assets/7654b383-669d-4eb9-b23c-06d7aefee8c5
## Prerequisites

- Bun (>= 1.2.x)
- GitHub account with Copilot subscription (Individual or Business)
- GitHub account with Copilot subscription (individual, business, or enterprise)

## Installation

Expand Down Expand Up @@ -64,7 +64,7 @@ npx copilot-api@latest auth

Copilot API now uses a subcommand structure with two main commands:

- `start`: Start the Copilot API server (default command). This command will also handle authentication if needed.
- `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.

## Command Line Options
Expand All @@ -73,22 +73,46 @@ Copilot API now uses a subcommand structure with two main commands:

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 |
| 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 |
| --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 |

### Auth Command Options

| Option | Description | Default | Alias |
| --------- | ---------------------- | ------- | ----- |
| --verbose | Enable verbose logging | false | -v |

## 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. |

## Example Usage

Using with npx:
Expand Down Expand Up @@ -125,6 +149,45 @@ npx copilot-api@latest auth
npx copilot-api@latest auth --verbose
```

## Using with Claude Code

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.

There are two ways to configure Claude Code to use this proxy:

### Interactive Setup with `--claude-code` flag

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.

Paste and run this command in a new terminal to launch Claude Code.

### Manual Configuration with `settings.json`

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_SMALL_FAST_MODEL": "gpt-4.1"
}
}
```

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:
Expand All @@ -143,18 +206,8 @@ bun run start

## Usage Tips

- Consider using free models (e.g., Gemini, Mistral, Openrouter) as the `weak-model`
- Use architect mode sparingly
- Disable `yes-always` in your aider configuration
- Enable the `--manual` flag to review and approve each request before processing
- 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 <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.
- `--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.

### Manual Request Approval

When using the `--manual` flag, the server will prompt you to approve each incoming request:

```
? Accept incoming request? > (y/N)
```

This helps you control usage and monitor requests in real-time.
Loading