Skip to main content
A relay has no model catalog to price against, so you describe the price yourself. The usage mapping says where in a call the billable quantity lives and what each unit costs. Every counted call is priced with it, the result is charged to the caller’s budgets and recorded on the Relay Logs row with its breakdown.

The formula

  • cost_per_request is a flat fee added to every counted call.
  • units is the quantity read at units_path (or the size of a whole body) from the request or the response; cost_per_unit is the price of one.
  • units_block_size bills per started block (100 for an API priced per 100 characters); units_minimum is the least number of billed units once a quantity was read. Both default to exact billing.
  • reported_cost is a USD figure the upstream itself puts in its reply, read at cost_path. An array of numbers is summed.
  • Token counts read at the token paths are logged, never priced.
A non-billable route or a non-2xx reply is not charged, but every forwarded reply counts one request against request rate limits. A call that never receives a reply counts nothing. A counted call whose mapping reads nothing still costs cost_per_request.

Set the relay pricing

  1. Open Relays, select the relay and choose Edit Relay Config.
  2. On the General tab, under Pricing, set Fee per Call, Price per Unit, Units Read From, Measure, Units Path and the optional Block Size and Minimum Units. The effective formula is written out underneath as you type.
  3. On the Advanced tab, under Usage Extraction, set Reported Cost Path, Model Path and the token paths, and the Ignore Reported Cost switch.
  4. Select Save General Configuration (or Save Advanced Configuration).

Mapping fields

All paths are gjson paths into a JSON body (usage.credits, DocumentMetadata.Pages, #.Text). A body is read as JSON when its content type contains json (including application/x-amz-json-1.1) or when it has no content type and parses as JSON. Negative, infinite or missing numbers read as nothing. ignore_upstream_cost sits on the relay, not in the mapping: when on, cost_path values are dropped everywhere while your fee and unit pricing still apply.

Reading the request body

When units_source is request and the measure needs a path (value or chars), the relay refuses with 400 before contacting the upstream any body it cannot measure unambiguously: a body that is not JSON, one that names a key twice in the same object (case-insensitively), or one that spells the key in a different case than units_path (text for a Text path). Whole-body measures (body_bytes, body_chars) need no such check. The caller’s Content-Type is not consulted for request-side units, so a caller cannot label a JSON body text/plain to be billed for nothing.

Route overrides

A route’s usage overrides the relay mapping field by field. An empty field inherits the relay’s value; a field set to 0 waives it on that route. A route therefore cannot switch a relay path off by leaving it blank; it can only replace it.
A route that sets only a rate is validated against the merged mapping, so it is accepted when the relay already names the units path. In the Web UI, Pricing Override on the route sheet shows the inherited value of each field as a placeholder and the merged formula underneath.

Worked examples

Tavily reports credits spent in its reply.
Response {"usage": {"credits": 4}}:

Test pricing

Test Pricing runs a sample call through a relay’s routes and mapping without contacting the upstream: which route matches, whether the call is counted, what each body yields and the resulting cost, with notes explaining every empty field.
The Web UI tests the saved relay, so save your pricing edits first. To preview a mapping before saving it, call the API with config instead of name (below).
  1. Open Relays, select the relay and choose Test Pricing.
  2. Enter the Method, Path (a query string may follow, as in /jobs/1?stream=true), the expected Status, any Request Headers a route matches on (one Name: value per line), the Request Body, the Response Body and its content type.
  3. Select Run Test.
The result is laid out like an itemised bill: the charge, the matched route, each part of the formula with the setting that produced it, and the formula written out with those numbers.

Next steps