Matrix logo

Gateway API

The metered, OpenAI-compatible LLM proxy: chat completions and embeddings, priced per model against a versioned PAX rate card and debited from a per-user credit ledger.

The gateway is an OpenAI-compatible LLM proxy that meters every call. It prices the request against a versioned rate card, debits a per-user PAX credit ledger, then forwards to the upstream provider (Fireworks or Together).

Wire shape

client -> https://matrix.paxeer.app/gw/v1/chat/completions
nginx  -> http://127.0.0.1:9090/v1/chat/completions   (strips /gw/)
gw     -> upstream Fireworks / Together

Routes

MethodPathPurpose
POST/v1/chat/completionsOpenAI-compatible chat completion (metered)
POST/v1/embeddingsOpenAI-compatible embeddings (input-only pricing; metered)
GET/healthzUnauthenticated liveness

Required headers

HeaderRequiredMeaning
AuthorizationalwaysBearer ${MATRIX_GATEWAY_TOKEN}
X-Matrix-Actor-DIDalwaysWallet/DID; ledger key
X-Matrix-Slotalwayscompiler / planner / executor
X-Matrix-Intent-IDoptionalFor cost-by-intent rollups
X-Matrix-Goal-IDoptionalFor cost-by-goal rollups
X-Matrix-Kind-RouteoptionalExecutor sub-route (reason, code, etc.)
X-Matrix-BYO-API-Keyoptionaltrue to bypass metering
X-Matrix-User-API-KeyBYO-onlyCaller's own provider API key

Response headers

Response headerMeaning
X-Matrix-Cost-PaxThis call's cost (PAX, fixed-12)
X-Matrix-Daily-Spent-PaxActor's running daily spend
X-Matrix-Daily-Remaining-PaxActor's daily-cap headroom
X-Matrix-Rate-Table-Versionrates.RateTableVersion

Metering model

1
Price

The model ID is looked up in the versioned rate card (RateTableVersion). PAX rates are derived from USD provider prices at a fixed PAX reference.

2
Gate

Free-tier callers are restricted to a per-slot model whitelist and a daily PAX cap (default 10 PAX). Other models return 403 model_not_whitelisted. BYO bypasses the whitelist AND skips metering.

3
Debit

Token usage is priced and written to the credit_ledger, recording the rate_table_v so historical rows replay byte-identically after a reprice.

Free-tier whitelist

All model IDs are prefixed accounts/fireworks/models/.

SlotAllowed modelsNotes
compilergpt-oss-120b, deepseek-v4-prov4-pro is the low-confidence escalation target
plannergpt-oss-120b, deepseek-v4-flash, deepseek-v4-proV1 pins planner = v4-pro via MATRIX_PLANNER_MODEL
executordeepseek-v4-flash, kimi-k2.6V1 pins executor = kimi-k2.6 via MATRIX_EXECUTOR_MODEL

Budget hard-stop

On every metered call the gateway:

  1. Reads the actor's daily spend from credit_ledger.
  2. Reads the actor's daily cap from daily_budget_caps (default 10 PAX).
  3. If spend + projected cost > cap, returns 429 budget_exhausted:
    {"error": "budget_exhausted", "spent_pax": "...", "limit_pax": "..."}
  4. Otherwise forwards upstream. On 2xx, debits ledger and stamps response headers.
  5. On non-2xx upstream, forwards body verbatim with no debit.

Streaming

stream=true requests pipe the SSE response through unmodified. The trailing usage chunk (emitted by both Fireworks and Together) is scanned out of the stream and used to debit the ledger. Cost headers are NOT added on streaming responses because the 200 status is flushed before upstream emits the usage trailer.

Kill switches

  • MATRIX_GATEWAY_DISABLED=true env returns 503 to every request, including /healthz. Restart to clear.
  • daily_budget_caps.daily_pax_max=0 for an actor returns 429 instantly on all their calls.
  • -postgres-uri="" uses an in-memory ledger (local-dev only; no cross-process persistence).

Chat completions

curl -X POST https://matrix.paxeer.app/gw/v1/chat/completions \
  -H "Authorization: Bearer $MATRIX_GATEWAY_TOKEN" \
  -H "X-Matrix-Actor-DID: did:matrix:user-id:keyfp" \
  -H "X-Matrix-Slot: executor" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "accounts/fireworks/models/kimi-k2.6",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Every ledger row records the rate-table version that priced it, so historical costs remain auditable and reproducible even after the rate card is bumped.

Pricing & PAX

How PAX, the rate card, and the free tier work.