Keyaos
Edge-native AI API gateway β cost-optimized routing across providers, multi-protocol support, built on Cloudflare Workers.
π δΈζ Β· π Website Β· πΊ Werewolf Β· π Docs Β· π‘ API Reference
You subscribe to multiple AI services β OpenRouter, DeepSeek, Google AI Studio, xAI, and more. Each has its own API key, pricing, and quota. Keyaos unifies them behind multi-protocol API endpoints (OpenAI, Anthropic, and more), automatically routing every request to the cheapest healthy provider.
Built entirely on Cloudflare Workers + D1 + Cron Triggers. Self-hosted deployments require no servers and fit within Cloudflare's free tier.
π Architecture
flowchart LR
Client([Client])
subgraph Keyaos ["Keyaos (Cloudflare Workers)"]
direction TB
Auth[Auth & Key Permissions]
Router[Cost-Optimal Router]
CB[Circuit Breaker]
Intercept[SSE Stream Interceptor]
Billing[Usage Tracking & Billing]
Sync[Cron: Model & Price Sync]
end
subgraph Upstream [Upstream Providers]
OR[OpenRouter]
DI[DeepInfra]
DS[DeepSeek]
OAI[OpenAI]
Anthr[Anthropic]
More["+9 more"]
end
Client --> Auth
Auth --> Router
Router --> CB
CB --> Intercept
Intercept --> OR & DI & DS & OAI & Anthr & More
Intercept -.-> Billing
Sync -.-> Router
Request flow: Client sends a request to any supported endpoint. Auth validates the API key and checks permissions (model restrictions, quota, expiry, IP). The router ranks all available credentials by unit_price Γ multiplier and picks the cheapest healthy one. The circuit breaker skips providers with recent failures. The SSE interceptor tee's the response stream β forwarding it to the client in real time while extracting usage data for billing in the background. A Cron job syncs model availability and pricing every minute.
β¨ Features
- Cost-optimized routing β every request goes to the cheapest available provider
- Automatic failover β quota exceeded or rate limited? The next cheapest option takes over
- Zero-latency streaming β SSE responses are tee'd and forwarded in real time
- Auto-synced catalog β model availability and pricing stay up to date via Cron
- Multi-protocol β OpenAI Chat & Embeddings, Anthropic Messages, Google Gemini, AWS Event Stream
- Multimodal β image generation, image/audio/video/PDF inputs via chat completions
- Reasoning effort β unified
reasoning_effortnormalization across providers - Circuit breaker β automatic failure detection and provider bypass
- API key permissions β model restrictions, expiration, spending quota, IP allowlist
- Two modes β self-hosted (single user) or platform (multi-user with Clerk + Stripe)
π Quick Start
βοΈ One-Click Deploy
Click the Deploy to Cloudflare button above, then set one secret:
npx wrangler secret put ADMIN_TOKEN
Done β D1 database, Cron Triggers, and schema are all provisioned automatically.
You'll get Core mode (single admin, sign in with ADMIN_TOKEN). To enable Platform mode (multi-user Clerk auth), add these build-time variables in Cloudflare β Workers β your project β Settings β Build β Variables and secrets:
| Variable | Required | Notes |
|---|---|---|
VITE_CLERK_PUBLISHABLE_KEY |
yes | Your own pk_live_... / pk_test_... from Clerk β must be domain-locked to your deploy origin |
VITE_CRISP_WEBSITE_ID |
no | Enables Crisp support chat |
VITE_GA_ID |
no | Enables Google Analytics |
They must live in the Build tab (read by vite build), not the Worker runtime secrets.
π§ Manual Setup
pnpm install
npx wrangler login
npx wrangler d1 create keyaos-db # update database_id in wrangler.toml
npx wrangler secret put ADMIN_TOKEN
pnpm deploy # builds, applies migrations, deploys
π» Local Development
cp .env.example .env.local # fill in provider keys
cp .dev.vars.example .dev.vars # fill in secrets (ADMIN_TOKEN, etc.)
pnpm db:setup:local
pnpm dev # http://localhost:5173
π‘ Usage
OpenAI Chat Completions
curl https://keyaos.<you>.workers.dev/v1/chat/completions \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello"}]
}'
Anthropic Messages
curl https://keyaos.<you>.workers.dev/v1/messages \
-H "x-api-key: YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'
Embeddings
curl https://keyaos.<you>.workers.dev/v1/embeddings \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/text-embedding-3-small",
"input": "Hello world"
}'
Works with Cursor, Continue, Cline, aider, LiteLLM, and any tool that supports custom OpenAI or Anthropic base URLs.
π Supported Providers
| Provider | Protocol | Pricing Source |
|---|---|---|
| OpenRouter | OpenAI | usage.cost from API |
| DeepInfra | OpenAI | usage.estimated_cost from API |
| ZenMux | OpenAI | Token Γ synced price |
| DeepSeek | OpenAI | Token Γ synced price |
| Google AI Studio | OpenAI | Token Γ synced price |
| xAI | OpenAI | Token Γ synced price |
| Moonshot | OpenAI | Token Γ synced price |
| OpenAI | OpenAI | Token Γ synced price |
| OAIPro | OpenAI | Token Γ synced price |
| Qwen Code | OpenAI | Token Γ synced price |
| Gemini CLI | Google Gemini | Token Γ synced price |
| Antigravity | Google Gemini | Token Γ synced price |
| Kiro | AWS Event Stream | Token Γ synced price |
| Anthropic | Anthropic Messages | Token Γ synced price |
Adding a new OpenAI-compatible provider takes a single entry in the provider registry.
βοΈ Core vs Platform
Core (self-hosted) Platform (multi-user)
βββ Credential pool βββ Everything in Core, plus:
βββ Cost-optimal routing βββ Clerk authentication
βββ Multi-protocol proxy βββ Stripe billing & auto top-up
βββ Circuit breaker βββ Shared credential marketplace
βββ Auto-sync catalog βββ Gift cards / redemption codes
βββ Embeddings endpoint βββ Admin console & analytics
βββ API key permissions
βββ ADMIN_TOKEN auth
Platform is strictly additive β Core runs independently and never depends on Platform.
π₯ Frontend
Keyaos ships with a full frontend built with React 19, Vite 7, and Tailwind CSS 4:
- Model catalog β browsable, searchable listing of all available models with live prices
- Provider directory β per-provider pages with model counts and credential health
- OHLC price charts β financial-grade candlestick charts tracking model price history
- Chat UI β built-in chat interface powered by AI SDK
- API reference β interactive OpenAPI 3.1 documentation via Scalar
- MDX docs β 16 pages of embedded documentation including multimodal guides
- Dark mode β full light / dark / system theme support
- i18n β English and Chinese
π Tech Stack
| Layer | Technology |
|---|---|
| Runtime | Cloudflare Workers |
| Database | Cloudflare D1 (SQLite) |
| Scheduler | Cron Triggers (every minute) |
| Frontend | React 19 Β· Vite 7 Β· Tailwind CSS 4 |
| UI | Radix UI Β· Headless UI Β· Framer Motion |
| Backend | Hono 4 Β· TypeScript |
| Auth | Clerk (platform mode) |
| Payments | Stripe (platform mode) |
| Charts | Lightweight Charts (OHLC) |
| Docs | MDX Β· Scalar (OpenAPI) |
π€ Contributing
Contributions are welcome! Whether it's a bug fix, new provider integration, feature request, or documentation improvement β we'd love your help.
- Fork the repository
- Create a feature branch (
git checkout -b feat/amazing-feature) - Commit your changes (
git commit -m "feat: add amazing feature") - Push to the branch (
git push origin feat/amazing-feature) - Open a Pull Request
If you're unsure where to start, check out the open issues or start a discussion. All contributions, big or small, are greatly appreciated.