# Billing and Fara

> All paid work is charged in Fara from the API key owner's account, exactly like on the website. Get the price first, check `GET /api/v1/account`, then create the job. Fara is held when the job starts, the real cost is charged when it finishes, and unused or failed amounts come back.

## At a glance

- Currency: Fara (integer amounts). 100 Fara = 1 US dollar of list price.
- Balance: `GET /api/v1/account` → `credits.balance` (spendable now) and `credits.reserved` (held by running jobs, already taken out of `balance`)
- Ledger: `GET /api/v1/account/transactions` (cursor paging, `?jobId=` filter)
- Buying Fara: website only (https://faraatarjomeh.com/pricing, https://faraatarjomeh.com/profile). An API key cannot buy. Pack prices are listed before value added tax; the tax (`vatRate` in `GET /api/v1/payment/packages`) is added at checkout and does not change the Fara you get.
- Not enough Fara: `402` with code `INSUFFICIENT_CREDITS`
- Retrying a paid POST safely: `Idempotency-Key` header — see [Conventions](https://faraatarjomeh.com/api/v1/docs/conventions.md#idempotency)

## Check the balance

```http
GET /api/v1/account HTTP/1.1
Authorization: Bearer fara_sk_...
```

```json
{
  "id": "66f1c0a2b4e5d6f7a8b9c0d1",
  "email": "owner@example.com",
  "emailVerified": true,
  "credits": {
    "currency": "FARA",
    "faraPerUsd": 100,
    "balance": 460,
    "reserved": 40,
    "chargebackLiability": 0,
    "lifetimeUsage": 1210,
    "lastTransactionAt": "2026-09-25T10:12:03.120Z"
  },
  "auth": { "type": "api_key", "keyId": "66f1c0a2b4e5d6f7a8b9c0ff", "scopes": ["read", "write"] }
}
```

| Field | Meaning |
|---|---|
| `credits.balance` | Fara you can spend now. Holds for running jobs are already subtracted. |
| `credits.reserved` | Fara held for jobs that have not finished. Shown for information; do not subtract it again. |
| `credits.chargebackLiability` | If above 0, a payment was reversed; no new Fara can be held until it is settled (`402 CHARGEBACK_LIABILITY_OUTSTANDING`). |

## Where each price comes from

| Feature | Price call | Price field |
|---|---|---|
| PDF translation | `POST /api/v1/translate/analyze` (or the analysis stream) | price estimates per quality level — see [PDF translation](https://faraatarjomeh.com/api/v1/docs/guides/pdf-translation.md) |
| Translation tools (slides, mind map, LinkedIn, proofread) | none — the cost is small and depends on the text; it is held before and charged after | `faraCost` in the response |
| Video | `POST /api/v1/video/jobs/estimate` | per output mode |
| Meeting minutes | `GET /api/v1/meetings/pricing` | `faraPerMin` |
| Podcast / audiobook | `GET /api/v1/audio/pricing` | per minute, and the hold for the longest length |
| Persian text-to-speech | `GET /api/v1/farsi-tts/pricing` | per minute of speech |
| Transcription | `GET /api/v1/transcription/pricing` | per minute, with and without translation |
| Meeting tools (early access) | `POST /api/v1/meetings/estimate` | hold per tool; see [Meetings: early-access features](https://faraatarjomeh.com/api/v1/docs/guides/meeting-extras.md#paid-tools) |

PDF translation has one price. Every translation starts at once and runs fast (`executionMode: "realtime"`, or leave it out). `executionMode: "economy_batch"` is still accepted and runs as `realtime`.

## Life of a charge

| Step | What happens to Fara | Ledger rows |
|---|---|---|
| Job is created (media jobs, tools) or starts running (PDF translation) | The estimated amount is **held**: taken out of `balance`, counted in `reserved` | `credit_hold` (`settlementStatus: "reserved"`) |
| Job finishes | The **real cost** is charged. If the hold was larger, the difference comes back. | hold → `settlementStatus: "charged"`; `credit_refund` for the difference, or an extra `*_charge` row if the real cost was higher |
| Job fails or is cancelled | The whole hold comes back | `credit_refund` (hold → `settlementStatus: "released"`) |
| Job was charged but its result could not be delivered | The charge is refunded in full | `service_failure_refund` |

Rules by feature:

- **PDF translation:** the balance is checked when you start (`402` if too low). The hold is taken when the job actually starts running; if the balance dropped below the price in between, the job fails with `customerErrorCode: "INSUFFICIENT_CREDITS"` and nothing is charged. The final charge is the real cost, which can differ from the estimate. If more than half of the document could not be translated and stays in English, nothing is charged. Economy jobs are charged the real economy cost.
- **Video, meeting minutes, podcast/audiobook, Persian text-to-speech, transcription:** the hold is taken when you create the job. The final charge is the real cost. If it is above the hold, the difference is charged as an extra ledger row when your balance covers it; if it does not, only the hold is charged.
- **Translation tools** (slides, mind map, LinkedIn posts, proofreading): synchronous. Fara is held before the result is made and charged right after; the response has `faraCost`. Each POST makes a new result and a new charge — always send an `Idempotency-Key`.
- **Section resends** (`POST /api/v1/translate/{jobId}/resend-chunks`): held before, charged for what was re-translated; nothing if nothing succeeded.
- **Free:** analysis, estimates, pricing, status, downloads, the document summary, and re-making files from results you already paid for (custom PDF, slide files, mind map PDF, summary PDF, regenerate).

## What did a job cost?

The real cost of a job is the **sum of `balanceChange`** of its ledger rows (negative = spent):

```http
GET /api/v1/account/transactions?jobId=3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70&limit=100 HTTP/1.1
Authorization: Bearer fara_sk_...
```

```json
{
  "data": [
    { "id": "66f1c2...", "type": "credit_refund", "amount": 12, "balanceChange": 12, "balanceAfter": 472,
      "jobId": "3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70", "relatedJobId": "3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70",
      "description": "Refund for overestimated hold on job 3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70", "createdAt": "2026-09-25T10:40:00.000Z" },
    { "id": "66f1c1...", "type": "credit_hold", "amount": 40, "balanceChange": -40, "balanceAfter": 460,
      "jobId": "3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70", "relatedJobId": "3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70",
      "description": "Credit hold for translation job 3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70", "settlementStatus": "charged", "createdAt": "2026-09-25T10:12:03.000Z" }
  ],
  "hasMore": false,
  "nextCursor": null
}
```

Here the job cost 40 − 12 = **28 Fara**. The `jobId` filter also returns the job's tool charges and section resends, which are stored under derived ids (`slides-<jobId>-<time>`, `chunk-resend:<jobId>:<id>`, `video-reprocess-<id>-<time>`); `relatedJobId` always names the parent job.

A hold still in `settlementStatus: "reserved"` or `"pending_finalization"` is not final yet.

### Ledger row types

| `type` | Direction | Meaning |
|---|---|---|
| `credit_hold` | − | Fara held for a job (see `settlementStatus`) |
| `credit_refund` | + | Unused or released hold returned |
| `translation_charge`, `video_charge`, `meeting_charge`, `audio_charge`, `farsi_tts_charge`, `transcription_charge`, `knowledge_charge` | − | Extra charge when the real cost was higher than the hold |
| `service_failure_refund` | + | Full refund of a charged job whose result could not be delivered |
| `zarinpal_topup` | + | Fara bought on the website |
| `signup_bonus`, `launch_bonus`, `admin_topup` | + | Free Fara added to the account |
| `admin_deduct`, `payment_chargeback` | − | Removed by support, or a reversed payment |
| `credit_hold_superseded`, `credit_refund_superseded` | − / + | An earlier, released attempt of the same job (its hold and its refund). The pair cancels out. |

## Not enough Fara

```json
{
  "type": "https://faraatarjomeh.com/api/v1/docs/errors#error-insufficient-credits",
  "title": "Payment Required",
  "status": 402,
  "detail": "Insufficient credits",
  "instance": "/api/v1/translate/start/3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70",
  "code": "INSUFFICIENT_CREDITS",
  "request_id": "b7c1e0f4-…",
  "balance": 12,
  "estimatedCost": 40
}
```

Depending on the endpoint the body has `balance` with `estimatedCost`, `cost` (with `faraCharged`), or `required`. Do not retry; the owner must buy Fara on the website first. No hold was taken.

## Spend limits per API key (early access)

The account owner can give an API key a spend limit (`{ "fara": 500, "period": "month" }`, or `"day"`; UTC) on the website. Every hold taken with that key counts; released holds and refunds give the room back. A hold that would pass the limit answers `402` [`SPEND_LIMIT_REACHED`](https://faraatarjomeh.com/api/v1/docs/errors.md#error-spend-limit-reached) with `spendLimit`, `spent` and `required`. The account balance is not touched, and topping up does not help: the owner raises the limit, or the period rolls over.

## Avoiding double charges

- Send `Idempotency-Key` on every POST that spends Fara. A retry with the same key returns the first answer and runs nothing again.
- Starting the same analyzed translation twice cannot charge twice: once started, the job is no longer `analyzed` and a second start is refused with `400` ("Cannot start job with status …"), or `409` if both calls arrive at the same moment.
- Creating a second audio job for the same translation while one runs is refused with `409 DUPLICATE_JOB`.
- A meeting job and an audio-to-text job for the same recording are two jobs, and each is charged (the recording is transcribed once, but both jobs pay). For minutes and a transcript, create only the meeting job and download its transcript with `GET /api/v1/meetings/jobs/{id}/transcript?format=json|txt|srt|vtt` (early access).
- Translation tools and the one-call endpoints (`POST /api/v1/translate/upload`, `POST /api/v1/translate/magazine-translate-pdf`) have no other duplicate guard: without an `Idempotency-Key`, a repeated POST is a second paid request.
