# For language models

https://ghazalai.ir/docs/agents-en/

> Give Ghazal to your agent so it writes better Persian: the loop, what not to fix, a paragraph for a system prompt, the tool definition and the MCP server.

Ghazal checks and corrects Persian (Farsi) writing: spelling, spacing and the half-space (ZWNJ, U+200C), punctuation, Arabic letters and digits that should be Persian, and spoken forms in formal text. An agent hands every Persian text to `fix` before it delivers it, and delivers the corrected text. A free key is required. Sign in and make one on the [account page](/account/). This page is also in Persian: [برای مدل‌های زبانی](/docs/agents/).

## The loop

1. Write the text.
2. `POST https://ghazalai.ir/api/v1/fix` with `{"text": "...", "apply": "house"}` and headers `content-type: application/json` and `Authorization: Bearer gz_...`; add `"format": "markdown"` if the text is Markdown. If you know the kind of text, send `kind` too: `formal` for edited writing, `colloquial` for spoken Persian written down.
3. Use the answer's `text` in place of yours.
4. Look at `left`. `house` applies style findings with one suggestion. Advice is optional. `spell.*` and `guess` findings are guesses: take one only if you are sure that word was meant.
5. Run it again only if you changed the text.

If you show suggestions to a person and they take or reject one, send [`feedback`](/docs/feedback/). On `429` or `503`, wait `Retry-After` seconds; on `413`, send the text paragraph by paragraph; on `422`, read `message` and fix the field it names. [Errors](/docs/errors/)

## Long documents

With a personal plan, corporate plan or pack, `check` and `fix` accept one text of up to 200,000 characters and answer it piece by piece; free keys stay at 20,000. Each answer says how far it got in `checked_to` (Unicode code points, even with `offsets: utf16`). While that is short of the end, send the same text and options again with `from: checked_to`. Only the checked range is charged. Here `fix` sends a POST to `/api/v1/fix`:

```python
at, corrected = 0, []
while at < len(text):
    r = fix(text=text, offsets="codepoint", **{"from": at})
    corrected.append(r["text"]); at = r.get("checked_to", len(text))
text = "".join(corrected)
```

Join each returned `text` with nothing between. `applied` points into the text you sent, `left` into the `text` of the same answer; add the length already joined to place a `left` finding in the whole. Each piece is read with 2,048 characters on either side, so now and then a result differs from checking the same text in one piece. `fix.py` in the skill folder runs this loop for you.

## Text written by a language model

Send `"profile": "llm"` to `check`, `fix`, `check_persian` or `fix_persian` for Persian written by a language model. For friendly written prose, also send `"kind": "formal"`; for chat, use `"kind": "colloquial"`. The profile leaves register detection unchanged.

```json
{"text": "این سوال می‌باشد.", "profile": "llm", "kind": "formal"}
```

I reviewed a sample of each rule's findings before choosing its level. The profile keeps a fixed set of rule ids and changes their levels. It leaves each rule's detection, spans and suggestions unchanged. Omit `profile` to keep the existing answers.

| Precision in the reviewed sample | Level |
|---|---|
| At least 95% | `error` |
| At least 85%, below 95% | `advice` |
| Below 85%, or no findings | Omitted |

Style findings, where both forms are right, stay `style`, so `apply: house` applies them as before. These levels come from the same texts used to choose the rules; I have not tested them on separate texts. Some rules had only one or two findings.

`house` sets writing preferences before the profile filters findings. `only` narrows the profile, `disable` removes rules, and `min_severity` uses the profile's levels. None can add a rule outside the profile. `max_findings` limits the remaining findings as usual. For example, `house.quotes: keep` suppresses quote changes; `house.ezafe: hamza` selects Academy spelling, whose ezafe rule is outside this profile.

`fix` uses these levels for `apply`: `sure` applies errors with suggestions, except `spell.*`; `house` also applies style findings with one suggestion; `all` also applies advice and spelling suggestions. Findings without a suggestion remain in `left`. Review them before delivery.

The profile omits the rules for ellipses, Latin digits and spaces around punctuation: template blanks, emoji and English quotations made too many of their findings wrong. A profile of existing rules also cannot add a check for calques.

### Rules in the profile

| Rule | Level |
|---|---|
| `academy.copula_after_silent_he` | `error` |
| `academy.plural_ha_after_silent_he` | `error` |
| `academy.ya_nakare_after_silent_he` | `error` |
| `confuse.gozar` | `error` |
| `confuse.hamza` | `error` |
| `confuse.khast` | `error` |
| `consistency.spelling` | `advice` |
| `ghazal.arabic_digits` | `error` |
| `ghazal.compounds` | `advice` |
| `ghazal.ezafe_after_silent_he` | `error` |
| `ghazal.guillemets` | `error` |
| `ghazal.house_forms` | `error` |
| `ghazal.latin_punctuation` | `error` |
| `ghazal.mi_prefix` | `error` |
| `ghazal.persian_letters` | `error` |
| `ghazal.plural_space` | `error` |
| `ghazal.redundant_zwnj` | `error` |
| `ghazal.spaced_ezafe_yeh` | `error` |
| `ghazal.tatweel` | `error` |
| `prose.affix` | `error` |
| `prose.arabic_plural` | `error` |
| `prose.office` | `error` |
| `prose.participle` | `error` |
| `register.clitic` | `error` |
| `register.verb` | `error` |
| `register.word` | `error` |
| `spacing.after_mark` | `error` |
| `spacing.mi` | `error` |
| `spell.be` | `error` |
| `spell.glued` | `advice` |

## What not to fix

Ghazal does not know which part of a text is someone else's. Don't send these, or don't take their suggestions:

- Quotations: other people's words stay as they said them. A Markdown quote (`>`) counts as prose and is checked.
- Names: people, companies, books and brands are spelled the way their owners spell them.
- Verse: the spelling and spacing of poetry, classical poetry above all, is sometimes deliberate.
- Code, commands and URLs: in Markdown, put them in `` ` `` or ```` ``` ```` and send `"format": "markdown"`; they come back untouched. [Markdown](/docs/markdown/)

The simplest way is to send only your own prose. If a quotation or a poem sits inside the text, send the paragraphs as `texts` and leave those out, or call `check` and don't apply findings that fall inside them.

## A ready-made skill

For Claude Code and other tools that read skills there is a folder to copy: [SKILL.md](/skill/ghazal-persian/SKILL.md), [the writing guide](/skill/ghazal-persian/guide.md) and [fix.py](/skill/ghazal-persian/fix.py). Put the three files in a folder named `ghazal-persian` among your skills. Set `GHAZAL_KEY` to your key. Read SKILL.md once; it includes the guide. Write the text to its delivery file, then run `python3 <the skill folder>/fix.py FILE` from wherever you are. The file is corrected in place; stdout gives the change count and the advice and spelling guesses left to decide. `.txt` is plain text; other files are Markdown. Add `--text` to force plain text, `--kind colloquial` when spoken Persian was asked for, or `--style academy` when the text already writes «خانهٔ». `--sure-only` leaves style choices as written. Files above the key’s request limit are sent in parts. You do not need to read guide.md or fix.py separately.

## A paragraph for a system prompt or AGENTS.md

```text
Before delivering Persian prose you wrote or edited, call Ghazal fix with {"text": "<the text>", "apply": "house"}; send format: markdown for Markdown, kind: colloquial when spoken Persian was asked for, and style: academy when the text already writes «خانهٔ». Use the returned text. Decide the advice and spelling guesses in left; accept a guess only if you are sure that word was meant. Leave quotations, names, verse, code and URLs alone. Send only your own prose; for a document containing protected passages, call check and apply findings only outside them. Run fix again only if you changed the text.
```

## Tool definitions

Copy either `tools` block into your request. Each has `ghazal_fix` and `ghazal_check`; send their arguments to `/api/v1/fix` and `/api/v1/check`. The descriptions and schemas come from [OpenAPI](/api/v1/openapi.json). Rebuild them with `python scripts/build_agent_tools.py` from the repository root.

<!-- tools -->
### OpenAI

```json
{
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "ghazal_fix",
        "description": "Returns the text corrected. `applied` lists what was changed (offsets into the text sent; the first suggestion\nwas used), `left` what is still worth a look (offsets into the returned text). With `apply: sure` only errors\nthat have a suggestion and are not spelling guesses (`spell.*`) are applied.\n`apply: house` also applies style findings with exactly one suggestion, never spelling guesses or advice.\nWith `profile: llm`, these choices use the profile's levels; style findings stay style, and `spell.*` still needs `apply: all`.\nFor short texts, fixing the returned text again changes nothing. With `format: markdown` code, URLs and markup come back unchanged.\nFor a document over 20,000 characters, `text` is the corrected range from `from` to `checked_to`.\n`applied` points into the original complete text; `left` points into this answer's corrected `text`, using `offsets`.\nAppend each returned `text` without separators; add the length already joined, in `offsets`, to each new `left` offset.\nA finding crossing a cut keeps its full `end`, which may exceed `checked_to` for `applied` or the returned text's length for `left`.\nSend the same original text and options with `from: checked_to` until the end. Only the checked range is charged.\nShort texts have no `checked_to`.\nWith `compact`, `applied` and `left` are lines as in `check`'s compact answer\n(`applied` without `@start`).",
        "parameters": {
          "properties": {
            "style": {"type": "string", "enum": ["ghazal", "academy"], "title": "Style", "description": "`ghazal`: Ghazal's house style. `academy`: the spelling rules of the Academy of Persian Language and Literature.", "default": "ghazal"},
            "house": {"anyOf": [{"properties": {"ezafe": {"anyOf": [{"type": "string", "enum": ["ye", "hamza"]}, {"type": "null"}], "title": "Ezafe", "description": "`ye`: خانه‌ی (`style: ghazal`); `hamza`: خانهٔ (`style: academy`). Omit to follow `style`. If both are sent, they must agree."}, "digits": {"type": "string", "enum": ["persian", "latin", "keep"], "title": "Digits", "description": "`persian`: ۱۲۳; `latin`: replace Persian and Arabic-Indic digits with 123 in Persian prose, outside code, URLs, Latin text and anything Markdown skips; `keep`: leave digits as written.", "default": "persian"}, "quotes": {"type": "string", "enum": ["guillemets", "keep"], "title": "Quotes", "description": "`guillemets`: «» for Persian quotations; `keep`: leave quotation marks as written.", "default": "guillemets"}}, "additionalProperties": false, "type": "object", "title": "House"}, {"type": "null"}], "description": "Optional writing preferences. Omit this object to keep the existing behaviour; omitted keys keep their defaults."},
            "words": {"items": {"type": "string", "maxLength": 60, "minLength": 1, "pattern": "^(?:[^\\W_]|[ً-ٰٟـ])+(?:‌(?:[^\\W_]|[ً-ٰٟـ])+)*$"}, "type": "array", "maxItems": 500, "title": "Words", "description": "Personal words, at most 500 entries of one word each, at most 60 characters, without spaces. Matching uses the spell checker's folding of Arabic letters, half-spaces and marks. Only spell.* and confuse.* findings are hidden. Omit or send [] to keep the existing answers.", "default": []},
            "text": {"anyOf": [{"type": "string"}, {"type": "null"}], "title": "Text", "description": "The text to check: up to 200,000 characters with a personal plan, corporate plan or pack, otherwise 20,000. Send `text` or `texts`, not both."},
            "texts": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Texts", "description": "Several texts, at most 20,000 characters in all with a newline between each, checked one by one; the answer has `results` in the same order."},
            "from": {"type": "integer", "minimum": 0.0, "title": "From", "description": "Resume at a previous `checked_to`, in Unicode code points. Send the same complete text and options; omit on the first call.", "default": 0},
            "kind": {"type": "string", "enum": ["auto", "formal", "mixed", "colloquial"], "title": "Kind", "description": "What kind of Persian the text is. `auto` decides from the words; spoken forms are flagged only in `formal` text.", "default": "auto"},
            "offsets": {"type": "string", "enum": ["utf16", "codepoint"], "title": "Offsets", "description": "How `start` and `end` count: UTF-16 code units (JavaScript strings) or Unicode code points (Python strings).", "default": "utf16"},
            "format": {"type": "string", "enum": ["text", "markdown"], "title": "Format", "description": "`markdown`: code, URLs, HTML, front matter and Markdown's own marks are left alone; only the prose is checked. Offsets still point into the text as sent.", "default": "text"},
            "profile": {"anyOf": [{"type": "string", "const": "llm"}, {"type": "null"}], "title": "Profile", "description": "`llm`: keep a fixed set of rules reviewed on Persian written by language models, at error or advice level; style findings, where both forms are right, stay style. Apply house preferences first, then the profile, then only, disable and min_severity. These options cannot add rules outside the profile. Rule detection and kind stay unchanged; use kind: formal for friendly written prose. Omit for the existing answers."},
            "only": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Only", "description": "Report only these rules: ids like `ghazal.mi_prefix`, or prefixes ending in a dot like `spell.`."},
            "disable": {"items": {"type": "string"}, "type": "array", "title": "Disable", "description": "Never report these rules (ids or prefixes, as in `only`).", "default": []},
            "min_severity": {"type": "string", "enum": ["style", "guess", "advice", "error"], "title": "Min Severity", "description": "Report only findings of this severity or higher: style < guess < advice < error.", "default": "style"},
            "max_findings": {"anyOf": [{"type": "integer", "minimum": 0.0}, {"type": "null"}], "title": "Max Findings", "description": "Report at most this many findings per text, the first in the text. For a long document, this limit applies to each response."},
            "compact": {"type": "boolean", "title": "Compact", "description": "Answer in few tokens, for a language model: findings as one line each, no nulls, only what a model needs.", "default": false},
            "apply": {"type": "string", "enum": ["sure", "house", "all"], "title": "Apply", "description": "`sure`: only errors with a suggestion, not spelling guesses (the site's «fix all»). `house`: also applies style findings with exactly one suggestion, never spelling guesses or advice. `all`: every finding with a suggestion.", "default": "sure"}
          },
          "additionalProperties": false,
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "ghazal_check",
        "description": "Finds what to correct. Each finding has `start` and `end` (where it is in the text), `text` (what is there),\n`suggestions` (what to write instead, best first; empty when there is no single fix), `rule` (explained in\nGET /api/v1/rules), `severity` (`error`: careful writers don't write it this way; `advice`: a source recommends\nit; `guess`: a model's guess, check it; `style`: both are right, the chosen style prefers this) and `confidence`\n(for guesses). With `profile: llm`, levels come from the review of Persian written by language models: at least 95% right for\n`error`, at least 85% for `advice`; other rules are omitted. Style findings stay `style`.\nConsistency findings also have a `reason` card with the two spellings and their counts.\n`register` is [spoken, written] evidence; `kind` is the kind of Persian the text was checked as;\nfor a long document both describe the whole text. `checked_to` and `from` count Unicode code points.\nSend the same whole text with `from: checked_to` to continue; only the checked range is charged.\nFinding offsets point into the whole text as sent. A cut that the server would not make gives 422.\nA finding that crosses a cut belongs to the piece containing its start; its end may exceed `checked_to`.\n`left_today` is what a key may still send today (null for own typing or with accounts off). With `compact`, each finding is one line:\n`@start «text» → «suggestion» | «another» rule severity`, and a guess's confidence last.",
        "parameters": {
          "properties": {
            "style": {"type": "string", "enum": ["ghazal", "academy"], "title": "Style", "description": "`ghazal`: Ghazal's house style. `academy`: the spelling rules of the Academy of Persian Language and Literature.", "default": "ghazal"},
            "house": {"anyOf": [{"properties": {"ezafe": {"anyOf": [{"type": "string", "enum": ["ye", "hamza"]}, {"type": "null"}], "title": "Ezafe", "description": "`ye`: خانه‌ی (`style: ghazal`); `hamza`: خانهٔ (`style: academy`). Omit to follow `style`. If both are sent, they must agree."}, "digits": {"type": "string", "enum": ["persian", "latin", "keep"], "title": "Digits", "description": "`persian`: ۱۲۳; `latin`: replace Persian and Arabic-Indic digits with 123 in Persian prose, outside code, URLs, Latin text and anything Markdown skips; `keep`: leave digits as written.", "default": "persian"}, "quotes": {"type": "string", "enum": ["guillemets", "keep"], "title": "Quotes", "description": "`guillemets`: «» for Persian quotations; `keep`: leave quotation marks as written.", "default": "guillemets"}}, "additionalProperties": false, "type": "object", "title": "House"}, {"type": "null"}], "description": "Optional writing preferences. Omit this object to keep the existing behaviour; omitted keys keep their defaults."},
            "words": {"items": {"type": "string", "maxLength": 60, "minLength": 1, "pattern": "^(?:[^\\W_]|[ً-ٰٟـ])+(?:‌(?:[^\\W_]|[ً-ٰٟـ])+)*$"}, "type": "array", "maxItems": 500, "title": "Words", "description": "Personal words, at most 500 entries of one word each, at most 60 characters, without spaces. Matching uses the spell checker's folding of Arabic letters, half-spaces and marks. Only spell.* and confuse.* findings are hidden. Omit or send [] to keep the existing answers.", "default": []},
            "text": {"anyOf": [{"type": "string"}, {"type": "null"}], "title": "Text", "description": "The text to check: up to 200,000 characters with a personal plan, corporate plan or pack, otherwise 20,000. Send `text` or `texts`, not both."},
            "texts": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Texts", "description": "Several texts, at most 20,000 characters in all with a newline between each, checked one by one; the answer has `results` in the same order."},
            "from": {"type": "integer", "minimum": 0.0, "title": "From", "description": "Resume at a previous `checked_to`, in Unicode code points. Send the same complete text and options; omit on the first call.", "default": 0},
            "kind": {"type": "string", "enum": ["auto", "formal", "mixed", "colloquial"], "title": "Kind", "description": "What kind of Persian the text is. `auto` decides from the words; spoken forms are flagged only in `formal` text.", "default": "auto"},
            "offsets": {"type": "string", "enum": ["utf16", "codepoint"], "title": "Offsets", "description": "How `start` and `end` count: UTF-16 code units (JavaScript strings) or Unicode code points (Python strings).", "default": "utf16"},
            "format": {"type": "string", "enum": ["text", "markdown"], "title": "Format", "description": "`markdown`: code, URLs, HTML, front matter and Markdown's own marks are left alone; only the prose is checked. Offsets still point into the text as sent.", "default": "text"},
            "profile": {"anyOf": [{"type": "string", "const": "llm"}, {"type": "null"}], "title": "Profile", "description": "`llm`: keep a fixed set of rules reviewed on Persian written by language models, at error or advice level; style findings, where both forms are right, stay style. Apply house preferences first, then the profile, then only, disable and min_severity. These options cannot add rules outside the profile. Rule detection and kind stay unchanged; use kind: formal for friendly written prose. Omit for the existing answers."},
            "only": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Only", "description": "Report only these rules: ids like `ghazal.mi_prefix`, or prefixes ending in a dot like `spell.`."},
            "disable": {"items": {"type": "string"}, "type": "array", "title": "Disable", "description": "Never report these rules (ids or prefixes, as in `only`).", "default": []},
            "min_severity": {"type": "string", "enum": ["style", "guess", "advice", "error"], "title": "Min Severity", "description": "Report only findings of this severity or higher: style < guess < advice < error.", "default": "style"},
            "max_findings": {"anyOf": [{"type": "integer", "minimum": 0.0}, {"type": "null"}], "title": "Max Findings", "description": "Report at most this many findings per text, the first in the text. For a long document, this limit applies to each response."},
            "compact": {"type": "boolean", "title": "Compact", "description": "Answer in few tokens, for a language model: findings as one line each, no nulls, only what a model needs.", "default": false}
          },
          "additionalProperties": false,
          "type": "object"
        }
      }
    }
  ]
}
```

### Anthropic

```json
{
  "tools": [
    {
      "name": "ghazal_fix",
      "description": "Returns the text corrected. `applied` lists what was changed (offsets into the text sent; the first suggestion\nwas used), `left` what is still worth a look (offsets into the returned text). With `apply: sure` only errors\nthat have a suggestion and are not spelling guesses (`spell.*`) are applied.\n`apply: house` also applies style findings with exactly one suggestion, never spelling guesses or advice.\nWith `profile: llm`, these choices use the profile's levels; style findings stay style, and `spell.*` still needs `apply: all`.\nFor short texts, fixing the returned text again changes nothing. With `format: markdown` code, URLs and markup come back unchanged.\nFor a document over 20,000 characters, `text` is the corrected range from `from` to `checked_to`.\n`applied` points into the original complete text; `left` points into this answer's corrected `text`, using `offsets`.\nAppend each returned `text` without separators; add the length already joined, in `offsets`, to each new `left` offset.\nA finding crossing a cut keeps its full `end`, which may exceed `checked_to` for `applied` or the returned text's length for `left`.\nSend the same original text and options with `from: checked_to` until the end. Only the checked range is charged.\nShort texts have no `checked_to`.\nWith `compact`, `applied` and `left` are lines as in `check`'s compact answer\n(`applied` without `@start`).",
      "input_schema": {
        "properties": {
          "style": {"type": "string", "enum": ["ghazal", "academy"], "title": "Style", "description": "`ghazal`: Ghazal's house style. `academy`: the spelling rules of the Academy of Persian Language and Literature.", "default": "ghazal"},
          "house": {"anyOf": [{"properties": {"ezafe": {"anyOf": [{"type": "string", "enum": ["ye", "hamza"]}, {"type": "null"}], "title": "Ezafe", "description": "`ye`: خانه‌ی (`style: ghazal`); `hamza`: خانهٔ (`style: academy`). Omit to follow `style`. If both are sent, they must agree."}, "digits": {"type": "string", "enum": ["persian", "latin", "keep"], "title": "Digits", "description": "`persian`: ۱۲۳; `latin`: replace Persian and Arabic-Indic digits with 123 in Persian prose, outside code, URLs, Latin text and anything Markdown skips; `keep`: leave digits as written.", "default": "persian"}, "quotes": {"type": "string", "enum": ["guillemets", "keep"], "title": "Quotes", "description": "`guillemets`: «» for Persian quotations; `keep`: leave quotation marks as written.", "default": "guillemets"}}, "additionalProperties": false, "type": "object", "title": "House"}, {"type": "null"}], "description": "Optional writing preferences. Omit this object to keep the existing behaviour; omitted keys keep their defaults."},
          "words": {"items": {"type": "string", "maxLength": 60, "minLength": 1, "pattern": "^(?:[^\\W_]|[ً-ٰٟـ])+(?:‌(?:[^\\W_]|[ً-ٰٟـ])+)*$"}, "type": "array", "maxItems": 500, "title": "Words", "description": "Personal words, at most 500 entries of one word each, at most 60 characters, without spaces. Matching uses the spell checker's folding of Arabic letters, half-spaces and marks. Only spell.* and confuse.* findings are hidden. Omit or send [] to keep the existing answers.", "default": []},
          "text": {"anyOf": [{"type": "string"}, {"type": "null"}], "title": "Text", "description": "The text to check: up to 200,000 characters with a personal plan, corporate plan or pack, otherwise 20,000. Send `text` or `texts`, not both."},
          "texts": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Texts", "description": "Several texts, at most 20,000 characters in all with a newline between each, checked one by one; the answer has `results` in the same order."},
          "from": {"type": "integer", "minimum": 0.0, "title": "From", "description": "Resume at a previous `checked_to`, in Unicode code points. Send the same complete text and options; omit on the first call.", "default": 0},
          "kind": {"type": "string", "enum": ["auto", "formal", "mixed", "colloquial"], "title": "Kind", "description": "What kind of Persian the text is. `auto` decides from the words; spoken forms are flagged only in `formal` text.", "default": "auto"},
          "offsets": {"type": "string", "enum": ["utf16", "codepoint"], "title": "Offsets", "description": "How `start` and `end` count: UTF-16 code units (JavaScript strings) or Unicode code points (Python strings).", "default": "utf16"},
          "format": {"type": "string", "enum": ["text", "markdown"], "title": "Format", "description": "`markdown`: code, URLs, HTML, front matter and Markdown's own marks are left alone; only the prose is checked. Offsets still point into the text as sent.", "default": "text"},
          "profile": {"anyOf": [{"type": "string", "const": "llm"}, {"type": "null"}], "title": "Profile", "description": "`llm`: keep a fixed set of rules reviewed on Persian written by language models, at error or advice level; style findings, where both forms are right, stay style. Apply house preferences first, then the profile, then only, disable and min_severity. These options cannot add rules outside the profile. Rule detection and kind stay unchanged; use kind: formal for friendly written prose. Omit for the existing answers."},
          "only": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Only", "description": "Report only these rules: ids like `ghazal.mi_prefix`, or prefixes ending in a dot like `spell.`."},
          "disable": {"items": {"type": "string"}, "type": "array", "title": "Disable", "description": "Never report these rules (ids or prefixes, as in `only`).", "default": []},
          "min_severity": {"type": "string", "enum": ["style", "guess", "advice", "error"], "title": "Min Severity", "description": "Report only findings of this severity or higher: style < guess < advice < error.", "default": "style"},
          "max_findings": {"anyOf": [{"type": "integer", "minimum": 0.0}, {"type": "null"}], "title": "Max Findings", "description": "Report at most this many findings per text, the first in the text. For a long document, this limit applies to each response."},
          "compact": {"type": "boolean", "title": "Compact", "description": "Answer in few tokens, for a language model: findings as one line each, no nulls, only what a model needs.", "default": false},
          "apply": {"type": "string", "enum": ["sure", "house", "all"], "title": "Apply", "description": "`sure`: only errors with a suggestion, not spelling guesses (the site's «fix all»). `house`: also applies style findings with exactly one suggestion, never spelling guesses or advice. `all`: every finding with a suggestion.", "default": "sure"}
        },
        "additionalProperties": false,
        "type": "object"
      }
    },
    {
      "name": "ghazal_check",
      "description": "Finds what to correct. Each finding has `start` and `end` (where it is in the text), `text` (what is there),\n`suggestions` (what to write instead, best first; empty when there is no single fix), `rule` (explained in\nGET /api/v1/rules), `severity` (`error`: careful writers don't write it this way; `advice`: a source recommends\nit; `guess`: a model's guess, check it; `style`: both are right, the chosen style prefers this) and `confidence`\n(for guesses). With `profile: llm`, levels come from the review of Persian written by language models: at least 95% right for\n`error`, at least 85% for `advice`; other rules are omitted. Style findings stay `style`.\nConsistency findings also have a `reason` card with the two spellings and their counts.\n`register` is [spoken, written] evidence; `kind` is the kind of Persian the text was checked as;\nfor a long document both describe the whole text. `checked_to` and `from` count Unicode code points.\nSend the same whole text with `from: checked_to` to continue; only the checked range is charged.\nFinding offsets point into the whole text as sent. A cut that the server would not make gives 422.\nA finding that crosses a cut belongs to the piece containing its start; its end may exceed `checked_to`.\n`left_today` is what a key may still send today (null for own typing or with accounts off). With `compact`, each finding is one line:\n`@start «text» → «suggestion» | «another» rule severity`, and a guess's confidence last.",
      "input_schema": {
        "properties": {
          "style": {"type": "string", "enum": ["ghazal", "academy"], "title": "Style", "description": "`ghazal`: Ghazal's house style. `academy`: the spelling rules of the Academy of Persian Language and Literature.", "default": "ghazal"},
          "house": {"anyOf": [{"properties": {"ezafe": {"anyOf": [{"type": "string", "enum": ["ye", "hamza"]}, {"type": "null"}], "title": "Ezafe", "description": "`ye`: خانه‌ی (`style: ghazal`); `hamza`: خانهٔ (`style: academy`). Omit to follow `style`. If both are sent, they must agree."}, "digits": {"type": "string", "enum": ["persian", "latin", "keep"], "title": "Digits", "description": "`persian`: ۱۲۳; `latin`: replace Persian and Arabic-Indic digits with 123 in Persian prose, outside code, URLs, Latin text and anything Markdown skips; `keep`: leave digits as written.", "default": "persian"}, "quotes": {"type": "string", "enum": ["guillemets", "keep"], "title": "Quotes", "description": "`guillemets`: «» for Persian quotations; `keep`: leave quotation marks as written.", "default": "guillemets"}}, "additionalProperties": false, "type": "object", "title": "House"}, {"type": "null"}], "description": "Optional writing preferences. Omit this object to keep the existing behaviour; omitted keys keep their defaults."},
          "words": {"items": {"type": "string", "maxLength": 60, "minLength": 1, "pattern": "^(?:[^\\W_]|[ً-ٰٟـ])+(?:‌(?:[^\\W_]|[ً-ٰٟـ])+)*$"}, "type": "array", "maxItems": 500, "title": "Words", "description": "Personal words, at most 500 entries of one word each, at most 60 characters, without spaces. Matching uses the spell checker's folding of Arabic letters, half-spaces and marks. Only spell.* and confuse.* findings are hidden. Omit or send [] to keep the existing answers.", "default": []},
          "text": {"anyOf": [{"type": "string"}, {"type": "null"}], "title": "Text", "description": "The text to check: up to 200,000 characters with a personal plan, corporate plan or pack, otherwise 20,000. Send `text` or `texts`, not both."},
          "texts": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Texts", "description": "Several texts, at most 20,000 characters in all with a newline between each, checked one by one; the answer has `results` in the same order."},
          "from": {"type": "integer", "minimum": 0.0, "title": "From", "description": "Resume at a previous `checked_to`, in Unicode code points. Send the same complete text and options; omit on the first call.", "default": 0},
          "kind": {"type": "string", "enum": ["auto", "formal", "mixed", "colloquial"], "title": "Kind", "description": "What kind of Persian the text is. `auto` decides from the words; spoken forms are flagged only in `formal` text.", "default": "auto"},
          "offsets": {"type": "string", "enum": ["utf16", "codepoint"], "title": "Offsets", "description": "How `start` and `end` count: UTF-16 code units (JavaScript strings) or Unicode code points (Python strings).", "default": "utf16"},
          "format": {"type": "string", "enum": ["text", "markdown"], "title": "Format", "description": "`markdown`: code, URLs, HTML, front matter and Markdown's own marks are left alone; only the prose is checked. Offsets still point into the text as sent.", "default": "text"},
          "profile": {"anyOf": [{"type": "string", "const": "llm"}, {"type": "null"}], "title": "Profile", "description": "`llm`: keep a fixed set of rules reviewed on Persian written by language models, at error or advice level; style findings, where both forms are right, stay style. Apply house preferences first, then the profile, then only, disable and min_severity. These options cannot add rules outside the profile. Rule detection and kind stay unchanged; use kind: formal for friendly written prose. Omit for the existing answers."},
          "only": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "title": "Only", "description": "Report only these rules: ids like `ghazal.mi_prefix`, or prefixes ending in a dot like `spell.`."},
          "disable": {"items": {"type": "string"}, "type": "array", "title": "Disable", "description": "Never report these rules (ids or prefixes, as in `only`).", "default": []},
          "min_severity": {"type": "string", "enum": ["style", "guess", "advice", "error"], "title": "Min Severity", "description": "Report only findings of this severity or higher: style < guess < advice < error.", "default": "style"},
          "max_findings": {"anyOf": [{"type": "integer", "minimum": 0.0}, {"type": "null"}], "title": "Max Findings", "description": "Report at most this many findings per text, the first in the text. For a long document, this limit applies to each response."},
          "compact": {"type": "boolean", "title": "Compact", "description": "Answer in few tokens, for a language model: findings as one line each, no nulls, only what a model needs.", "default": false}
        },
        "additionalProperties": false,
        "type": "object"
      }
    }
  ]
}
```
<!-- /tools -->

When the model calls the tool, your program sends the arguments to the matching endpoint and hands the answer back:

```python
import json, os, urllib.request

def ghazal_fix(arguments):
    request = urllib.request.Request("https://ghazalai.ir/api/v1/fix", json.dumps(arguments).encode(), {"content-type": "application/json", "authorization": "Bearer " + os.environ["GHAZAL_KEY"]})
    with urllib.request.urlopen(request) as answer:
        return json.load(answer)
```

## Fewer tokens, and the other tools

Send `"compact": true` to `check` or `fix` and each finding comes back as one line, `@start «text» → «suggestion» rule severity`, with no nulls and nothing a model doesn't need; on ten real texts that was 45% fewer tokens for `check` and 17% for `fix`, whose answer is mostly the text itself. [check](/docs/check/)

An agent that writes Persian may also want [`vowels`](/docs/vowels/) (vowel marks where a word has several readings), [`verse`](/docs/verse/) (metre and rhyme of a poem it writes; `compact` gives one line per hemistich) and [`verb`](/docs/verb/) (when it is unsure of a verb form: every reading and the conjugation tables). There are also [`normalize`](/docs/normalize/), [`word`](/docs/word/) and [`arabic`](/docs/arabic/). A call that runs past 9 seconds answers `503`; wait `Retry-After` seconds.

## MCP

An agent that speaks MCP can use Ghazal without any code: point it at `https://ghazalai.ir/mcp` (Streamable HTTP; send your key in the header `Authorization: Bearer gz_...`). In a config file with the common shape:

```json
{"mcpServers": {"ghazal": {"type": "http", "url": "https://ghazalai.ir/mcp", "headers": {"Authorization": "Bearer gz_..."}}}}
```

In Claude Code: `claude mcp add --transport http ghazal https://ghazalai.ir/mcp --header "Authorization: Bearer gz_..."`. There are six tools: `fix_persian` and `check_persian` take the fields of `fix` and `check` except `texts` and `offsets` (offsets always count code points), `explain_rule` explains a rule by its id, and `add_vowels`, `scan_verse` and `conjugate_verb` are `vowels`, `verse` and `verb`. Each answers as the API does, in `structuredContent` and as JSON text. Details, in Persian: [سرور MCP](/docs/mcp/).

## Limits and keys

Programs without a key get `401 key_required`. Make a free key on the [account page](/account/) after signing in. Each account may send up to 120 requests in a row, then about 5 a second, 3 at once. Calls that take no text, such as rules and the MCP tool list, stay open. For `check` and `fix`, a personal plan, corporate plan or pack accepts one document of up to 200,000 characters; free keys stay at 20,000. All `texts` together stay at 20,000, with one newline between each. Send `Authorization: Bearer gz_...`. Each call spends only the characters it checked from its account's daily allowance; `left_today` in every answer says what is left, and the count starts again at 00:00 UTC. Text you send is kept to improve Ghazal; see [the privacy page](/privacy/). With the corporate plan you can make keys whose text is not kept. [Creating and changing keys](/docs/keys/)

Characters count Unicode code points, as Python's `len` does. Daily limit errors include `left_today` and `reset_at` (UTC), also sent as `X-RateLimit-Remaining` and `X-RateLimit-Reset`; `retry_after` matches `Retry-After` in seconds. A shorter text may fit the remaining allowance. [Limits by plan and endpoint](/docs/keys/)

Call the API from your server and keep the key there. The API sends no CORS headers; calls without a key are for Ghazal's site, app and Word add-in. Tokenizer inspection and corpus search are website tools; neither has a v1 endpoint or MCP tool.

The other pages are in Persian; their field names, code and examples are exact. Everything for a first call is in one file: [`/llms-full.txt`](/llms-full.txt). The machine-readable description: [`/api/v1/openapi.json`](/api/v1/openapi.json).
