Pick how you cap each person
There are two ways to give each end user an allowance. Both work on every route on this page.
Use a key per end user when the client calls the gateway directly. The key is the person’s credential: it carries their budget and their concurrency cap, and it is revoked alone.
Use the per-end-user budget when every request already passes through your backend. Your backend holds one key and names the person on each request.
The product-wide cap is a
project budget in both cases. A request is checked against every budget that applies, so a person at 5 USD is stopped by their own cap and the product at 50 USD is stopped by the project’s.
Set up a key per end user
Create the project budget once:Idempotency-Key so a retry returns the same key:
Set up one per-end-user budget
X-LangWatch-End-User-Id: <your user id> on every request, voice session creates included. A voice session keeps the end user it was created with: every usage report of that session counts against that person’s bucket. See Budgets.
Which route for which feature
Prefer the routes the gateway meters. A client that reports its own usage can stop reporting, and the gateway then charges an estimate for the session instead of what it used.
A call, end to end
To call from a browser, list your page’s origin inLW_GATEWAY_CORS_ALLOWED_ORIGINS on the gateway. See Calling the gateway from a browser.
The client creates its WebRTC offer and posts it to the gateway with its key:
How far past the limit a call can go
A budget is checked when the call is created and again while it runs.- Calls the gateway meters are ended by the gateway. It checks on every usage report and every 30 seconds, so a call runs at most about one minute past the limit.
- Sessions the client meters cannot be ended by the gateway. Each usage report answers with
budget.exceeded; close the socket when it istrue. A client that ignores it is bounded by the credential lifetime and the vendor’s maximum session length, and the next mint answers402.
See what each person spent
GET /api/gateway/v1/end-users/:id/spend. Signed spend events for your own ledger are described in Metering and rebilling.