Connect an inference gateway
Deliver settled request receipts to a private UsageMax project and read them with a separate reporting key.
Create project keys
Open Gateway receipts in the intended workspace and select a project. Create an Ingest key for the server that delivers receipts and a Report key for the administrative application that reads them. Save each key in its server's secret storage. UsageMax shows the secret when you create or rotate a key.
Call GET https://usagemax.com/api/v1/gateway/status with Authorization: Bearer … to check the key scope and latest successful activity for that key. The key determines the destination workspace and project. Requests contain no customer-selected workspace or project identity.
Send from a durable outbox
In the same transaction that settles a request in your ledger, save a receipt in an outbox. Deliver it asynchronously. An analytics outage should leave inference and credit settlement available.
{
"receipts": [{
"schemaVersion": 1,
"requestId": "req_opaque_example",
"revision": 1,
"model": "example-model",
"provider": "example-provider",
"status": "ok",
"settledAt": 1795305600000,
"currency": "USD",
"customerChargeNanos": 1400000,
"providerCostNanos": null,
"providerCostBasis": "unknown",
"usage": { "inputTokens": 1000, "outputTokens": 120, "reportedTotalTokens": 1120 }
}]
}Post the batch to https://usagemax.com/api/v1/gateway/receipts using the ingest key. A batch can contain up to 50 receipts and 64 KiB.
| Result | Outbox handling |
|---|---|
accepted or replay | Acknowledge the receipt. |
stale | Acknowledge it when a later revision superseded it. |
conflict | Hold it for investigation. The same revision already contains different evidence. |
Retry transient failures with bounded exponential backoff and respect Retry-After when present. Preserve the request ID and revision on retry. To submit a correction, send a complete replacement receipt with a higher revision and the original settlement date. Keep the customer amount and provider cost distinct. USD amounts use integer nanodollars. A null cost or absent token field means the source did not supply it.
Validate a batch before delivery
When setting up or troubleshooting a sender, post the same JSON batch to https://usagemax.com/api/v1/gateway/receipt-validation. This endpoint uses the same ingest key, rate limit, and limits of 1–50 receipts and 64 KiB. A malformed batch envelope returns HTTP 400.
For a valid envelope, HTTP 200 includes a batch-wide valid flag and one result per candidate. Each result identifies the zero-based position in the original batch.
{
"valid": false,
"results": [
{ "index": 0, "valid": true },
{ "index": 1, "valid": false, "error": "invalid_gateway_receipt" }
]
}Compare each invalid candidate with the receipt contract before uploading. The response includes positions and statuses only. UsageMax checks payloads during validation and evaluates revisions, replays, and retention during ingestion.
Use validateReceipts() in the TypeScript client or validate_receipts() in the Python client.
Read reports and receipts
Use the server-side report key for GET /api/v1/gateway/receipts?from=2026-11-21&through=2026-11-21. Date bounds are inclusive UTC and can span up to 31 days. The response indicates truncation for a bounded result. Query a narrower range if you need complete counts. For one request, use GET /api/v1/gateway/receipts/{requestId}.
Traces, analytics, and alerts
Include an optional trace on a receipt with a 32-character lowercase hexadecimal trace ID. Send one request root followed by child spans in parent-first order. Each span has an opaque 16-character lowercase hexadecimal ID, start and end milliseconds, kind, and status. Provider attempts also carry a provider slug, optional model and HTTP status, and an allowlisted outcome. A request that reached the gateway but still needs billing recovery can use error status, trace.billingStatus: "pending", and a null customer charge. Publish a higher revision when the ledger resolves it.
GET /api/v1/gateway/operations?from=2026-11-21&through=2026-11-21 returns totals and UTC day, provider and model breakdowns over the newest 2,000 retained receipts in the selected period. It includes p50, p95 and p99 plus sample counts, exact decimal integer monetary sums, cost evidence coverage, and recent trace links. Covered margin includes only receipts with a known customer charge and provider-reported or invoice-confirmed cost. If the report hits the cap, it labels the coverage.
Each breakdown includes chargeCovered, the number of receipts that report a customer charge. This count includes an explicit zero. A positive count below requests marks a partial charge total. A zero count with receipts means the charges are unreported. Older gateway responses may omit the count.
Gateway alerts evaluate every five minutes. A provider triggers an error alert at a 20% attempt error rate, or a latency alert at 5 seconds p95, over at least five measured attempts in the previous hour. Pending billing alerts remain open while pending receipts exist within retention. The response includes open and resolved incidents and the last evaluation time.
Workspace members with finance and data export access can use Export receipts in the Gateway dashboard. The NDJSON download contains the latest retained revision of each request for the selected project and applied UTC dates. A completion marker at the end confirms that the live export finished.
The OpenAPI document describes the private gateway operations. The repository includes a TypeScript server client with generated contract types.
Gateway receipts stay private to the project. Send only permitted metrics and opaque identifiers. Keep prompts, responses, tools, headers, wallet addresses, secrets, and customer identity out of receipts.
Hosted evaluation runs
Run the versioned synthetic smoke fixture from the UsageMax repository with bun scripts/gateway-eval.ts fixture. It uses checked-in observations and incurs no provider charges. Use Publish hosted gateway eval in GitHub Actions to run it manually on main. The workflow requires a project Gateway Ingest key stored as USAGEMAX_GATEWAY_EVAL_INGEST_KEY in the gateway-evals environment. Supply baseline_run_id to compare against a retained fixture run. Each publication goes to the project assigned to the key.
For a direct run, inject the ingest key into the same environment variable and set USAGEMAX_GATEWAY_EVAL_RUN_ID to a stable ID for the report. With the ingest key unset, the fixture runs locally.
# Inject USAGEMAX_GATEWAY_EVAL_INGEST_KEY through the CI secret store.
USAGEMAX_GATEWAY_EVAL_RUN_ID=fixture-12345-1 \
bun scripts/gateway-eval.ts fixtureUnder Inference gateway, choose the project and open Hosted eval runs. Review pass counts, input and output tokens, charges and latency. To compare another run, set USAGEMAX_GATEWAY_EVAL_BASELINE_RUN_ID to an existing run from the same project with the same mode, dataset and version, evaluator, routes, and cases. Keep the ID and report stable when retrying a publication. Use a distinct ID for a new run.
The local baseline checks quality, latency, tokens, and charge budgets. The hosted baseline comparison flags cases that passed in the baseline and fail in the current run. The CLI exits unsuccessfully if publication fails or either gate fails.
Hosted reports include opaque IDs, pass/fail outcomes, token counts, charge in USD millionths, and latency. Keep prompts, expected answers, and completions in the local evaluator. The Gateway dashboard shows the latest 20 retained runs for the selected project to workspace members with reporting access. Runs follow the workspace's retention setting.
Send GET /api/v1/gateway/evals with the project report key to read those runs from a service. The repository TypeScript client exposes evals() and publishEval(). The Python client exposes evals() and publish_eval() starting with version 0.1.1. Publication requires an ingest key.