# alorse/copilot-to-api architecture

> Architecture diagram of the GitHub repository alorse/copilot-to-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alorse/copilot-to-api
- Repository: https://github.com/alorse/copilot-to-api

## Overview

The repository offers two ways to use Copilot: command-line clients and OpenAI-compatible web APIs, with Node.js and Python implementations. Web requests are handled either by servers that translate model/chat operations or by a Node.js transparent proxy; both obtain short-lived Copilot tokens using a configured GitHub access token. The README also documents manual device authorization and direct API usage, but the device-code flow is not implemented in the sampled runtime files. Edges reflect the excerpts and README; the Python web server and proxy excerpts are partial.

Main entry points: [`copilot-client.js`](https://github.com/alorse/copilot-to-api/blob/main/copilot-client.js) (Node Copilot client), [`copilot_client.py`](https://github.com/alorse/copilot-to-api/blob/main/copilot_client.py) (Python Copilot client), [`server.js`](https://github.com/alorse/copilot-to-api/blob/main/server.js) (Node Copilot API), [`server.py`](https://github.com/alorse/copilot-to-api/blob/main/server.py) (Python Copilot API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI clients"]
  node_node_cli["Node CLI<br/>[copilot-client.js]"]
  node_node_cli_api["Node Copilot client<br/>[copilot-client.js]"]
  node_python_cli["Python CLI<br/>[copilot_client.py]"]
  node_python_cli_api["Python Copilot client<br/>[copilot_client.py]"]
end

subgraph group_web["Web API servers"]
  node_node_routes["Node API routes<br/>[server.js]"]
  node_node_api["Node Copilot API<br/>[server.js]"]
  node_python_routes["Python API routes<br/>[server.py]"]
  node_python_api["Python Copilot API<br/>[server.py]"]
end

subgraph group_proxy["Proxy server"]
  node_proxy_routes["Proxy routes<br/>[server-proxy.js]"]
  node_token_manager["Token manager<br/>[server-proxy.js]"]
end

subgraph group_upstream["GitHub Copilot"]
  node_github_auth["GitHub token endpoint"]
  node_copilot_models["Copilot models API"]
  node_copilot_chat["Copilot chat API"]
end

node_cli_user(("CLI user"))
node_api_caller(("API caller"))

node_cli_user -->|"runs commands"| node_node_cli
node_node_cli -->|"calls"| node_node_cli_api
node_node_cli_api -->|"refreshes token"| node_github_auth
node_node_cli_api -->|"requests models"| node_copilot_models
node_node_cli_api -->|"sends completions"| node_copilot_chat
node_cli_user -->|"runs commands"| node_python_cli
node_python_cli -->|"calls"| node_python_cli_api
node_python_cli_api -->|"refreshes token"| node_github_auth
node_python_cli_api -->|"requests models"| node_copilot_models
node_python_cli_api -->|"sends completions"| node_copilot_chat
node_api_caller -->|"sends HTTP requests"| node_node_routes
node_node_routes -->|"dispatches operations"| node_node_api
node_node_api -->|"refreshes token"| node_github_auth
node_node_api -->|"requests models"| node_copilot_models
node_node_api -->|"sends completions"| node_copilot_chat
node_api_caller -->|"sends HTTP requests"| node_python_routes
node_python_routes -->|"dispatches operations"| node_python_api
node_python_api -->|"refreshes token"| node_github_auth
node_python_api -->|"requests models"| node_copilot_models
node_python_api -->|"sends completions"| node_copilot_chat
node_api_caller -->|"sends HTTP requests"| node_proxy_routes
node_proxy_routes -->|"gets valid token"| node_token_manager
node_token_manager -->|"refreshes token"| node_github_auth
node_proxy_routes -->|"proxies requests"| node_copilot_models
node_proxy_routes -->|"proxies requests"| node_copilot_chat

click node_node_cli "https://github.com/alorse/copilot-to-api/blob/main/copilot-client.js"
click node_node_cli_api "https://github.com/alorse/copilot-to-api/blob/main/copilot-client.js"
click node_python_cli "https://github.com/alorse/copilot-to-api/blob/main/copilot_client.py"
click node_python_cli_api "https://github.com/alorse/copilot-to-api/blob/main/copilot_client.py"
click node_node_routes "https://github.com/alorse/copilot-to-api/blob/main/server.js"
click node_node_api "https://github.com/alorse/copilot-to-api/blob/main/server.js"
click node_python_routes "https://github.com/alorse/copilot-to-api/blob/main/server.py"
click node_python_api "https://github.com/alorse/copilot-to-api/blob/main/server.py"
click node_proxy_routes "https://github.com/alorse/copilot-to-api/blob/main/server-proxy.js"
click node_token_manager "https://github.com/alorse/copilot-to-api/blob/main/server-proxy.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_cli,node_node_cli_api,node_python_cli,node_python_cli_api,node_cli_user toneBlue
class node_node_routes,node_node_api,node_python_routes,node_python_api toneAmber
class node_proxy_routes,node_token_manager,node_api_caller toneMint
class node_github_auth,node_copilot_models,node_copilot_chat toneRose
```

## Components

### CLI clients

- [Node CLI](https://github.com/alorse/copilot-to-api/blob/main/copilot-client.js): `copilot-client.js`
- [Node Copilot client](https://github.com/alorse/copilot-to-api/blob/main/copilot-client.js): `copilot-client.js`
- [Python CLI](https://github.com/alorse/copilot-to-api/blob/main/copilot_client.py): `copilot_client.py`
- [Python Copilot client](https://github.com/alorse/copilot-to-api/blob/main/copilot_client.py): `copilot_client.py`

### Web API servers

- [Node API routes](https://github.com/alorse/copilot-to-api/blob/main/server.js): `server.js`
- [Node Copilot API](https://github.com/alorse/copilot-to-api/blob/main/server.js): `server.js`
- [Python API routes](https://github.com/alorse/copilot-to-api/blob/main/server.py): `server.py`
- [Python Copilot API](https://github.com/alorse/copilot-to-api/blob/main/server.py): `server.py`

### Proxy server

- [Proxy routes](https://github.com/alorse/copilot-to-api/blob/main/server-proxy.js): `server-proxy.js`
- [Token manager](https://github.com/alorse/copilot-to-api/blob/main/server-proxy.js): `server-proxy.js`

### GitHub Copilot

- **GitHub token endpoint**
- **Copilot models API**
- **Copilot chat API**

### Other components

- **CLI user**
- **API caller**

## Connections

- CLI user → Node CLI: runs commands (evidence: `README.md`)
- Node CLI → Node Copilot client: calls (evidence: `copilot-client.js`)
- Node Copilot client → GitHub token endpoint: refreshes token (evidence: `copilot-client.js`)
- Node Copilot client → Copilot models API: requests models (evidence: `copilot-client.js`)
- Node Copilot client → Copilot chat API: sends completions (evidence: `copilot-client.js`)
- CLI user → Python CLI: runs commands (evidence: `README.md`)
- Python CLI → Python Copilot client: calls (evidence: `copilot_client.py`)
- Python Copilot client → GitHub token endpoint: refreshes token (evidence: `copilot_client.py`)
- Python Copilot client → Copilot models API: requests models (evidence: `copilot_client.py`)
- Python Copilot client → Copilot chat API: sends completions (evidence: `copilot_client.py`)
- API caller → Node API routes: sends HTTP requests (evidence: `README.md`)
- Node API routes → Node Copilot API: dispatches operations (evidence: `server.js`)
- Node Copilot API → GitHub token endpoint: refreshes token (evidence: `server.js`)
- Node Copilot API → Copilot models API: requests models (evidence: `server.js`)
- Node Copilot API → Copilot chat API: sends completions (evidence: `server.js`)
- API caller → Python API routes: sends HTTP requests (evidence: `README.md`)
- Python API routes → Python Copilot API: dispatches operations (evidence: `server.py`)
- Python Copilot API → GitHub token endpoint: refreshes token (evidence: `server.py`)
- Python Copilot API → Copilot models API: requests models (evidence: `server.py`)
- Python Copilot API → Copilot chat API: sends completions (evidence: `server.py`)
- API caller → Proxy routes: sends HTTP requests (evidence: `README.md`)
- Proxy routes → Token manager: gets valid token (evidence: `server-proxy.js`)
- Token manager → GitHub token endpoint: refreshes token (evidence: `server-proxy.js`)
- Proxy routes → Copilot models API: proxies requests (evidence: `server-proxy.js`)
- Proxy routes → Copilot chat API: proxies requests (evidence: `server-proxy.js`)
