{"id":49564882,"url":"https://github.com/anshulpatel25/copilot-sdk-gateway","last_synced_at":"2026-05-03T11:11:30.725Z","repository":{"id":342562310,"uuid":"1171527786","full_name":"anshulpatel25/copilot-sdk-gateway","owner":"anshulpatel25","description":"Open AI API compatible gateway for copilot-sdk","archived":false,"fork":false,"pushed_at":"2026-05-01T04:26:42.000Z","size":579,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-01T06:27:10.372Z","etag":null,"topics":["copilot-sdk","openai","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anshulpatel25.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-03-03T10:28:32.000Z","updated_at":"2026-05-01T04:26:42.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/anshulpatel25/copilot-sdk-gateway","commit_stats":null,"previous_names":["anshulpatel25/copilot-sdk-gateway"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/anshulpatel25/copilot-sdk-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshulpatel25%2Fcopilot-sdk-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshulpatel25%2Fcopilot-sdk-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshulpatel25%2Fcopilot-sdk-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshulpatel25%2Fcopilot-sdk-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anshulpatel25","download_url":"https://codeload.github.com/anshulpatel25/copilot-sdk-gateway/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshulpatel25%2Fcopilot-sdk-gateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32566480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["copilot-sdk","openai","python"],"created_at":"2026-05-03T11:11:28.881Z","updated_at":"2026-05-03T11:11:30.716Z","avatar_url":"https://github.com/anshulpatel25.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# copilot-sdk-gateway\n\nAn **OpenAI-API-compatible HTTP proxy** that forwards inference requests to the GitHub Copilot backend via the [GitHub Copilot Python SDK](https://github.com/github/copilot-sdk).\n\n## Architecture\n\n```\nOpenAI-API-compatible client  (e.g. Open WebUI, Continue, Aider)\n        │\n        ▼  HTTP  (Ollama wire format, port 11434)\ncopilot-sdk-gateway\n        │\n        ▼  github-copilot-sdk (Python)\n  Copilot CLI  (spawned per request)\n        │\n        ▼\n  GitHub Copilot / LLM backend\n```\n\nKey design decisions:\n\n- **Per-request isolation** — every HTTP request creates its own `CopilotClient` + session.  No shared mutable state between concurrent calls.\n- **Streaming emulation** — `session.send_and_wait()` fetches the full response; it is then split into word-level chunks and delivered as NDJSON.\n- **Model ID normalisation** — any `:tag` suffix (e.g. `:latest`) is stripped before forwarding to the SDK.\n- **12-factor config** — all configuration from environment variables; no hardcoded secrets.\n\n---\n\n## Prerequisites\n\n| Requirement | Notes |\n|---|---|\n| Python 3.12+ | |\n| [`uv`](https://docs.astral.sh/uv/) | Project / dependency manager |\n| [Copilot CLI](https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli) | `copilot` must be on `PATH` (or set `COPILOT_CLI_PATH`) |\n| GitHub Copilot subscription | Required for non-BYOK usage |\n\n---\n\n## Quick Start\n\n```bash\n# 1. Clone and enter the repo\ngit clone https://github.com/anshulpatel25/copilot-sdk-gateway\ncd copilot-sdk-gateway\n\n# 2. Install dependencies (creates .venv automatically)\nuv sync\n\n# 3. Configure (optional — sensible defaults for local dev)\nexport GITHUB_TOKEN=\"ghp_...\"   # or rely on `copilot auth login`\n\n# 4. Run the gateway\nuv run python -m copilot_sdk_gateway.main\n# → Listening on http://0.0.0.0:11434\n```\n\nPoint any OpenAI-API-compatible client at `http://localhost:11434`.\n\n---\n\n## Configuration Reference\n\nAll settings are read from environment variables (and optionally from a `.env` file).\n\n| Variable | Default | Description |\n|---|---|---|\n| `PORT` | `11434` | TCP port to listen on |\n| `GITHUB_TOKEN` | `\"\"` | GitHub personal access token; empty = fall back to `copilot auth login` |\n| `COPILOT_CLI_PATH` | `\"\"` | Absolute path to the `copilot` binary; empty = locate on `PATH` |\n| `COPILOT_CLI_URL` | `\"\"` | Connect to an already-running CLI server (`host:port`); when set, `COPILOT_CLI_PATH` is ignored |\n| `LOG_LEVEL` | `error` | Logging verbosity (`debug`, `info`, `warning`, `error`) |\n| `INFERENCE_TIMEOUT` | `300.0` | Seconds to wait for the Copilot session to become idle before raising a `TimeoutError`; increase for slow or long-running models |\n\n---\n\n## API Reference\n\n### `GET /api/version`\n\nReturns the gateway version.\n\n```bash\ncurl http://localhost:11434/api/version\n# {\"version\":\"0.1.0\"}\n```\n\n---\n\n### `GET /api/tags`\n\nLists available Copilot models in Ollama `tags` format.\n\n```bash\ncurl http://localhost:11434/api/tags\n```\n\n```json\n{\n  \"models\": [\n    {\n      \"name\": \"gpt-4o:latest\",\n      \"model\": \"gpt-4o:latest\",\n      \"modified_at\": \"2025-01-01T00:00:00Z\",\n      \"size\": 0,\n      \"digest\": \"\",\n      \"details\": {}\n    }\n  ]\n}\n```\n\n---\n\n### `POST /api/chat`\n\nMulti-turn chat completion.\n\n```bash\ncurl http://localhost:11434/api/chat \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"gpt-4o\",\n    \"messages\": [\n      {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n      {\"role\": \"user\",   \"content\": \"What is the capital of France?\"}\n    ]\n  }'\n```\n\n**Streaming:**\n\n```bash\ncurl http://localhost:11434/api/chat \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"gpt-4o\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"Count to five.\"}],\n    \"stream\": true\n  }'\n```\n\n---\n\n### `POST /api/generate`\n\nSingle-turn text generation.\n\n```bash\ncurl http://localhost:11434/api/generate \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\": \"gpt-4o\", \"prompt\": \"Why is the sky blue?\"}'\n```\n\n**Streaming:**\n\n```bash\ncurl http://localhost:11434/api/generate \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\": \"gpt-4o\", \"prompt\": \"Write a haiku.\", \"stream\": true}'\n```\n\n---\n\n## Observability / Metrics\n\nThe gateway exposes a Prometheus scrape endpoint at **`GET /metrics`** (powered by\n[`prometheus-fastapi-instrumentator`](https://github.com/trallnag/prometheus-fastapi-instrumentator)).\n\n### Available metrics\n\n#### Standard HTTP metrics (provided automatically by the instrumentator)\n\n| Metric | Type | Description |\n|---|---|---|\n| `http_requests_total` | Counter | Total HTTP requests by `handler`, `status`, `method` |\n| `http_request_size_bytes` | Summary | Incoming request content-length by `handler` |\n| `http_response_size_bytes` | Summary | Outgoing response content-length by `handler` |\n| `http_request_duration_seconds` | Histogram | Request latency by `handler` and `method` |\n| `http_request_duration_highr_seconds` | Histogram | High-resolution latency (no labels) |\n\n#### Custom business metrics\n\n| Metric | Type | Labels | Description |\n|---|---|---|---|\n| `completions_total` | Counter | `model`, `endpoint` | Successful inference completions |\n| `prompt_length_chars` | Histogram | `endpoint` | Prompt length in characters |\n| `response_length_chars` | Histogram | `endpoint` | Response length in characters |\n\nMetrics are recorded **only on successful completions** — errors do not increment any counter or histogram.\n\n### Scraping with Prometheus\n\nAdd a scrape job to your `prometheus.yml`:\n\n```yaml\nscrape_configs:\n  - job_name: copilot-sdk-gateway\n    static_configs:\n      - targets: [\"localhost:11434\"]\n    metrics_path: /metrics\n```\n\n### Example queries (PromQL)\n\n```promql\n# Completion rate per model over the last 5 minutes\nrate(completions_total[5m])\n\n# 95th-percentile response length per endpoint\nhistogram_quantile(0.95, sum by (le, endpoint) (rate(response_length_chars_bucket[5m])))\n\n# Average prompt length per endpoint\nrate(prompt_length_chars_sum[5m]) / rate(prompt_length_chars_count[5m])\n\n# HTTP error rate (5xx) per handler\nsum by (handler) (rate(http_requests_total{status=\"5xx\"}[5m]))\n```\n\n### Verifying locally\n\n```bash\ncurl http://localhost:11434/metrics\n```\n\nYou should see output like:\n\n```\n# HELP completions_total Total number of successful completions\n# TYPE completions_total counter\ncompletions_total{endpoint=\"/api/chat\",model=\"gpt-4o\"} 3.0\n# HELP prompt_length_chars Length of prompt in characters\n# TYPE prompt_length_chars histogram\nprompt_length_chars_bucket{endpoint=\"/api/chat\",le=\"0.005\"} 0.0\n...\n```\n\n---\n\n## Development Setup\n\n```bash\n# Install all dependencies (including dev)\nuv sync\n\n# Run tests\nuv run pytest\n\n# Lint\nuv run ruff check copilot_sdk_gateway/ tests/\n\n# Auto-fix lint issues\nuv run ruff check --fix copilot_sdk_gateway/ tests/\n\n# Start the server in development mode (auto-reload)\nuv run uvicorn copilot_sdk_gateway.main:create_app \\\n    --factory --reload --port 11434\n```\n\n---\n\n## License\n\nMIT — see [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshulpatel25%2Fcopilot-sdk-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanshulpatel25%2Fcopilot-sdk-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshulpatel25%2Fcopilot-sdk-gateway/lists"}