Skip to content

Repository files navigation

Ledger

Production-grade LLM Gateway in Go. Ledger sits between applications and AI providers (OpenAI, Anthropic/Claude, Gemini), giving a unified OpenAI-compatible API with cost control, reliability, and observability — so you always know what your AI usage costs, and a provider outage never takes your app down with it.

See ARCHITECTURE.md for the full system design, including package responsibilities, request lifecycle, schema, and build order.

Status

🚧 Phase 1 (MVP) in progress. Not production-ready yet.

Prerequisites

  • Go 1.24+
  • Docker and Docker Compose (local Postgres + Redis)
  • golang-migrate CLI (for database migrations)

Quick Start

  1. Start local dependencies:
docker compose up -d
  1. Build and run using the example config (defaults work for local dev):
make build
make run CONFIG=configs/config.example.yaml

To customize settings, copy the example config first and point CONFIG at your copy:

cp configs/config.example.yaml configs/config.yaml
make run CONFIG=configs/config.yaml

Makefile Targets

Target Description
make build Build the ledger binary to bin/ledger
make run Build and run with CONFIG (default: configs/config.example.yaml)
make test Run all unit tests
make migrate-up Apply pending database migrations
make migrate-down Roll back the last migration
make tidy Run go mod tidy

Configuration

Configuration is loaded from a YAML file (see configs/config.example.yaml).

  • Pass --config path/to/config.yaml to the binary
  • ${ENV_VAR} placeholders in YAML are expanded from the environment
  • Environment overrides (take precedence over YAML):
    • DATABASE_URL — Postgres connection string
    • REDIS_URL — Redis connection string
    • OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY — provider credentials

Invalid configuration fails at startup with a descriptive error.

Project Structure

See ARCHITECTURE.md for the full layout and package responsibilities.

License

MIT

About

Self-hosted LLM gateway in Go — unified OpenAI-compatible API with cost tracking, budgets, caching, retries, and circuit breaking across OpenAI, Claude, and Gemini

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages