Deep dive

Architecture

Ephemeral Side × Pipeline System — one metered HIT/MISS crossing.

Create AccountDocs

Shape

Metrecept is an OpenAI-compatible AI gateway. Clients send /v1/chat/completions (and related routes) with a Bearer key. Metrecept applies seat checks, Redis exact-replay, BYOK to the model provider, and Stripe metering. The response is OpenAI-shaped.

That is the whole product surface. Everything else is how inventory is addressed — and how governance stays off the hot path.

If you have used a single opaque proxy before, the mental model shift is small but load-bearing: replay lives in one container; money and policy live in another. They meet at HIT or MISS. They do not blur into each other.

The methodical cut of the same design lives in Docs — Architecture. This page is the walkthrough: tips, Promote, compose, and the anti-pattern we see when teams skip the tip.

Gateway

One URL. One key path. Cursor, CI, and agents use the same OpenAI-compatible contract. You do not learn a new protocol to get exact-replay; you point the client you already have.

curl -sS https://api.withohm.dev/v1/chat/completions \
  -H "Authorization: Bearer $OHM_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role":"user","content":"ping"}]
  }'

Exact replay is Redis-backed: same request fingerprint on the same tip returns the stored completion when present. Misses go BYOK to the provider and are written back. Ambient fact: the fingerprint is exact. Soft or semantic “close enough” matching is not part of the pipe — receipts would stop meaning anything if it were.

Two containers

On every request the edge and the control plane cooperate as two containers:

  • Ephemeral Side — edge HIT, cache trees, content-addressed blobs, BYOK request context. Optimized for latency and mechanical repeat. Safe to TTL or freeze without erasing your ledger.
  • Pipeline System — tenancy, Stripe meters, compliance ingest, provider route, JWKS receipts, org audit / FinOps. Optimized for claims you can stand behind.

They meet at a metered HIT / MISS crossing. HIT never calls the lab. MISS does — then stores, unless you said no_store.

Streaming rides the same split with an honest limit: pre-first-byte failover is shipped; mid-stream handoff is not. Details: Streaming & failover.

Tips

A tip is a named address in the exact-replay inventory. Clients select it with X-Ohm-Cache-Tree.

Default tip is main — durable inventory for the shared path. Ephemeral tips (pr-842, agent-a, suite names) keep work off main until Promote. Dashed frames in the diagrams are ephemeral. Hatch is durable main.

curl -sS https://api.withohm.dev/v1/chat/completions \
  -H "Authorization: Bearer $OHM_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Ohm-Cache-Tree: pr-842" \
  -d @prompt.json
Metrecept cache trees
  • Dashed = preview tip (ephemeral)
  • Hatch = main (durable)
  • Silver = Promote crossing
Branch for a PRShare answers without copyingBring hits to mainPreview inventoryMain inventoryPromoteRead from main

Metrecept branches exact-replay inventory by tip. For pairing tips with a database preview branch in CI, see Compose with Neon.

Collisions happen when two writers share one tip — not because the gateway is shared. That distinction is the whole tip story in one sentence. Keep one gateway. Split tips when streams should not pollute each other.

Crossing

Promote is the only intentional write from an ephemeral tip onto main. Until Promote, main does not absorb that tip’s inventory. After Promote, the next job on main can HIT those entries.

Promote is the only crossing
  • Dashed = preview tip
  • Hatch = main
  • Silver = Promote only
pr-842ephemeral tipPromotemaindurable inventory

Until Promote, main does not absorb the tip. After Promote, the next job on main can hit exact replay for those entries.

Billing stays on the shared gateway (seats + meters). Promote is inventory hygiene, not a second SKU. Silver in the diagrams is that crossing — the moment preview work earns durable inventory.

Compose

Optional database preview branches carry database state. Metrecept tips carry exact-replay inventory. CI can compose both: a preview DATABASE_URL (or equivalent) plus X-Ohm-Cache-Tree. Same job. Two headers. Clear nouns. Dedicated guide: Compose with Neon.

Metrecept — middleware governance
  • Dashed = PR-scoped peer, ephemeral for this job
CI job · PR 842Metreceptexact-replay inventoryX-Ohm-Cache-Tree: pr-842Neon previewDB + AI Gateway betapreview branch · PR 842Same slug. Compose peers. Promote on merge.

Neon branches state (and, in beta, the model path). Metrecept branches exact-replay inventory — middleware governance on mechanical repeats.

export DATABASE_URL="$NEON_PREVIEW_URL"
export OHM_TIP="pr-${PR_NUMBER}"

# suite runs against both peers…
curl -sS https://api.withohm.dev/v1/chat/completions \
  -H "Authorization: Bearer $OHM_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Ohm-Cache-Tree: $OHM_TIP" \
  -d @prompt.json

# on green — Promote inventory to main
curl -sS -X POST "https://api.withohm.dev/v1/cache/trees/${OHM_TIP}/promote" \
  -H "Authorization: Bearer $OHM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"target":"main"}'

Metrecept does not replace the database preview. It is the inventory peer in the same workflow. If you already branch state for PRs, pairing a tip is the smallest change that stops preview prompts from warming production HITs by accident.

Anti-pattern

Putting every agent on main, then spinning a second gateway when collisions appear, buys keys — not isolation.

Shared main vs named trees
  • Red = collides on one tip
  • Silver = Promote into main
  • Hatch = main
One tip for everyoneA tree per streammain tipeveryone writes hereCI suiteagent Aagent BPR-991noisy neighborpr-842suite onlyagent-afleet onlymainpromote inPromote

Isolation is a tip problem, not a second gateway problem.

Isolation is a tip problem. Keep one gateway. Split tips. Promote when the suite earns main. The noisy-neighbor diagram is not a morality play; it is the failure mode we see when the gateway is shared for the right reason and the tip is shared for the wrong one.

What this architecture enables

This design turns traditionally wasteful AI operations — re-paying identical agent and CI prompts, mixing preview pollution into production HIT inventory — into inventory and metadata operations.

  • Signed, verifiable receipts

    Every HIT, MISS, and API call mints an Ed25519 JWS receipt — proof, not a promise.

  • Zero-upstream replay

    Identical requests answer from Redis. The lab is not paid twice.

  • Tree-scoped isolation

    PR and agent inventories diverge without cloning tenants or databases.

  • Promote as index work

    Bring new digests to main without rewriting history as a bulk export.

  • Compose with a DB preview

    State branch + replay tip in one CI job — complementary peers.

  • Governed browse

    Public web through robots / PII / SSRF before model contact.

  • Compliance-grade ledger

    Tenant spend, SSO, and audit trail feed one meter — no side channel.

Related

All product