A distributed, low-latency, high-performance AI gateway on Cloudflare Workers, with channel management, load balancing, and usage analytics.
English | 中文
- Built on Cloudflare Workers: global edge network, low latency, high performance
- Unified proxy entry:
/v1/chat/completions,/v1/messages,/v1/responses,/v1/audio/speech,/v1/models - Weighted load balancing: multi-key per channel, retry, key rotation, and cross-channel fallback
- Quotas and billing: token-level quotas, global model pricing, channel-level model pricing
- Observability: writes to Cloudflare Analytics Engine; admin UI covers overview, trends, distributions, and usage log search
- Admin console: React + Vite UI for channels, tokens, pricing, API testing, and system settings
- Admin security: admin-token login by default; optional Telegram 2FA; rate limits and session cookies on the login path
- API docs: Chanfana-powered Swagger, ReDoc, and OpenAPI JSON, toggleable in system settings
| Route | Description | Channel types |
|---|---|---|
/v1/chat/completions |
OpenAI Chat Completions–compatible proxy | openai, azure-openai, gemini |
/v1/messages |
Anthropic Claude Messages–compatible proxy | claude, claude-to-openai |
/v1/responses |
OpenAI / Azure Responses proxy | openai-responses, azure-openai-responses |
/v1/audio/speech |
TTS speech generation proxy | openai-audio, azure-openai-audio |
/v1/models |
Model list filtered by token permissions and quota | Returned dynamically from channels the token can access |
# Create a D1 database and note its name and ID
# Enable Analytics Engine, create a dataset, and note its name
# Put those values into wrangler.jsonc
# Set production secrets
wrangler secret put ADMIN_TOKEN
wrangler secret put CF_API_TOKEN
wrangler secret put CF_ACCOUNT_ID
# Publish the Worker
bun run deployCurrent admin pages:
Dashboard: total requests, success rate, cost, latency, and token/channel/model/provider distributionsUsage Logs: filter detailed logs by time range, dimensions, keywords, and resultChannels: channel config, weights, auto retry/rotation, model mapping, pull upstream model listsTokens: API token management, channel access scope, quotas, usage resetPricing: global model pricing; per-token and per-request billingAPI Test: test/v1/chat/completions,/v1/messages,/v1/responses,/v1/audio/speechfrom the consoleSystem Settings: Telegram admin verification, currency display precision, API docs toggle
one-api-workers/
├── src/
│ ├── admin/ # Admin APIs: auth / channel / token / pricing / analytics / system
│ ├── analytics/ # Analytics Engine write and query
│ ├── db/ # D1 init and migrations
│ ├── providers/ # Upstream provider proxies
│ ├── billing.ts # Billing and amount precision
│ ├── channel-config.ts # Channel config normalization
│ ├── system-config.ts # System config and Telegram security settings
│ └── index.ts # Worker entry
├── frontend/
│ ├── src/pages/ # Dashboard / Channels / Tokens / Pricing / Usage Logs / Settings
│ ├── src/components/ # Layout, charts, UI components
│ └── package.json # Frontend build and lint
├── public/ # Frontend build output, served by the Worker
├── docs/ # Usage and security docs
├── tests/ # Mock upstream + local E2E scripts
├── wrangler.jsonc # Production config
├── wrangler.local.jsonc # Local Worker config
├── type.d.ts # Worker bindings and shared types
└── package.json # Root workspace and dev scripts
- Bun 1.3+
- Cloudflare account with Workers + D1 + Analytics Engine (
usage_events_by_token)
bun installwrangler.jsonc / wrangler.local.jsonc already include the required binding shape; replace them with your own values:
d1_databases[].database_name/database_id: your D1 databaseanalytics_engine_datasets[].dataset: defaults tousage_events_by_tokenvars.FRONTEND_DEV_SERVER_URL: local integrated dev only; defaulthttp://127.0.0.1:5173assets: keep thepublic/→ASSETSbinding
Required secrets in the current setup:
ADMIN_TOKEN: admin login token (required)CF_API_TOKEN: Analytics Engine SQL queries for the dashboard and usage logsCF_ACCOUNT_ID: used withCF_API_TOKENfor Cloudflare Analytics queries
Example:
wrangler secret put ADMIN_TOKEN
wrangler secret put CF_API_TOKEN
wrangler secret put CF_ACCOUNT_IDFor local development, put these in .dev.vars; scripts under tests/ also prefer that file.
D1 schema init and migrations run automatically on the first request. No manual SQL is required.
To trigger init after deploy (with admin auth):
POST /api/admin/db_initialize
Start frontend + Worker together:
bun run devCommon URLs:
- Vite frontend:
http://127.0.0.1:5173 - Local Worker:
http://127.0.0.1:8787
Other useful commands:
bun run dev:worker
bun run build
bun run cf-typegen
cd frontend && bun run lintIssues and pull requests are welcome.
MIT License
Credits: dreamhunter2333/awsl-one-api
For questions or suggestions, open an Issue or contact the maintainers.