# Pricing

Input is free. You pay per answer and per memory line written. This is the mirror image of TypeSafe's pricing for Jev (paid input tokens, free output): with Jers the state and the questions cost nothing however long they are, and each question answered is one answer.

The owner of the gateway sets the prices in `pricing.json` next to the keys file:

| Key | Meaning |
|---|---|
| `currency` | the currency of every amount |
| `per_answer` | charged for each question answered in `/v1/systemone` |
| `per_memory_line_written` | charged for each line `remember` adds and each rule `POST /v1/memory/rules` adds |
| `per_request` | usually 0 |
| `per_million_input_characters` | usually 0: input is free |
| `bill_engine_answers` | false: bill the answers asked for; true: every answer the engine computed |

Until the owner edits the file, the values are placeholders the code wrote, and the file says so.

## How it is counted

A decision is billed `usage.answers_billed` answers: one per question, times the work you asked for.

- `"robust": true` bills each choice once per option order the engine used (up to 3 by default; a 2-option choice has only 2 orders). Scores and yes/no questions are never asked in orders and bill 1.
- `"windows": true` bills every window the state was read in.
- `"memory": {"placebo": true}` bills the neutral pass as well, so twice.
- `"memory": {"compare": true}` (the same call without memory) and the extra rounds of a choice with more than 20 options are not billed, unless the owner sets `bill_engine_answers` in `pricing.json`, which bills every answer the engine computed.
- A cache hit is billed like the first call (with `bill_engine_answers`, one answer per question); `usage.cached` says it cost no engine work.

`usage.engine_answers` always reports the answers the engine computed, billed or not.

Every priced request is one line in your tenant's ledger with the time, the route, the counts and the cost, and is charged against your prepaid credit at once. `GET /v1/usage` returns credited, spent, balance, requests, the prices, your rate limit, your key ids, the ledger totals and the last twenty lines; the totals and the balance always agree. A request that fails upstream (502) or in the gateway (500) is not charged.

## Credit

Jers adds credit to your tenant after a payment. When the balance is zero or below, priced requests answer 402 until credit is added; `GET` routes still work so you can see the account.

## Rate limits

Each key has a limit of requests per minute, set for its tenant (default 600; 60 for a tenant made by sign-up). Over it, 429 with `Retry-After`.
