# Website and app copy

> Send the English text of a website or app (an i18n JSON file, Markdown pages, HTML, or a list of strings) and get the same file back in natural Persian: the same keys, placeholders, tags, links and code, with Persian text that reads as if it was written in Persian. Sequence: `POST /api/v1/content/translate` with `dryRun: true` (the price) → `POST /api/v1/content/translate` → the answer has `content`, or poll `GET /api/v1/content/jobs/{id}`.

## At a glance

- Base path: `/api/v1/content`
- Auth: `Authorization: Bearer fara_sk_...` ([Authentication](https://faraatarjomeh.com/api/v1/docs/authentication.md))
- Scope: `read` for GET, `write` for everything else
- Spends Fara: yes, `POST /api/v1/content/translate` (not with `dryRun: true`). Strings already in your translation memory are free.
- Price: the model's token cost at our rate, never more than the quote (`quote.maxFara`), which is held while the work runs.
- Async: small work (about 1,000 words of new text) answers in the same call; more answers 202 with a job.
- Terminal statuses: `completed`, `completed_partial`, `failed`
- Webhook events: `content.completed`, `content.completed_partial`, `content.failed`
- Results are kept 7 days.

## What you send

| Field | Meaning |
|---|---|
| `format` | `json` (any object or array), `markdown`, `html` (a page or a fragment), `strings` (a string or an array of strings). |
| `content` | The English text in that shape. |
| `brief` | One or two sentences: what the product is and who reads it. The Persian fits better with it. |
| `tone` | `neutral` (default), `formal`, `friendly`. |
| `glossary` | Terms that must be translated one way: `{ "dashboard": "پیشخوان", "Acme": "Acme" }`. A translation equal to the term keeps it in English. |
| `keep` | Names to leave in English everywhere: `["Acme", "Acme Cloud"]`. |
| `notes` | Per JSON key: where the string is used and a length limit: `{ "nav.signup": { "note": "button", "maxLength": 12 } }`. |
| `skipKeys` | `json`: key paths to leave as they are. Parts are joined by dots; `*` matches inside one part and `**` any number of parts: `meta.*`, `**.url`, `faq.*.q` (or `faq[*].q`). A pattern that matches no string is reported in `warnings`. |
| `project` | Your name for the site. Translation memory is kept per project. |
| `memory` | `use` (default), `refresh` (translate again), `off`. |
| `digits` | `persian` (default) or `latin`. |
| `dryRun` | `true`: only the price. |
| `async` | `true`: always answer 202 with a job. |

What is never changed:

- JSON keys, numbers, booleans, `null`, and string values that are data (ids like `user_id`, paths, file names, colours, dates). Leave out more with `skipKeys`.
- Placeholders: `{name}`, `{0}`, `{{count}}`, `${x}`, `%s`, `%1$d`, `%(name)s`; the frame of ICU `plural` and `select` messages (each form is translated in place); template tags (`{% %}`, `<% %>`).
- Tags in strings (`<b>…</b>`, `<0>…</0>`), links and e-mail addresses, HTML entities, line breaks, and the spacing next to a tag or a line break (`Tools,<br>not talk` comes back with no space before or after `<br>`).
- Markdown: code blocks and code spans, link and image addresses, front matter other than `title`, `description`, `summary`, `excerpt`, `subtitle` (change with `frontMatterKeys`), the table layout.
- HTML: every byte of markup outside the text. `<script>`, `<style>`, `<pre>`, `<code>`, `<svg>` and anything with `translate="no"` or `class="notranslate"` are left as they are. `alt`, `title`, `placeholder`, `aria-label`, button `value` and the page description `meta` tags are translated. A full page gets `lang="fa" dir="rtl"` on `<html>` (turn off with `setDirection: false`).

JSX and other code are not a format: send their strings as `json` or `strings`.

## Steps

### 1. Get the price

```http
POST /api/v1/content/translate HTTP/1.1
Authorization: Bearer fara_sk_...
Content-Type: application/json

{
  "format": "json",
  "content": { "hero": { "title": "Ship faster", "cta": "Start your free trial" }, "plans": "{n, plural, one {# project} other {# projects}}" },
  "brief": "Hosting for small online shops in Iran.",
  "project": "acme-site",
  "dryRun": true
}
```

Response `200 OK`:

```json
{ "object": "content_translation_quote", "quote": { "maxFara": 1, "characters": 62, "strings": 3, "translatable": 3, "fromMemory": 0, "toTranslate": 3, "repeated": 0, "runs": "now" } }
```

`maxFara` is the most the request can cost. Show it to the user before you send the request without `dryRun`. `repeated` counts sentences that repeat another string of the request: they are translated once, read the same everywhere, and cost nothing more (a single word is translated per key, because one English word can need two Persian words). When something in the request had no effect, the answer also has `warnings` (for example a `skipKeys` pattern that matched nothing).

```bash
curl -sS -X POST "https://faraatarjomeh.com/api/v1/content/translate" \
  -H "Authorization: Bearer $FARA_API_KEY" -H "Content-Type: application/json" \
  -d '{"format":"strings","content":["Save changes","Delete project?"],"dryRun":true}'
```

### 2. Translate

Send the same body without `dryRun`, with an `Idempotency-Key` (a new UUID per request; reuse it on retries).

Response `200 OK` (small work):

```json
{
  "id": "6740c1f2a9e4b1d2c3f4a5b6",
  "object": "content_translation",
  "status": "completed",
  "format": "json",
  "project": "acme-site",
  "counts": { "strings": 3, "translatable": 3, "fromMemory": 0, "translated": 3, "failed": 0 },
  "price": { "maxFara": 1, "chargedFara": 1 },
  "failed": [],
  "content": { "hero": { "title": "سریع‌تر منتشر کنید", "cta": "دورهٔ رایگان را شروع کنید" }, "plans": "{n, plural, one {# پروژه} other {# پروژه}}" },
  "createdAt": "2026-11-16T09:00:00.000Z",
  "updatedAt": "2026-11-16T09:00:09.000Z",
  "completedAt": "2026-11-16T09:00:09.000Z",
  "links": { "self": "https://faraatarjomeh.com/api/v1/content/jobs/6740c1f2a9e4b1d2c3f4a5b6" }
}
```

Response `202 Accepted` (more work, or `async: true`): the same job with `status: "queued"` or `"running"` and no `content`, plus `quote`. Poll `links.self` (first after 10 s, then every 30–60 s) or wait for a `content.completed` webhook.

When every string comes from memory, the answer is `200` at once with `id: null`, `content`, and nothing charged.

### 3. Check `failed`

Every string is checked before it is returned: all placeholders and tags kept, no English left behind, the `maxLength` kept. A string that still fails after a second try is listed in `failed` with its key and reason, and keeps its English text in `content`. The job is then `completed_partial`. Send those strings again, or change the note or limit.

## Translation memory

Each account has its own memory, per `project`. A string translated before (same text, note, tone, digits and glossary terms) comes back the same and costs nothing. So when your site changes, send the whole file again: only new and changed strings are translated and charged, and the rest stay word for word as before.

- `memory: "refresh"` translates everything again and saves the new Persian.
- `DELETE /api/v1/content/memory?project=acme-site` clears one project; without `project`, all of it.
- Memory not used for a year is removed on its own.

## Errors

| Code | When | What to do |
|---|---|---|
| `CONTENT_FORMAT_INVALID` (400) | `content` does not match `format`. | Fix the request. |
| `BAD_REQUEST` (400) | A field is wrong; `detail` names it. | Fix the request. |
| `CONTENT_TOO_LARGE` (413) | More than 20,000 strings or 1,000,000 characters. | Split the content; memory keeps terms the same. |
| `INSUFFICIENT_CREDITS` (402) | The balance is below `maxFara`. | Tell the user to top up. |
| `JOB_NOT_FINISHED` (409) | Delete of a running job. | Wait for it to finish. |

## Limits

| Limit | Value |
|---|---|
| Strings per request | 20,000 |
| Text per request | 1,000,000 characters |
| Answered in the same call | about 6,000 characters (≈1,000 words) of new text |
| Glossary | 500 terms |
| Rate limits | 120 requests per 60 s per API key |
