Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8f6c468
feat: add GitHub Enterprise Server/Cloud support
jkorsvik Oct 13, 2025
32e948d
fix: use copilot-api subdomain for enterprise Copilot endpoints
jkorsvik Oct 13, 2025
6f07c56
chore: clean up docs and bump version to 0.8.0
jkorsvik Oct 13, 2025
ee4670a
refactor: clean up enterprise URL handling and simplify code patterns
jkorsvik Oct 13, 2025
151646e
feat: add AGENTS.md for build, lint, test commands and code style gui…
jkorsvik Oct 13, 2025
d9f3aad
Grafana
luisbrandao Oct 16, 2025
dc46615
Refactor code structure for improved readability and maintainability
luisbrandao Oct 28, 2025
265a2df
feat: include context size in token usage logs for chat completions
luisbrandao Oct 28, 2025
0f99cae
refactor: replace consola with console.log for token logging
luisbrandao Oct 28, 2025
1e6d259
feat: add tzdata installation for timezone support in Dockerfile
luisbrandao Oct 28, 2025
a7da48d
feat: add local timezone formatting for timestamps in chat completion…
luisbrandao Oct 28, 2025
29668ce
feat: support copilot reasoning_opaque and reasoning_text
caozhiyuan Nov 19, 2025
a2467d3
feat: add signature field to AnthropicThinkingBlock
caozhiyuan Nov 19, 2025
58f7a45
feat: add idleTimeout configuration for bun server
caozhiyuan Nov 19, 2025
3fa5519
feat: enhance reasoning handling in tool calls and change the thinkin…
caozhiyuan Nov 19, 2025
dfb40d2
feat: conditionally handle reasoningOpaque in handleFinish based on t…
caozhiyuan Nov 19, 2025
7657d87
fix: handleReasoningOpaqueInToolCalls add isToolBlockOpen judge
caozhiyuan Nov 20, 2025
968ff12
merge: integrate chat-completions-reasoning support
jkorsvik Nov 25, 2025
9b3f737
Merge branch 'feat/enterprise-and-reasoning'
luisbrandao Feb 19, 2026
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
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.0] - 2025-01-31

### Added
- GitHub Enterprise Server/Cloud support
- New `--enterprise-url` flag for `auth` and `start` commands
- Interactive prompt during auth for enterprise configuration
- Persistent enterprise URL storage in `~/.local/share/copilot-api/enterprise_url`
- Automatic endpoint routing for enterprise instances
- Comprehensive test suite with 41 new tests covering enterprise functionality
- URL normalization utilities for enterprise host configuration

### Changed
- OAuth endpoints now use enterprise URLs when configured
- Copilot API endpoints route to `copilot-api.{enterprise}` for enterprise users
- GitHub API endpoints route to `api.{enterprise}` for enterprise users

### Technical Details
- Enterprise endpoint structure:
- OAuth: `https://{enterprise}/login/...`
- GitHub API: `https://api.{enterprise}/...`
- Copilot API: `https://copilot-api.{enterprise}/...`
- 100% backwards compatible - defaults to github.com when no enterprise configured

## [0.7.0] - Previous Release
- See git history for details
41 changes: 41 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# CLAUDE.md

This file provides guidance to Claude Code when working with this repository.

## Overview

TypeScript CLI application using Bun runtime that exposes GitHub Copilot as OpenAI/Anthropic-compatible APIs.

## Commands

- `bun install` - Install dependencies
- `bun run build` - Build distribution
- `bun run dev` - Development with watch mode
- `bun run start` - Production start
- `bun run lint` - Lint code
- `bun run typecheck` - Type checking
- `bun test` - Run tests

## Architecture

- **Entry**: `src/main.ts` - CLI definition with subcommands (auth, start, check-usage, debug)
- **Server**: `src/start.ts` - Orchestrates initialization and HTTP server
- **Routes**: `src/routes/` - OpenAI & Anthropic compatible endpoints
- **Services**:
- `src/services/github/` - GitHub OAuth and token management
- `src/services/copilot/` - Copilot API interactions
- **Utilities**: `src/lib/` - State management, paths, token handling

## GitHub Enterprise Support

- Use `--enterprise-url` flag for GHE Server/Cloud
- Interactive prompt during auth if no flag provided
- Enterprise URL persisted in `~/.local/share/copilot-api/enterprise_url`
- Endpoints: `https://{enterprise}/...` for OAuth, `https://api.{enterprise}/...` for GitHub API, `https://copilot-api.{enterprise}/...` for Copilot

## Key Files

- CLI flags: `src/start.ts:123`, `src/main.ts:10`
- Routes: `src/server.ts`, `src/routes/*`
- Models: `src/services/copilot/get-models.ts`
- Token storage: `src/lib/paths.ts`, `src/lib/token.ts`
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ RUN bun run build
FROM oven/bun:1.2.19-alpine AS runner
WORKDIR /app

# Install tzdata for timezone support
RUN apk add --no-cache tzdata

COPY ./package.json ./bun.lock ./
RUN bun install --frozen-lockfile --production --ignore-scripts --no-cache

Expand Down
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ A reverse-engineered proxy for the GitHub Copilot API that exposes it as an Open
- **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.
- **GitHub Enterprise Support**: Compatible with GitHub Enterprise Server and GitHub Enterprise Cloud installations.

## Demo

Expand Down Expand Up @@ -163,13 +164,15 @@ The following command line options are available for the `start` command:
| --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 |
| --enterprise-url | GitHub Enterprise host to use (eg. https://ghe.example.com) | none | none |

### Auth Command Options

| Option | Description | Default | Alias |
| ------------ | ------------------------- | ------- | ----- |
| --verbose | Enable verbose logging | false | -v |
| --show-token | Show GitHub token on auth | false | none |
| --enterprise-url | GitHub Enterprise host (eg. https://ghe.example.com) | none | none |

### Debug Command Options

Expand Down Expand Up @@ -204,10 +207,35 @@ These endpoints are designed to be compatible with the Anthropic Messages API.

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. |
| 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. |
| `GET /metrics`| `GET` | Prometheus metrics endpoint exposing token usage per model. |

### Prometheus Metrics

The `/metrics` endpoint exposes Prometheus-compatible metrics for monitoring token usage:

**Available Metrics:**
- `copilot_api_tokens_in_total` - Total input tokens processed per model
- `copilot_api_tokens_out_total` - Total output tokens generated per model
- `copilot_api_requests_total` - Total number of requests per model and endpoint

Example metrics output:
```
# HELP copilot_api_tokens_in_total Total number of input tokens processed per model
# TYPE copilot_api_tokens_in_total counter
copilot_api_tokens_in_total{model="gpt-4o"} 1523

# HELP copilot_api_tokens_out_total Total number of output tokens generated per model
# TYPE copilot_api_tokens_out_total counter
copilot_api_tokens_out_total{model="gpt-4o"} 342

# HELP copilot_api_requests_total Total number of requests per model
# TYPE copilot_api_requests_total counter
copilot_api_requests_total{model="gpt-4o",endpoint="chat-completions"} 15
```

## Example Usage

Expand Down Expand Up @@ -255,6 +283,15 @@ npx copilot-api@latest debug --json

# Initialize proxy from environment variables (HTTP_PROXY, HTTPS_PROXY, etc.)
npx copilot-api@latest start --proxy-env

# Use GitHub Enterprise / GitHub Enterprise Server
npx copilot-api@latest start --account-type enterprise --enterprise-url https://ghe.example.com

# Authenticate with GitHub Enterprise interactively (will prompt for enterprise host)
npx copilot-api@latest auth

# Authenticate with GitHub Enterprise using CLI flag (for scripting)
npx copilot-api@latest auth --enterprise-url ghe.example.com
```

## Using the Usage Viewer
Expand Down Expand Up @@ -349,3 +386,8 @@ bun run start
- `--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.
- For GitHub Enterprise Server/Cloud users: Use `--enterprise-url` to specify your enterprise host (e.g., `--enterprise-url https://ghe.example.com`). The interactive auth command (`copilot-api auth`) will prompt you for your enterprise host if you don't provide it via the CLI flag.



export ANTHROPIC_BASE_URL=http://localhost:4141 ANTHROPIC_AUTH_TOKEN=dummy ANTHROPIC_MODEL=claude-sonnet-4.5 ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4.5 ANTHROPIC_SMALL_FAST_MODEL=gpt-5-mini ANTHROPIC_DEFAULT_HAIKU_MODEL=gpt-5-mini DISABLE_NON_ESSENTIAL_MODEL_CALLS=1 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 && claude
9 changes: 9 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading