This article is for API providers. For the consumer view of per-object pricing and usage, see Credit & Usage.Billing on JoJ API is built around billable objects: the resources your API charges for. Every API starts with a default Credits object, and you can define more — AI tokens, compute time, bandwidth, storage, or anything else you meter. Each endpoint declares how much of each object a request consumes, and each plan declares how much of each object a subscriber gets (or what they pay per unit).
Objects
Manage your objects in Studio → your API → Objects.- Name, slug and dimension are set once at creation and cannot be changed. The slug appears in the per-object response headers (
X-Jojapi-<slug>-Used), so treat it as part of your API’s contract. - The Credits object is created automatically for every API and cannot be deleted. Additional objects can be deleted while no endpoint or plan references them.
- Slugs use lowercase letters, numbers and hyphens. A few platform names are reserved (
credits,user-balance,spent-balance,gateway-response,key).
Default usage formula
Each object can carry a default usage formula — the metering rule that endpoints inherit when they don’t define their own. Set it once on the object instead of repeating it on every endpoint. A plain number works as a constant (for example1 bills one unit per request); a template computes the amount from the response:
Endpoint billing
Each endpoint’s Details page has a Billing section listing the objects the endpoint consumes. Add or remove objects, and give each one a single cost input:| You enter | Meaning |
|---|---|
A plain number (5) | Fixed: the request always bills exactly this many units. The amount is also an upper bound — a response can lower it (see below) but never exceed it. |
A formula ({{response.json.usage.total_tokens}}) | Metered: the amount is computed from the final response on every request. |
| Nothing (empty) | Metered: inherits the object’s default formula. With no default either, the object bills 0. |
Formulas
Formulas are template expressions evaluated against the finished request/response. Useful building blocks:response.json.…,response.headers["…"],request.json.…— read the exchange. Your upstream’s ownx-jojapi-*headers are visible to formulas even though the gateway strips them from the client response.default(x, fallback)—fallbackwhenxis missing or empty; a real0passes through.isNumber(x) ? x : 2— a stricter fallback:2wheneverxisn’t a valid number.min(x, cap)/max(x, floor)— bound a computed amount, e.g.{{min(response.json.tokens, 10)}}never bills more than 10.- Also available:
round,floor,ceil,abs,toInt,len,contains,split,first,lastand more.
- Responses with a 5xx status, and gateway-generated errors, bill 0 on every object — no formula, header or SSE value can charge for a failed response.
- A formula that fails to evaluate or produces a non-numeric result bills 0 for that object (“charge nothing you can’t compute”). Negative results are clamped to 0.
- On fixed costs, any computed or reported value is capped at the declared amount.
Plans
Plan pricing is per object. When creating a plan in Studio → your API → Plans:- Fixed price plans — set an included quota for each object the plan covers (“5,000 Credits and 100,000 AI Tokens per month”). Quotas reset each period and do not carry over.
- Pay as you go plans — define a graduated tier ladder per object. Each unit is billed at the rate of the tier it falls in.
