feat: add GitHub Copilot as a third provider#1
Open
rujaksoto wants to merge 1 commit intorizqme:mainfrom
Open
Conversation
Add support for GitHub Copilot subscriptions alongside the existing Claude MAX and ChatGPT providers. This enables routing API requests through Copilot using a GitHub OAuth device flow for authentication. New files: - copilot-oauth.ts: GitHub Device Flow OAuth (RFC 8628) - copilot-token-manager.ts: Token persistence to ~/.copilot-token.json Changes: - Router server: Copilot provider routing in all three endpoints (messages, chat/completions, responses) with required headers (Openai-Intent, x-initiator, Copilot-Vision-Request, User-Agent) - Model mapper: Copilot model mapping and responses API detection - CLI: auth copilot, logout copilot, verify, models, status commands - Legacy CLI: Copilot in auth/logout/verify menus - Types: Added copilot to Provider union Usage: code-router auth copilot code-router verify --provider copilot code-router serve Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
|
Please test in opencode:
Here example opencode provider |
Author
Testing Results with OpenCodeSetupCustom provider config in {
"provider": {
"coderouter": {
"npm": "@ai-sdk/openai-compatible",
"name": "Code Router",
"options": { "baseURL": "http://localhost:3344/v1" },
"models": {
"gpt-4.1": { "name": "GPT-4.1", "modalities": { "input": ["text", "image"], "output": ["text"] } },
"gpt-4o": { "name": "GPT-4o", "modalities": { "input": ["text", "image"], "output": ["text"] } },
"gpt-5-mini": { "name": "GPT-5 Mini", "modalities": { "input": ["text", "image"], "output": ["text"] } },
"claude-sonnet-4": { "name": "Claude Sonnet 4", "modalities": { "input": ["text", "image"], "output": ["text"] } }
}
}
}
}Copilot Supported Models (tested)
1. Text — ✅ Working2. Image Input — ✅ WorkingTested with a 100x100 red PNG: 3. Priority PrecedenceCurrent routing logic in
Key observation: When Copilot is the only provider, all models route through it correctly (GPT and Claude models alike). When multiple providers are configured, GPT models prefer OpenAI and Claude models prefer Anthropic — Copilot is only selected via explicit hint or as the sole provider. Manual override options:
Verbose Routing LogsWhen Copilot is the only configured provider, both GPT and Claude models correctly route through it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for GitHub Copilot subscriptions alongside the existing Claude MAX and ChatGPT providers. This enables routing API requests through Copilot using GitHub's Device Flow OAuth for authentication.
New Files
src/copilot-oauth.ts— GitHub Device Flow OAuth (RFC 8628) with device code request, polling, and browser auto-opensrc/copilot-token-manager.ts— Token persistence to~/.copilot-token.jsonwith load/save/validate helpersModified Files
src/router/server.ts— Full Copilot provider integration: auth state hydration, request headers (Openai-Intent,x-initiator,Copilot-Vision-Request,User-Agent), routing in all three endpoints (messages, chat/completions, responses), startup loggingsrc/router/model-mapper.ts— Copilot model mapping and responses API detection (shouldUseCopilotResponsesApifor GPT-5+ models)src/commands.ts— Copilot verify, models listing, OAuth, logout, and status snapshotsrc/bin/code-router.ts—auth copilot,logout copilotcommands, updated help textsrc/legacy-cli.ts— Copilot options in auth/logout/verify menussrc/types.ts— Added'copilot'toProviderunion typeUsage
API Details
https://api.githubcopilot.com(orhttps://copilot-api.<domain>for enterprise)Ov23li8tweQw6odWQebz)~/.copilot-token.json(mode 0600)Testing
tsc --noEmit)gpt-4oresponded correctly