Categories
Self-Hosted AI Agents Observability AI Gateway LLM Proxy OpenAI Compatible Failover Semantic CacheStars
Forks
Watchers
Developer links
KGateway
Standing between applications and 25 LLM providers, KGateway presents one OpenAI-compatible API and adds failover, spend limits, caching, and tracing. Switching among OpenAI, Anthropic, Gemini, Bedrock, Groq, or a local Ollama server means editing one provider/model string. An Anthropic-compatible endpoint lets Claude Code and other coding agents route through the gateway, which can also inject MCP tools into requests and run them. Provider errors or exhausted keys trigger backoff retries, key rotation, or a fallback provider named in the request, and streams switch before the client sees a byte. Virtual keys give each team a model allow-list, rate limit, token budget, and dollar ceiling, and real provider keys stay inside the gateway. A two-tier semantic cache answers repeated and near-duplicate prompts without a provider call, trying exact text first and embedding similarity second. Stage-by-stage traces show retries, failures, and time to first token; logs filter by provider, model, key, and status, with a live tail. Sessions group a coding agent's calls into one row per task, showing live spend, tokens, and duration. Redaction masks secrets in captured bodies, and role-based tokens guard the control plane; set an admin token before exposing it. A separate web dashboard adds a playground, provider and key management, analytics, and a generated API reference. Most config edits reload without a restart. Running on a dedicated VPS on RepoCloud with guaranteed CPU, RAM, and SSD, full root SSH access, and a browser serial console. AGPL-3.0 licensed.
Benefits
- One API for every provider
- Apps keep using the OpenAI request format while a provider/model string routes each call to any of 25 providers, so changing vendors never touches client code.
- Outages stay invisible to clients
- Retries with backoff, weighted key rotation, and fallback providers named per request cover errors on normal and streaming calls, and streams fail over before the first byte reaches the caller.
- Spend limits for every team
- Each virtual key sets model allow and deny lists, a request rate limit, a token budget, and a dollar ceiling, so one runaway script or agent cannot drain the shared provider account.
- See where every request went
- Stage-by-stage traces show retries, failures, and time to first token, and sessions roll a coding agent's whole run into one row showing spend, tokens, and duration.
Features
- OpenAI-Compatible API
- Chat completions with streaming, embeddings, images, speech, transcription, and rerank, plus an Anthropic-compatible messages endpoint, all addressed as provider/model across 25 providers.
- Failover and Key Rotation
- Per-request fallback providers, weighted key selection, retries with backoff and jitter, and per-provider concurrency isolation apply to normal and streaming calls alike.
- Virtual Keys and Budgets
- Model allow and deny lists, request rate limits, token budgets, and per-period dollar budgets per key; counters are shared across replicas when Postgres is the database.
- Two-Tier Semantic Cache
- Exact-hash matches first, then embedding similarity, scoped to model and parameters; an embedding provider must be configured, and entries can persist across restarts with pgvector.
- Tracing, Logs, and Analytics
- Request waterfalls, filterable audit logs with an SSE live tail, session grouping, and latency, cost, and token distributions, plus Prometheus metrics and OTLP trace and metric export.
- Dashboard and Playground
- A separate Next.js dashboard, started with pnpm, adds a streaming playground, provider and virtual key management, MCP tool views, settings, and a generated API reference.