Skip to content
d0njPublic

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

llm:gate — one endpoint for every model

Self-hosted gateway for OpenAI, Anthropic and Responses APIs.
Route across providers, fall back when one fails, scope keys with budgets, and account for every request.

Next.js 16 Go 1.26 SQLite WAL Self-hosted MIT license

Quick start · Dashboard · API · Configuration · Deployment · Development

llm:gate dashboard: providers, requests, spend, recent requests and routing

Why llm:gate

  • One endpoint, three protocols. OpenAI Chat Completions, Anthropic Messages and OpenAI Responses clients share the same gateway and model catalog.
  • Routing that survives failure. Combos choose by order, round-robin, price, intelligence or measured speed, with retries, fallbacks and key cooldowns.
  • Keys with real limits. Scope client keys to models or combos, set monthly budgets and RPM/TPM limits, and reserve cost before dispatch. API-key checks can be relaxed for loopback only; non-local hosts always require a key.
  • Small, self-hosted footprint. One Next.js app, Go route handlers and a single SQLite file. No Redis, Postgres or sidecar.

Quick start

Requirements: Node.js with npm, and Go 1.26+ with CGO_ENABLED=0.

npm install
go mod download
npm run build
npm start

Open http://localhost:20127. The first start creates data/llmgate.db, applies migrations and prints a dashboard password in the server log. Change it at /settings.

Then:

  1. Add a provider and its API key on Providers.
  2. Create a combo on Routing if you want strategy-based routing.
  3. Create a client key on Keys and point your client at the gateway.
curl http://localhost:20127/v1/chat/completions \
  -H "Authorization: Bearer $LLMGATE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"openai/gpt-6.2-sol","messages":[{"role":"user","content":"Hello"}]}'

Replace the model with one from your Providers page. For a populated dashboard without configuring providers first:

npm run demo:seed
GATEWAY_DB=data/llmgate-demo.db npm start

The demo password is llmgate-demo. See development for details.

Docker

docker run -d --name llmgate \
  -p 20127:20127 \
  -v llmgate-data:/data \
  ghcr.io/d0nj/llmgate:latest
docker logs llmgate

The first password is printed in the container log. The image stores SQLite in /data; set TRUST_PROXY=true when running behind a reverse proxy. The dev tag tracks prereleases.

CLI

The npm CLI runs the server and dashboard:

npm install -g llmgate
llmgate

llmgate --port 8080 --host 0.0.0.0
llmgate --data-dir ./data

The first password is printed by the server. The CLI downloads a prebuilt server bundle on first run for Linux x64 or Windows x64; use Docker or build from source on other platforms. See CLI for flags and environment variables.

Warning

Client keys are optional for loopback requests. Requests from non-local hosts always require a key; with none configured, remote /v1 calls are rejected. Create a key before exposing the gateway beyond localhost.

Dashboard

Connect presets or any OpenAI-compatible endpoint. Keys rotate in order and cooling keys are skipped.

Providers

Combos are virtual models. Pick a strategy, reorder the members, or bring custom filters over price, quality and speed.

Routing

Track requests, tokens, spend and latency across Today, 24h, 7D, 30D, 60D and All.

Usage

Client keys and runtime settings
Client keys Runtime settings
Client keys Runtime settings

Features

Gateway

  • OpenAI Chat Completions, Anthropic Messages and OpenAI Responses in one service.
  • Streaming SSE with keep-alive, idle detection and retry before the first content event.
  • Tool calls, vision and reasoning pass through; provider-side server tools are gated.
  • Exact-origin CORS and a /health endpoint for probes.

Routing

  • Combos with ordered, fallback, round-robin, cheapest, quality, fastest and custom.
  • Retries, key rotation, cooldowns and cross-model fallback.
  • Conversation affinity through prompt_cache_key, session headers and user.

Control

  • Scoped client keys with model allowlists, monthly budgets and RPM/TPM limits.
  • Local-only API-key bypass for development; non-loopback hosts always require a key.
  • Runtime settings stored in SQLite; environment variables override and lock fields.
  • Dashboard password and session management with per-source login lockout behind a trusted proxy.

Accounting

  • One usage_events row per request with tokens, cached tokens, cost, latency, route and status.
  • Provider and model breakdowns, success rate, average latency and per-request cost.
  • Retention is configurable from 40 to 3650 days; the current month is never pruned.

API

Method Path Format
POST /v1/chat/completions OpenAI Chat Completions
POST /v1/messages Anthropic Messages
POST /v1/messages/count_tokens Anthropic token estimate
POST /v1/responses OpenAI Responses
GET /v1/models Model list
GET /v1/models/{id} One model, including aliases
GET /health Health check

Models are addressed as provider/model, by alias, or by combo name. Successful responses include x-llmgate-request-id, x-llmgate-attempts, x-llmgate-provider, x-llmgate-model and x-llmgate-strategy, plus fallback headers when applicable.

See the API reference for auth, examples, error shapes, client keys and gateway behaviour.

Routing

Strategy Picks
ordered / fallback The list order
round-robin Rotates the list per request
cheapest Lowest combined price; unpriced models skipped
quality Highest Artificial Analysis Intelligence Index
fastest Highest measured output speed
custom Filters then sorts by metadata

If no member qualifies, the request fails with 404. See API → Routing for the full rules.

Client keys

Client keys are optional for loopback callers and stored as SHA-512 hashes; the plaintext key is shown once. Allowed models accept exact IDs, combos, provider/* and *. Budgets are checked per UTC month and RPM/TPM over the last 60 seconds. Requests reserve their estimated cost first, so concurrent calls cannot overrun a limit.

Configuration

Most deployment settings are environment variables; gateway limits and policy can be edited at /settings and stored in SQLite. A non-empty environment variable overrides the stored value and locks the field in the dashboard.

Variable Purpose
GATEWAY_DB SQLite path (default data/llmgate.db)
GATEWAY_INTERNAL_URL Where Server Actions reach the Go admin API (default http://127.0.0.1:20127)
TRUST_PROXY true to trust forwarded host and protocol headers from your proxy
GATEWAY_CORS_ORIGINS Comma-separated browser origins allowed to call /v1
USAGE_RETENTION_DAYS Usage retention in days (default 90, minimum 40)
GATEWAY_DISABLE_API_KEY_AUTH true to skip client-key checks for loopback requests only

See configuration for every variable, duration syntax, provider-tool policy and the full precedence rules.

How it works

flowchart LR
  C[OpenAI / Anthropic / Responses clients] -->|/v1/* /health| G[Go gateway]
  D[Dashboard] -->|SSR + Server Actions| N[Next.js app]
  N -->|admin API| A[Go /admin]
  A --> S[(SQLite WAL)]
  G --> S
  G -->|provider APIs| P[Configured providers]
Loading

Go owns gateway and admin logic; Next.js renders the dashboard and forwards mutations to Go. Both runtimes open the same SQLite file, and Drizzle owns the schema. See architecture for the request path, data model and failure model.

Development

CI runs typecheck, lint, Vitest, Go tests, demo seeding, a standalone build and a Docker image build on pushes to main/master and pull requests. Stable releases are cut by semantic-release from Conventional Commits on main; dev produces prereleases. Releases publish the llmgate npm CLI and the ghcr.io/d0nj/llmgate Docker image.

npm run dev          # http://localhost:20127
npx tsc --noEmit     # typecheck
npm test             # Vitest
npm run lint         # oxlint
go test ./...        # Go tests
npm run build        # production build, including Go routes

Demo data:

npm run demo:seed
GATEWAY_DB=data/llmgate-demo.db npm run dev

See development for the full command list, project layout, screenshot workflow and conventions.

Docs

License

MIT © llm:gate contributors. See LICENSE.

Credits

Provider logos from LobeHub Icons (MIT). Model metadata from models.dev. Intelligence Index and measured speed from Artificial Analysis.