{"id":50263938,"url":"https://github.com/yansircc/llm-broker","last_synced_at":"2026-05-27T12:33:35.449Z","repository":{"id":339323333,"uuid":"1160833743","full_name":"yansircc/llm-broker","owner":"yansircc","description":"LLM account orchestration broker for Claude Code and Codex CLI.","archived":false,"fork":false,"pushed_at":"2026-05-14T08:26:42.000Z","size":15291,"stargazers_count":1,"open_issues_count":6,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-14T10:33:52.832Z","etag":null,"topics":["claude","codex","golang","llm","oauth","orchestration","relay","sqlite"],"latest_commit_sha":null,"homepage":"https://ccc.210k.cc","language":"Go","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/yansircc.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-02-18T12:30:35.000Z","updated_at":"2026-05-14T08:26:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yansircc/llm-broker","commit_stats":null,"previous_names":["yansircc/cc-relayer"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yansircc/llm-broker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yansircc%2Fllm-broker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yansircc%2Fllm-broker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yansircc%2Fllm-broker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yansircc%2Fllm-broker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yansircc","download_url":"https://codeload.github.com/yansircc/llm-broker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yansircc%2Fllm-broker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33566872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["claude","codex","golang","llm","oauth","orchestration","relay","sqlite"],"created_at":"2026-05-27T12:33:29.552Z","updated_at":"2026-05-27T12:33:35.442Z","avatar_url":"https://github.com/yansircc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# broker\n\n[![CI](https://github.com/yansircc/llm-broker/actions/workflows/ci.yml/badge.svg)](https://github.com/yansircc/llm-broker/actions/workflows/ci.yml)\n\n`broker` is a personal VPS relay for Claude Code and Codex CLI. The repository name is `llm-broker`. In the current architecture it is closer to an LLM account orchestration kernel than a thin proxy: it schedules a small pool of OAuth accounts, keeps identity boundaries intact, manages token refresh, and exposes one stable relay surface.\n\n## Architecture\n\nThe system is built around one rule: provider is the change axis.\n\nCore code stays provider-agnostic. Provider behavior lives behind `driver.Driver`.\n\n```text\nRelay(req, drv) =\n  retry(N) {\n    a \u003c- pool.Pick(drv, model, boundSession)\n    t \u003c- tokens.Ensure(a)\n    u \u003c- drv.BuildRequest(req, a, t)\n    r \u003c- upstream(u)\n    e \u003c- drv.Interpret(r)\n    pool.Observe(a, e)\n    surface.Write(drv, r)\n  }\n```\n\nUseful mental model:\n\n- `driver` translates provider protocol into stable core semantics.\n- `pool` is a synchronous state machine, not a provider parser.\n- `tokens` owns access-token freshness.\n- `relay` is a provider-neutral execution pipeline.\n- `events` are observational side effects, not source of truth.\n\nTwo formulas matter:\n\n```text\nidentity(account) = (provider, subject)\n\navailable(account, model, now) =\n  status == active\n  AND cooldown_until \u003c= now\n  AND driver.CanServe(provider_state_json, model, now)\n```\n\nThat is why:\n\n- `email` is display data, not account identity.\n- `(provider, subject)` is the durable uniqueness boundary.\n- provider-specific rate-limit and health state lives in `provider_state_json`, not public schema columns.\n\n## Current Surface\n\n- UI: `/` and `/dashboard`\n- Add account: `/add-account/{provider}`\n- Relay metadata: `GET /v1/models` (authenticated)\n- Claude relay paths: exposed from the Claude driver\n- Codex relay paths: exposed from the Codex driver\n- Dead routes by design: `/ui/*`, `/add-account`\n\n## Features\n\n- Multi-account scheduling for a small OAuth account pool\n- Per-provider drivers with explicit boundaries\n- Session binding for providers that need conversation stickiness\n- Per-account proxy support via a shared transport pool\n- Token refresh via `internal/tokens`\n- Built-in dashboard, account admin, user management, and usage views\n- Explicit DB migration command\n- Snapshot-friendly deployment and restore workflow\n\n## Quick Start\n\n### 1. Build\n\n```bash\ngit clone https://github.com/yansircc/llm-broker.git\ncd llm-broker\ncd web \u0026\u0026 npm ci \u0026\u0026 npm run build \u0026\u0026 cd ..\ngo build -o llm-broker ./cmd/relay\n```\n\nRequires:\n\n- Go 1.24+\n- Node 22+\n\n### 2. Create the schema\n\n```bash\n./llm-broker migrate\n```\n\nSchema migration is explicit. Startup does not mutate the database.\n\n### 3. Start the server\n\n```bash\nexport ENCRYPTION_KEY=$(openssl rand -hex 16)\nexport API_TOKEN=$(openssl rand -hex 16)\n\n./llm-broker\n```\n\nDefaults:\n\n- listen: `0.0.0.0:3000`\n- SQLite: `./llm-broker.db`\n\n### 4. Add accounts\n\nOpen the UI:\n\n- `http://YOUR_SERVER:3000/`\n\nOr use the admin API:\n\n```bash\ncurl -X POST \"http://YOUR_SERVER:3000/admin/accounts/generate-auth-url?provider=claude\" \\\n  -H \"Authorization: Bearer $API_TOKEN\"\n```\n\nThen exchange the callback:\n\n```bash\ncurl -X POST \"http://YOUR_SERVER:3000/admin/accounts/exchange-code\" \\\n  -H \"Authorization: Bearer $API_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"provider\": \"claude\",\n    \"session_id\": \"SESSION_ID\",\n    \"callback_url\": \"https://...\"\n  }'\n```\n\n### 5. Point clients at the relay\n\nClaude Code:\n\n```bash\nexport ANTHROPIC_BASE_URL=\"http://YOUR_SERVER:3000\"\nexport ANTHROPIC_API_KEY=\"$API_TOKEN\"\nclaude\n```\n\nCodex CLI:\n\n```bash\nexport OPENAI_BASE_URL=\"http://YOUR_SERVER:3000/openai\"\nexport OPENAI_API_KEY=\"$API_TOKEN\"\ncodex\n```\n\n### 6. Verify a key\n\nUse a copy-paste-safe shell form:\n\n```bash\nBASE_URL=\"https://ccc.210k.cc\"\nAPI_KEY=\"tk_...\"\n\ncurl -fsS \"$BASE_URL/v1/models\" \\\n  -H \"Authorization: Bearer $API_KEY\" \\\n  \u003e/dev/null \u0026\u0026 echo \"key ok\"\n```\n\n`/v1/models` is authenticated on purpose, so this is a meaningful smoke test.\n\n## Data Model\n\n`accounts` keeps only core fields plus two provider-owned JSON pockets:\n\n- `identity_json`: durable provider identity metadata for display and admin flows\n- `provider_state_json`: mutable provider runtime state such as utilization windows or cooldown signals\n\nCore account columns:\n\n- `id`\n- `provider`\n- `subject`\n- `email`\n- `status`\n- `priority`\n- `priority_mode`\n- `cooldown_until`\n- token material and timestamps\n\nImportant invariant:\n\n```text\nUNIQUE(provider, subject)\n```\n\nThis is the real account identity. Never deduplicate by email.\n\n## Package Guide\n\n```text\ncmd/relay/              binary entrypoint + explicit migrate command\ninternal/\n  auth/                 API key authentication middleware\n  config/               environment config\n  crypto/               token encryption\n  domain/               stable core types\n  driver/               provider boundary\n  events/               observational event bus\n  identity/             request masking and session fingerprinting\n  pool/                 account state machine and scheduler\n  relay/                provider-neutral execution pipeline\n  server/               HTTP surface, admin API, UI\n  store/                SQLite persistence + migration\n  tokens/               access-token refresh manager\n  transport/            shared transport pool keyed by proxy shape\n  ui/                   embedded built frontend\nweb/                    Svelte source\n```\n\n## Admin API\n\nAll authenticated endpoints accept either:\n\n- `Authorization: Bearer $API_TOKEN`\n- `x-api-key: $API_TOKEN`\n\nMain endpoints:\n\n| Method | Path | Purpose |\n| --- | --- | --- |\n| `GET` | `/v1/models` | authenticated relay model catalog |\n| `GET` | `/admin/providers` | provider catalog for UI/onboarding |\n| `POST` | `/admin/accounts/generate-auth-url` | start OAuth |\n| `POST` | `/admin/accounts/exchange-code` | finish OAuth |\n| `GET` | `/admin/accounts` | list accounts |\n| `GET` | `/admin/accounts/{id}` | account detail |\n| `POST` | `/admin/accounts/{id}/refresh` | refresh token |\n| `POST` | `/admin/accounts/{id}/test` | probe account |\n| `GET` | `/admin/dashboard` | dashboard data |\n| `GET` | `/admin/users` | list users |\n| `POST` | `/admin/users` | create user key |\n| `GET` | `/admin/health` | authenticated health |\n| `GET` | `/health` | unauthenticated process/store health |\n\n## Development\n\n```bash\ngo build ./...\ngo test ./...\ngo vet ./...\ncd web \u0026\u0026 npm run build\n```\n\n## Operations\n\nDeploy:\n\n```bash\nbash .claude/skills/deploy/scripts/deploy.sh\n```\n\nRestore latest snapshot:\n\n```bash\nbash .claude/skills/deploy/scripts/restore.sh latest\n```\n\nThis project prefers explicit rollback over long-lived compatibility clutter.\n\n## Adding a Provider\n\nIf the architecture is healthy, a new provider should mostly mean:\n\n1. Implement a new `driver.Driver`.\n2. Register it in `cmd/relay/main.go`.\n3. Expose its relay paths and OAuth metadata through `Driver.Info()`.\n4. Let existing core code keep working unchanged.\n\nIf a new provider requires edits scattered across `pool`, `relay`, `server`, and `store`, the boundary is regressing.\n\n## Design Standard\n\nThe codebase prefers fewer states over more fallback code.\n\nBad direction:\n\n- provider-specific branches in core\n- duplicate availability flags\n- schema columns for each provider's rate-limit model\n- email-based deduplication\n- dead compatibility layers that outlive migration\n\nGood direction:\n\n- one provider boundary: `driver`\n- one state transition entrance: `pool.Observe`\n- one real identity: `(provider, subject)`\n- one mutable provider pocket: `provider_state_json`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyansircc%2Fllm-broker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyansircc%2Fllm-broker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyansircc%2Fllm-broker/lists"}