← portfolio
Paid LLM Inference Gateway
September 2026
Metered, pay-as-you-go inference
A single Go binary that adds pay-as-you-go billing to a self-hosted Ollama instance. Accounts are funded with USDC over the x402 payment protocol, and usage is settled off-chain in Postgres.
highlights
- Proxies the whole Ollama HTTP API (native NDJSON and OpenAI-compatible SSE) behind an authenticated wildcard reverse proxy that passes methods, paths, headers, and streaming bytes through unchanged.
- Funds prepaid USDC balances over x402. The first request comes back 402 Payment Required with the exact price, then the gateway verifies and settles the on-chain payment through Coinbase's CDP facilitator on Base.
- Meters with a reserve-then-settle flow: cap the requested output, reserve the worst-case cost before calling Ollama, then bill the exact usage reported and release the rest.
- Keeps an off-chain Postgres ledger that credits balances and records every usage transaction.
- Invite-only API keys stored only as SHA-256 digests, per-key rate and concurrency limits, and an admin CLI for user management and settlement reconciliation.
tech
Go
x402
USDC / Base
PostgreSQL
Ollama
systemd
links