> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jojapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Adjusting Usage from Your Server

> This article is for API providers. Billing is configured per [billable object](/studio/billable-objects) — this page covers the ways your **server** can report the actual amount at request time.

The normal way to meter usage is a **formula** on the endpoint's billing element (or the object's default formula): the gateway evaluates it against the finished response and bills the result. Two common patterns report the amount from your side:

## Reporting with a response header

Return any header from your upstream and read it in the formula. The conventional header is `X-Jojapi-Credits-Used`, and migrated APIs use exactly this formula:

```
{{default(response.headers["x-jojapi-credits-used"], 1)}}
```

That bills the header's value when present (an explicit `0` bills nothing) and falls back to 1 when your server doesn't send it. Any header name works — the gateway strips `x-jojapi-*` headers from the client response but your formulas can read them.

A non-numeric header value makes the formula non-numeric, and **a formula that can't produce a number bills 0**. If you prefer a fallback for invalid values too, use:

```
{{isNumber(response.headers["x-jojapi-credits-used"]) ? response.headers["x-jojapi-credits-used"] : 1}}
```

## Reporting inside SSE streams

For [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) responses (`content-type: text/event-stream`), send a message during the stream:

```
data: {"x-jojapi-credits-used": 3}
```

The in-band value applies to the **first** object in the endpoint's billing list and takes precedence over that object's formula. An explicit `0` means "charge nothing" — it never falls through to a default.

## Rules

* On **fixed** costs (a plain number in the billing element), reported and computed values are capped at the declared amount — you can lower a request's bill, never raise it above what consumers see.
* Responses with a **5xx status bill 0 on every object**, regardless of any header, SSE message or formula. Failed responses are always free.
* Values must be non-negative integers; anything else is treated as unusable and bills 0 for that object.

## On the edge gateway

APIs served by the edge gateway read reported amounts through **usage sources** (a response header, a header key or a JSON field, each with an optional default) configured on the billing element, see [Billable objects](/studio/billable-objects#usage-sources-on-the-edge-gateway). The header example above becomes the source *Response header* `x-jojapi-credits-used` with default `1`. In-band SSE reporting works the same way. A Worker in [code mode](/studio/custom-code) reports with a response header, `x-jojapi-usage: {"credits": 3}`, or the per-object form `x-jojapi-credits-used: 3`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.