Sign inSign up

onklave/copilot-api

By onklave

•Updated 23 days ago

GitHub Copilot (incl. *.ghe.com) as an OpenAI/Anthropic-compatible API server for Claude Code

Image
0

655

onklave/copilot-api repository overview

⁠@onklave/copilot-api

Expose a GitHub Copilot subscription as an OpenAI/Anthropic-compatible API server — including Copilot accounts on GitHub Enterprise Cloud with data residency (*.ghe.com). Point Claude Code (or any OpenAI/Anthropic-compatible client) at it and use your Copilot entitlement as the model backend.

This is an Onklave-maintained derivative of ericc-ch/copilot-api⁠ (forked at v0.7.0, commit 0ea08feb, MIT — see NOTICE). What it adds over upstream:

  • --github-host / $GH_HOST — authenticate against a GHE Cloud data-residency tenant (acme.ghe.com) instead of github.com. Device-flow login, the Copilot token exchange, and usage queries all route to the tenant.
  • Self-configuring inference endpoint — the Copilot token exchange returns per-tenant service endpoints; the server honours endpoints.api (e.g. https://copilot-api.acme.ghe.com) instead of assuming api.githubcopilot.com, so data-residency traffic stays regional.
  • Per-host credential storage — a github.com login and a tenant login coexist under ~/.local/share/onklave-copilot-api/.

⁠Quickstart

npx @onklave/copilot-api start

First run walks you through GitHub device-flow login, then serves on http://localhost:4141.

⁠GitHub Enterprise Cloud (*.ghe.com)
# One-time login against your tenant
npx @onklave/copilot-api auth --github-host acme.ghe.com

# Run the server against the tenant (or: export GH_HOST=acme.ghe.com)
npx @onklave/copilot-api start --github-host acme.ghe.com

If your tenant blocks the device flow, generate an OAuth token on the tenant and pass it with --github-token instead.

⁠Docker
docker run -it -p 4141:4141 \
  -v copilot-api-data:/home/node/.local/share/onklave-copilot-api \
  onklave/copilot-api start --github-host acme.ghe.com

First run prints the device-flow code in the container logs; the named volume keeps the token across restarts. Pass any start flags after the image name (e.g. --github-token on tenants without device flow). Images are published to onklave/copilot-api⁠ on Docker Hub alongside each npm release, tagged latest and the package version.

Corporate proxies: the standard HTTPS_PROXY/HTTP_PROXY/NO_PROXY environment variables are honoured automatically by every command — no flag needed. If auth times out connecting to your tenant on a managed machine, check env | grep -i proxy and make sure your proxy variables are set in that shell.

⁠Connecting Claude Code

Interactive — pick models and get a ready-to-paste launch command:

npx @onklave/copilot-api start --github-host acme.ghe.com --claude-code

Manual:

export ANTHROPIC_BASE_URL=http://localhost:4141
export ANTHROPIC_AUTH_TOKEN=dummy
# Optional — pin models; without these, unknown claude-* IDs are
# auto-mapped to your account's models (see Model mapping below)
export ANTHROPIC_MODEL=claude-sonnet-5
export ANTHROPIC_SMALL_FAST_MODEL=claude-haiku-4.5
claude

The server implements Anthropic's /v1/messages (streaming and count_tokens included) plus OpenAI-style /v1/chat/completions, /v1/models, and /v1/embeddings.

Model mapping: Claude Code's default settings request Anthropic's own model IDs (e.g. claude-haiku-4-5-20251001 for background calls), which Copilot serves under different names (claude-haiku-4.5). When a requested claude-* model isn't in your account's model list, the server automatically substitutes the same family — haiku-class requests get the available haiku model, everything else gets the strongest non-haiku Claude — and logs the substitution. Claude Code therefore works with no model configuration at all; pin exact models with the --claude-code picker or the ANTHROPIC_MODEL/ANTHROPIC_SMALL_FAST_MODEL env vars if you want control.

⁠Commands and flags

CommandPurpose
startRun the API server (default port 4141)
authDevice-flow login only
check-usageShow Copilot quota/usage for the account
debugPrint version, paths, and token status

Key start flags (see --help for all): --port, --github-host, --account-type individual|business|enterprise, --github-token, --claude-code, --rate-limit <s> (+ --wait), --manual (approve each request), --proxy-env.

All commands accept --github-host; when omitted, $GH_HOST is used, then github.com.

Quota/usage for the signed-in account is served as JSON at http://localhost:4141/usage (same data as check-usage).

⁠Caveats

  • This uses Copilot's internal editor API (reverse-engineered, as upstream). It is not a GitHub-supported integration surface; use it with your own account, within your organization's policies and GitHub's terms.
  • Excessive automated traffic can trip Copilot abuse detection — consider --rate-limit for agent workloads.
  • Requires Node >= 20.

⁠Development

Self-contained package (own package-lock.json, not part of the monorepo's Nx graph):

npm install
npm run typecheck && npm test && npm run build
node dist/main.js start

Published to npm (and as a Docker image to docker.io/onklave/copilot-api) by .github/workflows/publish-libs.yaml on merge to main.

⁠License

Apache-2.0 (see LICENSE). Derived from MIT-licensed ericc-ch/copilot-api⁠; the original license and copyright are preserved in NOTICE.

Tag summary

Content type

Image

Digest

sha256:8d1975102…

Size

79.5 MB

Last updated

23 days ago

docker pull onklave/copilot-api