[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81760":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":14,"stars7d":15,"stars30d":16,"stars90d":14,"forks30d":14,"starsTrendScore":14,"compositeScore":17,"rankGlobal":8,"rankLanguage":8,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":8,"pushedAt":8,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":14,"starSnapshotCount":14,"syncStatus":15,"lastSyncTime":26,"discoverSource":27},81760,"ai-gateway","VaalaCat\u002Fai-gateway","VaalaCat",null,"Go",27,5,1,7,0,2,3,40.63,"MIT License",false,"main",true,[],"2026-06-12 04:01:35","> My Blog: https:\u002F\u002Fvaala.cat\u002Fposts\u002Fvibe-ai-gateway-oss\u002F\n\n# AI Gateway\n\nA distributed-by-design AI API gateway with a separated control-plane (master) \u002F data-plane (agent) architecture. Provides OpenAI\u002FClaude-compatible `\u002Fv1\u002F*` relay endpoints, built-in management APIs, Web UI, and single-binary distributed deployment.\n\n[中文文档](README.zh.md)\n\n## Features\n\n- **Control Plane Management** — Users (groups), tokens, channels, models, and agents\n- **Data Plane Relay** — OpenAI\u002FClaude-compatible API endpoints (`\u002Fv1\u002Fchat\u002Fcompletions`, `\u002Fv1\u002Fresponses`, `\u002Fv1\u002Fmessages`, etc.) with automatic cross-protocol conversion\n- **Real-Time Config Sync** — Master\u002Fagent incremental sync over WebSocket; lightweight distributed deployment with zero external dependencies\n- **Multi-Region Routing** — Route requests from region A to agents in region B, enabling cross-region load balancing and bypassing regional restrictions\n- **Quota & Billing** — Usage-based settlement and quota enforcement\n- **Model Routing** — Aggregate multiple upstream models under one name with priority\u002Fweight load balancing and error retries\n- **BYOK (Bring Your Own Key)** — End-users can self-serve upload their own provider API keys (AES-GCM encrypted at rest); private channels are merged into the candidate pool with priority over shared admin channels, with optional service-fee billing mode\n- **Single Binary** — Frontend static assets embedded; no separate web server needed\n\n## Screenshots\n\n\u003Ctable>\n  \u003Ctr>\n    \u003Ctd colspan=\"2\">\u003Ca href=\"docs\u002Fimages\u002Fen\u002Fdashboard.png\">\u003Cimg src=\"docs\u002Fimages\u002Fen\u002Fdashboard.png\" alt=\"Dashboard\"\u002F>\u003C\u002Fa>\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd width=\"50%\">\u003Ca href=\"docs\u002Fimages\u002Fen\u002Fchannels.png\">\u003Cimg src=\"docs\u002Fimages\u002Fen\u002Fchannels.png\" alt=\"Channels\"\u002F>\u003C\u002Fa>\u003Cbr\u002F>\u003Csub>\u003Cb>Channels\u003C\u002Fb> — upstream provider configuration\u003C\u002Fsub>\u003C\u002Ftd>\n    \u003Ctd width=\"50%\">\u003Ca href=\"docs\u002Fimages\u002Fen\u002Fmodels.png\">\u003Cimg src=\"docs\u002Fimages\u002Fen\u002Fmodels.png\" alt=\"Models\"\u002F>\u003C\u002Fa>\u003Cbr\u002F>\u003Csub>\u003Cb>Models\u003C\u002Fb> — per-model pricing\u003C\u002Fsub>\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd>\u003Ca href=\"docs\u002Fimages\u002Fen\u002Fmodel-routings.png\">\u003Cimg src=\"docs\u002Fimages\u002Fen\u002Fmodel-routings.png\" alt=\"Model Routings\"\u002F>\u003C\u002Fa>\u003Cbr\u002F>\u003Csub>\u003Cb>Model Routings\u003C\u002Fb> — priority\u002Fweight aggregation\u003C\u002Fsub>\u003C\u002Ftd>\n    \u003Ctd>\u003Ca href=\"docs\u002Fimages\u002Fen\u002Flogs.png\">\u003Cimg src=\"docs\u002Fimages\u002Fen\u002Flogs.png\" alt=\"Usage Logs\"\u002F>\u003C\u002Fa>\u003Cbr\u002F>\u003Csub>\u003Cb>Usage Logs\u003C\u002Fb> — per-request audit trail\u003C\u002Fsub>\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd>\u003Ca href=\"docs\u002Fimages\u002Fen\u002Fbilling.png\">\u003Cimg src=\"docs\u002Fimages\u002Fen\u002Fbilling.png\" alt=\"Billing\"\u002F>\u003C\u002Fa>\u003Cbr\u002F>\u003Csub>\u003Cb>Billing\u003C\u002Fb> — daily rollups by token and channel\u003C\u002Fsub>\u003C\u002Ftd>\n    \u003Ctd>\u003Ca href=\"docs\u002Fimages\u002Fen\u002Fplayground.png\">\u003Cimg src=\"docs\u002Fimages\u002Fen\u002Fplayground.png\" alt=\"Playground\"\u002F>\u003C\u002Fa>\u003Cbr\u002F>\u003Csub>\u003Cb>Playground\u003C\u002Fb> — in-browser chat tester\u003C\u002Fsub>\u003C\u002Ftd>\n  \u003C\u002Ftr>\n\u003C\u002Ftable>\n\n[See all 20 screenshots →](docs\u002Fscreenshots.md)\n\n## Architecture\n\n```\n┌─────────────────────────────────────────────────────┐\n│                   master (control plane)             │\n│  ┌──────────┐  ┌──────────┐  ┌───────────────────┐ │\n│  │ Admin API│  │  Web UI  │  │ Agent Sync Hub    │ │\n│  │ & Auth   │  │ (embed)  │  │ (WebSocket)       │ │\n│  └──────────┘  └──────────┘  └───────────────────┘ │\n│  ┌──────────────────────────────────────────────┐   │\n│  │         Billing & Quota Settlement           │   │\n│  └──────────────────────────────────────────────┘   │\n└─────────────────────────────────────────────────────┘\n          │ WebSocket sync\n          ▼\n┌─────────────────────────────────────────────────────┐\n│                   agent (data plane)                 │\n│  ┌──────────────┐  ┌────────────┐  ┌────────────┐  │\n│  │ \u002Fv1\u002F* Relay  │  │ Token\u002FChan │  │  Usage     │  │\n│  │ Endpoints    │  │ Cache      │  │  Reporter  │  │\n│  └──────────────┘  └────────────┘  └────────────┘  │\n└─────────────────────────────────────────────────────┘\n```\n\n### Deployment Topologies\n\n| Topology                              | Pros                                                  | Cons                                        | Use Case                              |\n| ------------------------------------- | ----------------------------------------------------- | ------------------------------------------- | ------------------------------------- |\n| Single node (master + embedded agent) | Simplest setup; one container                         | Shared resources; single point of failure   | PoC, testing, small production        |\n| Multi-node (master + external agents) | Horizontal scaling; fault isolation; geo-distribution | Higher ops complexity; enrollment lifecycle | Medium\u002Flarge production, multi-region |\n\n## Quick Start\n\n```bash\n# 1. Prepare config\nmkdir -p deploy data\ncp config.example.yaml deploy\u002Fconfig.yaml\n# Edit deploy\u002Fconfig.yaml — set jwt_secret and admin_password\n\n# 2. Run with Docker Compose\nexport AI_GATEWAY_IMAGE=vaalacat\u002Fai-gateway:latest\ndocker compose up -d\n\n# 3. Access\n# Web UI: http:\u002F\u002Flocalhost:8140\n# Health: http:\u002F\u002Flocalhost:8140\u002Fping\n```\n\n## Configuration\n\nThe configuration file accepts these top-level keys:\n\n- `log_level` — Logging verbosity (debug, info, warn, error)\n- `master` — Control plane settings (listen address, DB, JWT, admin credentials)\n- `agent` — Data plane settings (listen address, master URL, enrollment)\n- `runtime` — Optional advanced tuning (timeouts, heartbeat, retry)\n\nSee [`config.example.yaml`](config.example.yaml) for a complete template.\n\n## Deployment\n\n### Single Node (Docker Compose)\n\nSee the [Quick Start](#quick-start) section above. Full details in [`docker-compose.yml`](docker-compose.yml).\n\n### Multi-Node (External Agents)\n\n1. Generate an enrollment token from master\n2. Configure agent with `master_url` and `enrollment_token`\n3. Start with `docker compose -f docker-compose.yml -f docker-compose.agent.yml up -d`\n\nSee [`docker-compose.agent.yml`](docker-compose.agent.yml) for the overlay template.\n\n### Kubernetes\n\nSee [`docs\u002Fk8s-deployment.md`](docs\u002Fk8s-deployment.md) for Kubernetes deployment guidance.\n\n## Development\n\n```bash\n# Prerequisites: Go 1.25+, Node.js 20+, pnpm\n\n# Build (frontend + backend)\nCGO_ENABLED=0 bash .\u002Fbuild.sh\n\n# Run tests\nCGO_ENABLED=0 go test .\u002F... -count=1 -timeout=120s\n\n# Frontend dev server (port 8141, proxies to :8140)\ncd web && pnpm install && pnpm dev\n```\n\n## Releasing\n\nReleases are cut by pushing a `v*` git tag. GitHub Actions builds a multi-arch\nimage (linux\u002Famd64 + linux\u002Farm64) and pushes it to\n[Dockerhub](https:\u002F\u002Fhub.docker.com\u002Fr\u002Fvaalacat\u002Fai-gateway).\n\n```bash\n# Stable release — also updates :latest\ngit tag v1.2.3\ngit push origin v1.2.3\n\n# Pre-release — pushes :v1.2.3-rc1 only, does NOT update :latest\ngit tag v1.2.3-rc1\ngit push origin v1.2.3-rc1\n```\n\nThe git tag is injected into the binary as `internal\u002Fversion.Version`.\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, code style, and PR process.\n\n## Acknowledgments\n\nThis project supports native code (purely self-developed, supporting chat, response, and messages protocols), while other protocols are supported by the new-api channel.\n\nIt builds upon the work of the following:\n\n- **[new-api](https:\u002F\u002Fgithub.com\u002FQuantumNous\u002Fnew-api)** by [@QuantumNous](https:\u002F\u002Fgithub.com\u002FQuantumNous) — the legacy channel adaptor, 50+ upstream provider constants, model-fetch protocols, and token-counting utilities are reused via `github.com\u002FQuantumNous\u002Fnew-api`. Without this prior work, out-of-the-box support for 50+ providers would not be feasible. Sincere thanks to the new-api maintainers and contributors.\n\n- **[datatype](https:\u002F\u002Fgithub.com\u002Ffranktisellano\u002Fdatatype)** by [@franktisellano](https:\u002F\u002Fgithub.com\u002Ffranktisellano) — variable OpenType font (SIL OFL 1.1) used for inline sparklines in the UI. See `web\u002Fpublic\u002Ffonts\u002FOFL.txt`.\n\n## Contract Test (optional)\n\n`test\u002Fcontract\u002F` 包含跨语言一致性测试,默认不跑,需要时手动:\n\n```bash\n# 1) 启动 master\n.\u002Fai-gateway --config config.yaml &\n\n# 2) 取 admin token\nTOKEN=$(curl -s -X POST http:\u002F\u002Flocalhost:8140\u002Fapi\u002Flogin \\\n  -H 'Content-Type: application\u002Fjson' \\\n  -d '{\"username\":\"admin\",\"password\":\"change-this-password\"}' \\\n  | jq -r '.data.token')\n\n# 3) 跑测试\nAIGW_ADMIN_TOKEN=$TOKEN go test -tags=contract .\u002Ftest\u002Fcontract\u002F\n```\n\n测试内容: 扫 `web\u002Fsrc\u002Flib\u002Fapi\u002F*.ts` 中所有 `\u002F...` 路径字面量,逐个发请求,验证后端没有返回 404 (即不存在路由漂移)。\n\n## License\n\n[MIT](LICENSE)\n","AI Gateway 是一个采用分离控制平面和数据平面架构设计的分布式AI API网关。其核心功能包括提供与OpenAI\u002FClaude兼容的API端点、内置管理API及Web界面，支持单个二进制文件的分布式部署。技术特点涵盖实时配置同步、多区域路由、配额与计费管理、模型路由以及用户自服务上传密钥等。适用于需要跨区域负载均衡、绕过地区限制或统一管理多个AI服务提供商接口的企业级应用场景。","2026-06-11 04:06:17","CREATED_QUERY"]