# Ghazal writing API: everything in one file Ghazal checks and corrects Persian (Farsi) writing over HTTP. Programs need a free key: sign in and make one at https://ghazalai.ir/account/. POST JSON to https://ghazalai.ir/api/v1/fix with {"text": ""} (add "format": "markdown" for Markdown) and header content-type: application/json; the answer's "text" is the corrected text, "applied" lists what changed and "left" lists findings that were not applied, such as style preferences and spelling guesses (offsets into the returned text). For house spellings too, send "apply": "house": it also applies style findings with exactly one suggestion, never spelling guesses or advice. With the skill, read SKILL.md once and run python3 /fix.py FILE to correct the delivery file in place. One request carries at most 20,000 characters. POST the same body to /api/v1/check to get findings without changing anything: each has start and end (UTF-16 offsets by default, end exclusive), text, suggestions (best first; "" means delete), rule and severity (error, advice, guess, style). Filter with "only" or "disable" (rule ids or prefixes ending in a dot, such as "spell."; ids from GET /api/v1/rules) and "min_severity". Send "compact": true to check or fix for a shorter answer (45% fewer tokens for check on ten real texts): each finding one line, "@start «text» → «suggestion» rule severity". Other endpoints take {"text": ...} the same way: /api/v1/vowels (vowel marks where the reading is sure), /api/v1/verse (metre and rhyme, one hemistich per line), /api/v1/verb (verb readings and conjugation tables), /api/v1/word ({"word": ...}: stem, endings, verb analysis), /api/v1/arabic (Arabic passages) and /api/v1/normalize (the corpus normalizer alone). Every failure is {"error": {"code", "message", "message_fa", "request_id"}}; on 429 or 503 wait Retry-After seconds; a call past 9 seconds answers 503. Send the key in Authorization: Bearer gz_.... Without it, text calls answer 401 with code key_required. Rules, health, OpenAPI and the MCP tool list stay open. Call from your server and keep the key there; the API sends no CORS headers. Tokenizer inspection and corpus search are website tools, with no v1 endpoint or MCP tool. Daily limit errors include left_today and reset_at (UTC), also sent as X-RateLimit-Remaining and X-RateLimit-Reset. The pages below are in Persian; field names, code and examples are exact. The last page is in English. --- # شروع https://ghazalai.ir/docs/start/ > نخستین درخواست به API غزل با کلید رایگان، با curl، Python و JavaScript. API غزل متن فارسی را بررسی و درست می‌کند: املا، فاصله و نیم‌فاصله، نشانه‌گذاری، حرف‌ها و رقم‌های عربی، واژه‌های گفتاری در متن رسمی و چند نکته‌ی نثر. کلید رایگان لازم است؛ در صفحه‌ی [حساب کاربری](/account/) وارد شوید و کلید بسازید. ## نخستین درخواست کلید را در متغیر محیطی `GHAZAL_KEY` بگذارید. نمونه‌ها نخستین درخواست روز یک حساب رایگان را نشان می‌دهند. متن را با `POST` به `https://ghazalai.ir/api/v1/check` بفرستید: ```sh curl https://ghazalai.ir/api/v1/check \ -H "authorization: Bearer $GHAZAL_KEY" \ -H 'content-type: application/json' \ -d '{"text": "این کتاب ها را میخوانم و آنها را دوست دارم ."}' ``` همین درخواست در Python، فقط با کتابخانه‌ی استاندارد: ```python import json, os, urllib.request body = json.dumps({"text": "این کتاب ها را میخوانم و آنها را دوست دارم ."}).encode() request = urllib.request.Request("https://ghazalai.ir/api/v1/check", body, {"content-type": "application/json", "authorization": "Bearer " + os.environ["GHAZAL_KEY"]}) with urllib.request.urlopen(request) as answer: print(json.dumps(json.load(answer), ensure_ascii=False, indent=2)) ``` و در JavaScript، مثلاً در Node: ```js const answer = await fetch("https://ghazalai.ir/api/v1/check", { method: "POST", headers: { "content-type": "application/json", "authorization": `Bearer ${process.env.GHAZAL_KEY}` }, body: JSON.stringify({ text: "این کتاب ها را میخوانم و آنها را دوست دارم ." }), }); console.log(JSON.stringify(await answer.json(), null, 2)); ``` پاسخ هر سه یکی است: ```json { "kind": "formal", "register": [0, 3], "findings": [ {"start": 4, "end": 11, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 15, "end": 22, "text": "میخوانم", "suggestions": ["می‌خوانم"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 25, "end": 29, "text": "آنها", "suggestions": ["آن‌ها"], "rule": "ghazal.house_forms", "severity": "style", "confidence": null}, {"start": 42, "end": 43, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ], "left_today": 49956 } ``` API سرآیندهای CORS نمی‌فرستد، پس صفحه‌ای در وبگاه دیگر نمی‌تواند مستقیم آن را صدا بزند. درخواست را از سرور یا برنامه‌ی خودتان بفرستید. ## خواندن پاسخ هر عضو `findings` یک پیشنهاد است. نخستینش می‌گوید از نویسه‌ی ۴ تا پیش از ۱۱ «کتاب ها» آمده و به جایش «کتاب‌ها» بنویسید، با نیم‌فاصله. `rule` نام قاعده است و `severity` سطح پیشنهاد: `error` یعنی خطا، و `style` در پیشنهاد «آنها» یعنی هر دو صورت درست است و سبک غزل «آن‌ها» را ترجیح می‌دهد. پیشنهاد آخر می‌گوید فاصله‌ی پیش از نقطه را بردارید؛ `""` یعنی حذف. `kind` نوع متن است که خودکار تشخیص داده شد، `register` شمار نشانه‌های گفتار و نوشتار در متن، و `left_today` شمار نویسه‌هایی است که امروز در سهمیه‌ی کلید مانده است. ## متن درست‌شده برای گرفتن متن درست‌شده، همین بدنه را به `fix` بفرستید: ```sh curl https://ghazalai.ir/api/v1/fix -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "این کتاب ها را میخوانم و آنها را دوست دارم ."}' ``` ```json { "kind": "formal", "text": "این کتاب‌ها را می‌خوانم و آنها را دوست دارم.", "applied": [ {"start": 4, "end": 11, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 15, "end": 22, "text": "میخوانم", "suggestions": ["می‌خوانم"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 42, "end": 43, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ], "left": [ {"start": 26, "end": 30, "text": "آنها", "suggestions": ["آن‌ها"], "rule": "ghazal.house_forms", "severity": "style", "confidence": null} ], "left_today": 49956 } ``` `fix` خطاها را درست کرد و «آنها» را نگه داشت، چون ترجیح سبک است نه خطا؛ آن را در `left` برگرداند. ## بعد - [کلید و سقف‌ها](/docs/keys/): ساختن کلید و سهمیه‌ی هر حساب. - [check](/docs/check/) و [fix](/docs/fix/): همه‌ی فیلدها و پاسخ‌ها. - [برای مدل‌های زبانی](/docs/agents/): غزل را به عامل هوش مصنوعی‌تان بدهید. - توصیف ماشینی همه‌ی نشانی‌ها، با یک نمونه‌ی واقعی برای هر کدام: [`/api/v1/openapi.json`](/api/v1/openapi.json). --- # کلید و سقف‌ها https://ghazalai.ir/docs/keys/ > چطور کلید رایگان بسازید، چقدر می‌شود فرستاد و left_today چه می‌گوید. ## کلید لازم است برنامه‌ها برای فرستادن متن به API و ابزارهای MCP به کلید نیاز دارند. بی‌کلید پاسخ `401` با کد `key_required` می‌آید. در صفحه‌ی [حساب کاربری](/account/) وارد شوید و کلید رایگان بسازید. سایت، برنامه‌ی غزل و افزونه‌ی Word کلید نمی‌خواهند؛ [سقف‌های نوشتن](/docs/write/) و سقف روزانه‌ی هر نشانی، ۲۰۰٬۰۰۰ نویسه، همان است. درخواست‌هایی که متن نمی‌گیرند، مثل `health`، `rules`، `openapi.json` و فهرست ابزارهای MCP، باز می‌مانند. `usage` همچنان کلید می‌خواهد. API را از سرور خودتان صدا بزنید و کلید را همان‌جا نگه دارید. API سرآیند CORS نمی‌فرستد؛ فراخوانی بی‌کلید برای سایت، برنامه و افزونه‌ی Word غزل است. ## شمار درخواست سقف‌ها برای همه‌ی کلیدهای یک حساب مشترک است. درخواست‌های بی‌کلید که متن نمی‌گیرند، با نشانی IP شمرده می‌شوند: | سقف | اندازه | |---|---| | شمار درخواست | تا ۱۲۰ درخواست پشت سر هم، و پس از آن حدود ۵ در ثانیه | | درخواست هم‌زمان | ۳ | وقتی کل سرور پر است، پاسخ `503` با کد `busy` می‌آید. در هر دو حالت سرآیند `Retry-After` می‌گوید چند ثانیه صبر کنید. ## با کلید کلید رایگان را پس از ورود در صفحه‌ی [حساب کاربری](/account/) می‌سازید؛ ورود با شماره‌ی موبایل ایرانی است. هر حساب تا پنج کلید دارد و هر کلید فقط یک بار، هنگام ساختن، نشان داده می‌شود. برای اجرای نمونه‌های این راهنما، کلید را در متغیر محیطی `GHAZAL_KEY` بگذارید. کلید را در سرآیند `Authorization` بفرستید: ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H 'authorization: Bearer gz_...' \ -d '{"text": "این کتاب ها را میخوانم ."}' ``` ```json { "kind": "formal", "register": [0, 1], "findings": [ {"start": 4, "end": 11, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 15, "end": 22, "text": "میخوانم", "suggestions": ["می‌خوانم"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 22, "end": 23, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ], "left_today": 49976 } ``` این کلید از حسابی با طرح رایگان است. `left_today` نویسه‌های مانده را می‌گوید. - هر نویسه‌ای که به `check` یا `fix` می‌فرستید یک بار شمرده می‌شود: طول `text`، یا جمع طول‌های `texts`. `fix` هم هر چند بار که متن را از نو بررسی کند، همان یک بار حساب می‌شود. - نویسه‌ها با code point شمرده می‌شوند، مثل `len` در Python، هر `offsets` که انتخاب کنید. - سهمیه‌ی روزانه مال حساب است و همه‌ی کلیدهای حساب از آن خرج می‌کنند. وقتی تمام شد، از بسته‌های پیش‌خرید برداشته می‌شود، اگر بسته‌ای داشته باشید. هر کلید در روز فقط تا اندازه‌ی `pack_day` از بسته‌ها برمی‌دارد. - روزها به وقت UTC است: شمارش ساعت ۰۰:۰۰ UTC، یعنی ۳:۳۰ بامداد به وقت تهران، از صفر شروع می‌شود. - `left_today` در هر پاسخ `check` و `fix` می‌گوید این کلید امروز چند نویسه‌ی دیگر می‌تواند بفرستد، با بسته‌ها. در سایت و برنامه‌ی غزل، یا وقتی حساب‌ها در محیط توسعه خاموش‌اند، `null` است. جزئیات را [`usage`](/docs/feedback/) می‌دهد. - سقف شمار درخواست با کلید هم هست، و همه‌ی کلیدهای یک حساب یک سهم دارند. وقتی نویسه‌های امروز تمام شود، پاسخ `429` با کد `quota_exceeded` می‌آید و `Retry-After` شمار ثانیه‌ها تا ۰۰:۰۰ UTC است. کلیدی که نادرست یا باطل شده باشد `401` با کد `unauthorized` می‌گیرد. کلید معتبر بفرستید. در خطای سقف روزانه، `left_today` نویسه‌های مانده و `reset_at` زمان شروع روز بعد به وقت UTC است. همین دو مقدار در سرآیندهای `X-RateLimit-Remaining` و `X-RateLimit-Reset` می‌آید. اگر متن از سهمیه‌ی مانده بلندتر باشد، خطا می‌گیرید؛ لازم نیست سهمیه صفر شده باشد. | طرح | نویسه در روز | نویسه در هر درخواست | برداشت هر کلید از بسته در روز | |---|---|---|---| | رایگان | ۵۰٬۰۰۰ | ۲۰٬۰۰۰ | — | | شخصی، یک‌ماهه | ۱٬۰۰۰٬۰۰۰ | ۲۰۰٬۰۰۰ | — | | شخصی، سه‌ماهه | ۱٬۰۰۰٬۰۰۰ | ۲۰۰٬۰۰۰ | — | | شخصی، یک‌ساله | ۱٬۰۰۰٬۰۰۰ | ۲۰۰٬۰۰۰ | — | | سازمانی، یک‌ماهه | ۱۰٬۰۰۰٬۰۰۰ | ۲۰۰٬۰۰۰ | — | | سازمانی، سه‌ماهه | ۱۰٬۰۰۰٬۰۰۰ | ۲۰۰٬۰۰۰ | — | | سازمانی، یک‌ساله | ۱۰٬۰۰۰٬۰۰۰ | ۲۰۰٬۰۰۰ | — | | بسته‌ی ده میلیون نویسه | ۰ | ۲۰۰٬۰۰۰ | ۲٬۰۰۰٬۰۰۰ | | بسته‌ی صد میلیون نویسه | ۰ | ۲۰۰٬۰۰۰ | ۱۰٬۰۰۰٬۰۰۰ | بسته سهمیه‌ی روزانه اضافه نمی‌کند؛ پس از سهمیه‌ی طرح از آن برداشته می‌شود. ## اندازه‌ی درخواست | سقف | اندازه | |---|---| | `check` و `fix`، یک متن با کلید طرح شخصی، سازمانی یا بسته | ۲۰۰٬۰۰۰ نویسه | | یک متن برای رایگان یا بدون کلید؛ همه‌ی `texts` با خط تازه میان هر دو | ۲۰٬۰۰۰ نویسه | | `vowels` | ۸٬۰۰۰ نویسه | | `verse`، جمع طول مصراع‌هایی که خوانده می‌شود | ۲٬۴۰۰ نویسه | | `verse`، هر مصراع | ۳۰۰ نویسه | | `verse`، شمار مصراع‌هایی که خوانده می‌شود | ۴۰ | | `word` | ۶۰ نویسه | | `verb` | ۱٬۰۰۰ نویسه | | `verb`، شمار واژه‌هایی که خوانده می‌شود | ۴۰ | | بدنه‌ی `check` و `fix` با کلید طرح شخصی، سازمانی یا بسته | ۱٬۲۰۴٬۰۹۶ بایت | | بدنه‌ی درخواست‌های دیگر | ۲۵۶ کیلوبایت | | زمان هر درخواست | ۹ ثانیه | ### سند بلند با کلید طرح شخصی، سازمانی یا بسته، `check` و `fix` یک متن تا ۲۰۰٬۰۰۰ نویسه می‌پذیرند. با کلید رایگان یا بدون کلید سقف همان ۲۰٬۰۰۰ نویسه است، و برای `texts` با هر کلیدی. سرور متن بلند را بخش‌بخش بررسی می‌کند و هر پاسخ در `checked_to` می‌گوید تا کجا رسیده است، با شمارش Unicode code point، حتی اگر `offsets: utf16` باشد. اگر به پایان متن نرسیده بود، همان متن و همان تنظیم‌ها را با `from: checked_to` دوباره بفرستید. فقط نویسه‌های بخش بررسی‌شده از سهمیه کم می‌شود، نه آنچه دوباره فرستاده‌اید. `from` باید همان عددی باشد که سرور داده است؛ عدد دیگر پاسخ ۴۲۲ می‌گیرد. متن تا ۲۰٬۰۰۰ نویسه `checked_to` ندارد. در این نمونه، `fix` تابعی است که درخواست را به `/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) ``` در پاسخ `fix`، `text` همان بخش است که درست شده؛ بخش‌ها را بی هیچ فاصله‌ای پشت هم بگذارید. جای هر `applied` در متنی است که فرستاده‌اید و جای هر `left` در `text` همان پاسخ، هر دو با واحد `offsets`؛ برای یافتن `left` در متن کامل، طول بخش‌های پیشین را به آن بیفزایید. پیشنهادی که در یک بخش آغاز و در بخش بعد تمام می‌شود با بخش اول می‌آید و `end` آن از پایان بخش می‌گذرد. سرور متن را در پایان بند می‌بُرد، و اگر بندی از ۲۰٬۰۰۰ نویسه بلندتر بود، در پایان جمله یا میان دو واژه. نوع متن و شمارش املاهای ناهمسان از کل سند است. هر بخش با ۲٬۰۴۸ نویسه از پیش و پس آن خوانده می‌شود، پس نتیجه گاهی با بررسی یک‌جای همان متن فرق دارد: در حدس املایی برای واژه‌ای که جای دوری از متن تکرار شده، و در قاعده‌هایی که به جمله‌های دورتر نگاه می‌کنند. اگر `Content-Length` از سقف بدنه بیشتر باشد، سرور پیش از خواندن بدنه پاسخ ۴۱۳ می‌دهد. توکن‌کاوی و جست‌وجوی پیکره فقط در سایت‌اند؛ نشانی `/api/v1/` یا ابزار MCP ندارند. ## آنچه نگه داشته می‌شود متنی که می‌فرستید برای بهتر شدن غزل نگه داشته می‌شود؛ [حریم خصوصی](/privacy/). با طرح سازمانی می‌توانید کلیدی بسازید که متنش نگه داشته نشود: `POST /api/account/keys` با `{"name":"example","keep":false}`، یا برای کلید موجود `PATCH /api/account/keys/123` با `{"keep":false}`. بدون طرح سازمانی، پاسخ `403` با `{"detail":"private key needs the corporate plan"}` می‌آید. `keys[].keep` در پاسخ حساب و `limits.keep` در `/api/v1/usage` تنظیم هر کلید را می‌گویند. کلید را فقط یک بار می‌بینید. ## قیمت‌ها سهمیه‌ی روزانه‌ی هر طرح، بسته‌ها و قیمت‌ها در صفحه‌ی [قیمت‌ها](/pricing/) است. --- # بررسی متن: check https://ghazalai.ir/docs/check/ > POST /api/v1/check متن را تغییر نمی‌دهد؛ فهرست پیشنهادها را با جای هر کدام، قاعده و جایگزین‌هایش برمی‌گرداند. ## فیلدهای درخواست `check` و [`fix`](/docs/fix/) فیلدهای یکسانی می‌گیرند. فیلد ناشناخته با `invalid_request` رد می‌شود. | فیلد | مقدار | پیش‌فرض | کارش | |---|---|---|---| | `text` | رشته | | متن. یا `text` بفرستید یا `texts`، نه هر دو. | | `from` | عدد صحیح، ۰ یا بیشتر | `0` | ادامه‌ی بررسی یک متن بلند: همان `checked_to` که پاسخ پیشین داد، با همان متن و همان تنظیم‌ها. | | `texts` | فهرست رشته‌ها | | چند متن، مثلاً بندهای یک نوشته، که هر کدام جدا بررسی می‌شود؛ روی هم تا ۲۰٬۰۰۰ نویسه. پاسخ به‌جای `findings` فهرست `results` را به همان ترتیب دارد. | | `style` | `ghazal`، `academy` | `ghazal` | سبک غزل، یا قاعده‌های فرهنگستان زبان و ادب فارسی. [نوع متن و سبک](/docs/kinds/) | | `house` | شیء با کلیدهای `ezafe`، `digits`، `quotes` | بدون تغییر رفتار پیشین | [تنظیمات نوشتن](#تنظیمات-نوشتن) | | `words` | فهرست واژه‌ها | `[]` | حداکثر ۵۰۰ واژه؛ هر واژه حداکثر ۶۰ نویسه و بدون فاصله. [واژه‌های من](#واژههای-من) | | `kind` | `auto`، `formal`، `mixed`، `colloquial` | `auto` | نوع متن: رسمی، نیمه‌رسمی یا محاوره. `auto` از روی واژه‌ها تشخیص می‌دهد. | | `offsets` | `utf16`، `codepoint` | `utf16` | `start` و `end` با چه واحدی شمرده شوند. [offsets](/docs/offsets/) | | `format` | `text`، `markdown` | `text` | با `markdown` فقط نثر بررسی می‌شود. [Markdown](/docs/markdown/) | | `only` | فهرست نام قاعده یا پیشوند | همه | فقط این قاعده‌ها. پیشوند به نقطه ختم می‌شود: `spell.`، `ghazal.` | | `disable` | فهرست نام قاعده یا پیشوند | هیچ | این قاعده‌ها هرگز گزارش نشوند. | | `min_severity` | `style`، `guess`، `advice`، `error` | `style` | فقط این سطح و بالاتر. ترتیب: `style` < `guess` < `advice` < `error` | | `max_findings` | عدد صحیح، ۰ یا بیشتر | بی‌سقف | در هر متن حداکثر این تعداد پیشنهاد، به ترتیب جا در متن. | | `compact` | `true`، `false` | `false` | پاسخ کوتاه برای مدل‌های زبانی؛ پایین همین صفحه. | نامی در `only` یا `disable` که با هیچ قاعده‌ای نخواند رد می‌شود. نام‌ها در [فهرست قاعده‌ها](/docs/rules/) و در `GET /api/v1/rules` است. ## تنظیمات نوشتن برای پیروی از شیوه‌نامه‌ی خودتان، در `check` و `fix` شیء `house` بفرستید: ```json {"text": "خانه‌ی ما در سال ۱۴۰۵", "house": {"ezafe": "hamza", "digits": "latin", "quotes": "keep"}} ``` | کلید | مقدارها | پیش‌فرض | |---|---|---| | `ezafe` | `ye`: خانه‌ی؛ `hamza`: خانهٔ | از `style` | | `digits` | `persian`: ۱۲۳؛ `latin`: 123؛ `keep`: همان متن | `persian` | | `quotes` | `guillemets`: «»؛ `keep`: همان متن | `guillemets` | `ezafe: ye` همان `style: ghazal` و `ezafe: hamza` همان `style: academy` است. اگر هر دو را بفرستید و ناسازگار باشند، پاسخ ۴۲۲ می‌گیرید. `digits: latin` در نثر فارسی رقم‌های فارسی و عربی را با رقم‌های لاتین جایگزین می‌کند؛ کد، نشانی‌ها و عددهای متن لاتین می‌مانند. در حالت Markdown، بخش‌هایی که بررسی نمی‌شوند دست‌نخورده می‌مانند. `digits: keep` دو قاعده‌ی `ghazal.persian_digits` و `ghazal.arabic_digits` و پیشنهاد یکدستی رقم‌ها را خاموش می‌کند. `quotes: keep` قاعده‌ی `ghazal.guillemets` و پیشنهاد یکدستی نقل‌قول‌ها را خاموش می‌کند. کلیدهای نفرستاده پیش‌فرض خود را دارند. اگر `house` نفرستید، رفتار پیشین عوض نمی‌شود. ## واژه‌های من نام‌ها و اصطلاح‌های خودتان را در `words` بفرستید: `{"text": "کتابخنه", "words": ["کتابخنه"]}`. فقط پیشنهادهای `spell.*` و `confuse.*` برای این واژه‌ها پنهان می‌شوند؛ پیشنهادهای فاصله‌گذاری، نشانه‌گذاری و دستور زبان می‌مانند. برای مقایسه، صورت‌های عربی و فارسی حروف، نیم‌فاصله و اعراب مثل غلط‌یاب یکسان شمرده می‌شوند. اگر فهرست خالی باشد یا آن را نفرستید، پاسخ پیشین عوض نمی‌شود. اگر تعداد یا طول واژه‌ها از سقف بگذرد یا واژه‌ای فاصله داشته باشد، پاسخ ۴۲۲ می‌گیرید. ## سند بلند با کلید طرح شخصی یا بسته، `text` می‌تواند تا ۲۰۰٬۰۰۰ نویسه باشد. پاسخ متن بلند `checked_to` دارد؛ اگر به پایان متن نرسیده بود، همان متن را با `from: checked_to` دوباره بفرستید. [سند بلند](/docs/keys/#سند-بلند) ## پاسخ برای `text`، پاسخ `kind` و `register` و `findings` و `left_today` دارد؛ برای `texts`، `kind` و `results` و `left_today`، و هر عضو `results` یک `register` و یک `findings` دارد. - `kind`: نوعی که متن با آن بررسی شد. با `auto`، نوعی که تشخیص داده شد. - `register`: `[spoken, written]`، شمار نشانه‌های گفتار و نوشتار در متن. - `left_today`: نویسه‌هایی که این کلید امروز هنوز می‌تواند بفرستد؛ در سایت و برنامه‌ی غزل، یا وقتی حساب‌ها در محیط توسعه خاموش‌اند، `null`. [کلید و سقف‌ها](/docs/keys/) هر پیشنهاد این فیلدها را دارد: | فیلد | معنی | |---|---| | `start`، `end` | جای پیشنهاد: از `start` تا پیش از `end`. اگر برابر باشند، جایی است که باید چیزی افزود. | | `text` | آنچه اکنون آنجاست، دقیقاً همان نویسه‌های میان `start` و `end`. | | `suggestions` | جایگزین‌ها، بهترین اول. `""` یعنی حذف. فهرست خالی یعنی اینجا ایرادی هست ولی جایگزین یگانه‌ای نیست. | | `rule` | نام قاعده. | | `severity` | سطح پیشنهاد؛ جدول زیر. | | `confidence` | برای پیشنهادهای `guess`، اطمینان مدل از ۰ تا ۱؛ وگرنه `null`. | | `severity` | نام در نوشت‌یار | معنی | |---|---|---| | `error` | خطا | نویسندگان دقیق این‌طور نمی‌نویسند. | | `advice` | توصیه | منبع این را توصیه می‌کند، ولی الزامی نیست. | | `guess` | احتمالی | حدس یک مدل است؛ پیش از پذیرفتن بررسی کنید. | | `style` | سبک | هر دو املا درست است؛ سبک انتخاب‌شده این یکی را ترجیح می‌دهد. | پیشنهادها هم‌پوشانی ندارند و به ترتیب جا در متن می‌آیند. اگر خودتان چند پیشنهاد را اعمال می‌کنید، از آخر به اول بروید تا جای پیشنهادهای پیشین به هم نخورد؛ یا [`fix`](/docs/fix/) را صدا بزنید. ## نمونه: متن رسمی با واژه‌های گفتاری ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "فردا نامه رو میفرستم و جواب رو بهتون میگم.", "kind": "formal"}' ``` ```json { "kind": "formal", "register": [4, 0], "findings": [ {"start": 10, "end": 12, "text": "رو", "suggestions": ["را"], "rule": "register.ra", "severity": "advice", "confidence": null}, {"start": 13, "end": 20, "text": "میفرستم", "suggestions": ["می‌فرستم"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 28, "end": 30, "text": "رو", "suggestions": ["را", "روی"], "rule": "register.ra", "severity": "advice", "confidence": null}, {"start": 31, "end": 36, "text": "بهتون", "suggestions": ["به شما"], "rule": "register.clitic", "severity": "advice", "confidence": null}, {"start": 37, "end": 41, "text": "میگم", "suggestions": ["می‌گویم"], "rule": "register.verb", "severity": "advice", "confidence": null} ], "left_today": 49958 } ``` با `"kind": "formal"` صورت‌های گفتاری توصیه می‌گیرند. دومین «رو» دو جایگزین دارد، چون می‌تواند «را» باشد یا «روی». بی‌این فیلد، متن محاوره تشخیص داده می‌شد و به‌جای این توصیه‌ها فقط نیم‌فاصله‌ی «میفرستم» و «میگم» پیشنهاد می‌شد. ## نمونه: چند متن و فقط خطاها ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"texts": ["فردا کتاب رو بهت میده.", "این کتاب ها را میخوانم ."], "min_severity": "error"}' ``` ```json { "kind": "colloquial", "results": [ {"register": [3, 0], "findings": []}, {"register": [0, 1], "findings": [ {"start": 4, "end": 11, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 15, "end": 22, "text": "میخوانم", "suggestions": ["می‌خوانم"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 22, "end": 23, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ]} ], "left_today": 49954 } ``` نوع متن یک بار برای همه‌ی متن‌های درخواست تشخیص داده می‌شود: اینجا سه نشانه‌ی گفتار در برابر یک نشانه‌ی نوشتار، پس محاوره. جای هر پیشنهاد از آغاز متن خودش شمرده می‌شود. متن اول یک پیشنهاد «احتمالی» دارد («میده» ← «می‌ده»، با اطمینان ۰٫۸) که `min_severity` آن را کنار گذاشت. ## پاسخ کوتاه برای مدل‌های زبانی با `"compact": true` هر پیشنهاد یک سطر است: `@start «text» → «suggestion» | «suggestion» rule severity`، و برای `guess` اطمینان در آخر. `register` نمی‌آید و `left_today` فقط با کلید می‌آید. پاسخ زیر ۹۵ توکن است و پاسخ کامل همین درخواست ۱۹۹ توکن (با توکن‌ساز o200k)؛ روی ده متن واقعی، پاسخ کوتاه ۴۵٪ توکن کمتر داشت. ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "فردا نامه رو میفرستم و جواب رو بهتون میگم.", "kind": "formal", "compact": true}' ``` ```json { "kind": "formal", "findings": [ "@10 «رو» → «را» register.ra advice", "@13 «میفرستم» → «می‌فرستم» ghazal.mi_prefix error", "@28 «رو» → «را» | «روی» register.ra advice", "@31 «بهتون» → «به شما» register.clitic advice", "@37 «میگم» → «می‌گویم» register.verb advice" ], "left_today": 49958 } ``` `«»` یعنی حذف، و سطری بی `→` یعنی ایرادی هست ولی جایگزین یگانه‌ای نیست. --- # درست کردن متن: fix https://ghazalai.ir/docs/fix/ > POST /api/v1/fix متن درست‌شده را برمی‌گرداند، با آنچه تغییر کرد و آنچه برای تصمیم شما ماند. `fix` همه‌ی فیلدهای [`check`](/docs/check/) را می‌گیرد و یک فیلد دیگر: `apply`، با مقدار `sure` (پیش‌فرض)، `house` یا `all`. با [`words`](/docs/check/#واژههای-من)، پیشنهادهای `spell.*` و `confuse.*` برای واژه‌های فهرست، حتی با `apply: all`، اعمال یا گزارش نمی‌شوند؛ فاصله‌گذاری، نشانه‌گذاری و دستور زبان همچنان بررسی می‌شوند. ## پاسخ برای `text`، پاسخ `kind` و `text` و `applied` و `left` و `left_today` دارد؛ برای `texts`، `kind` و `results` و `left_today`، و هر عضو `results` یک `text` و `applied` و `left` دارد. - `text`: متن درست‌شده. - `applied`: پیشنهادهایی که اعمال شد، به همان شکل پیشنهادهای `check`. جایشان در متنی است که فرستادید و جایگزین اول به کار رفته است. - `left`: پیشنهادهایی که در متن درست‌شده مانده و اعمال نشده. جایشان در متن برگشتی است. `max_findings` فقط این فهرست را کوتاه می‌کند. - `only`، `disable` و `min_severity` هم آنچه را اعمال می‌شود محدود می‌کنند و هم آنچه را فهرست می‌شود. با `"compact": true` پیشنهادهای `applied` و `left` هر کدام یک سطرند، مثل [پاسخ کوتاه check](/docs/check/)؛ سطرهای `applied` جای پیشنهاد را ندارند. نمونه‌اش در [normalize](/docs/normalize/) آمده است. ## سند بلند با کلید طرح شخصی یا بسته، `fix` متن تا ۲۰۰٬۰۰۰ نویسه را بخش‌بخش درست می‌کند: `text` هر پاسخ همان بخش است و `checked_to` می‌گوید تا کجا رسیده است. همان متن اولیه را با `from: checked_to` بفرستید تا به پایان برسد، و بخش‌ها را بی هیچ فاصله‌ای پشت هم بگذارید. [حلقه‌ی کامل و جای `applied` و `left`](/docs/keys/#سند-بلند) ## چه چیزی اعمال می‌شود با `apply: sure` همان کاری می‌شود که دکمه‌ی «همه‌ی خطاها را درست کن» در نوشت‌یار می‌کند. پیشنهادی اعمال می‌شود که: 1. سطحش `error` باشد؛ 2. دست‌کم یک جایگزین داشته باشد؛ 3. قاعده‌اش با `spell.` شروع نشود، چون پیشنهاد املایی حدسی است درباره‌ی واژه‌ای که نویسنده در نظر داشته؛ 4. از فیلترهای `only`، `disable` و `min_severity` بگذرد. با `apply: house` خطاهای `sure` و پیشنهادهای سطح `style` که دقیقاً یک جایگزین دارند اعمال می‌شوند: املای سبک غزل یا فرهنگستان، نشانه‌ی «…»، اضافه‌ی «ه‌ی» یا «هٔ» و نوشتار یکدست در هر متن. توصیه‌ها و حدس‌های املایی اعمال نمی‌شوند. پیشنهادهای سبک درون نقل‌قول هم می‌مانند؛ نام‌ها و شعر را نفرستید. با `apply: all` هر پیشنهادی که جایگزین دارد و از فیلترها می‌گذرد اعمال می‌شود، از جمله سبک، توصیه و حدس‌ها. پس از اعمال، متن درست‌شده با همان نوع متن دوباره بررسی می‌شود و آنچه اکنون پیدا شود هم اعمال می‌شود، حداکثر در سه دور. برای همین اگر متن برگشتی را با همان فیلدها دوباره به `fix` بدهید، بی‌تغییر برمی‌گردد. با `kind: auto` درخواست دوم نوع متن را از نو تشخیص می‌دهد؛ برای نتیجه‌ی یکسان، `kind` پاسخ اول را بفرستید. هزینه‌ی `fix` همان نویسه‌هایی است که بررسی شد، یک بار، هر چند دور که لازم شود. ## نمونه: `sure` ```sh curl https://ghazalai.ir/api/v1/fix -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "او دانش اموز خوبی است و کتاب ها را با دقت میخواند ."}' ``` ```json { "kind": "formal", "text": "او دانش اموز خوبی است و کتاب‌ها را با دقت می‌خواند.", "applied": [ {"start": 24, "end": 31, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 42, "end": 49, "text": "میخواند", "suggestions": ["می‌خواند"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 49, "end": 50, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ], "left": [ {"start": 8, "end": 12, "text": "اموز", "suggestions": ["آموز"], "rule": "spell.typo", "severity": "error", "confidence": null} ], "left_today": 49949 } ``` «اموز» خطاست، ولی پیشنهاد املایی است و `sure` آن را به شما واگذاشت. ## نمونه: `all` ```sh curl https://ghazalai.ir/api/v1/fix -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "او دانش اموز خوبی است و کتاب ها را با دقت میخواند .", "apply": "all"}' ``` ```json { "kind": "formal", "text": "او دانش‌آموز خوبی است و کتاب‌ها را با دقت می‌خواند.", "applied": [ {"start": 3, "end": 12, "text": "دانش اموز", "suggestions": ["دانش‌آموز"], "rule": "spell.typo", "severity": "error", "confidence": null}, {"start": 24, "end": 31, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 42, "end": 49, "text": "میخواند", "suggestions": ["می‌خواند"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 49, "end": 50, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ], "left": [], "left_today": 49949 } ``` دور اول «اموز» را «آموز» کرد و دور دوم «دانش آموز» را با نیم‌فاصله نوشت. وقتی دوری متنی را تغییر دهد که دور پیش‌تر نوشته بود، هر دو یک عضو `applied` می‌شوند: قاعده‌ی دور اول، جای کل تغییر در متن فرستاده‌شده، و متن نهایی به‌عنوان تنها جایگزین. --- # feedback، usage و rules https://ghazalai.ir/docs/feedback/ > گزارش پذیرفتن یا رد یک پیشنهاد، مصرف یک کلید، و توضیح همه‌ی قاعده‌ها. ## `POST /api/v1/feedback` اگر پیشنهادها را به کسی نشان می‌دهید، با این نشانی بگویید پیشنهادی را پذیرفت یا رد کرد. بدنه دقیقاً دو فیلد دارد: `rule` (نام قاعده، همان که `check` داد) و `action` (`accepted` یا `rejected`). فیلدی برای متن نیست و هر فیلد دیگری رد می‌شود. پاسخ `204` است، بی‌بدنه. ```sh curl -i https://ghazalai.ir/api/v1/feedback -H 'content-type: application/json' \ -d '{"rule": "ghazal.mi_prefix", "action": "accepted"}' ``` بدنه‌ای که رد می‌شود: ```sh curl https://ghazalai.ir/api/v1/feedback -H 'content-type: application/json' \ -d '{"rule": "ghazal.mi_prefix", "action": "rejected", "text": "..."}' ``` ```json {"error": {"code": "invalid_request", "message": "text: Extra inputs are not permitted", "message_fa": "مقدار text درست نیست.", "request_id": "req_2a12d5b5b6c20486"}} ``` ## `GET /api/v1/usage` مصرف یک کلید. کلید لازم دارد؛ بی‌کلید پاسخ `401` با کد `unauthorized` است. ```sh curl https://ghazalai.ir/api/v1/usage -H 'authorization: Bearer gz_...' ``` ```json { "today": {"characters": 24, "requests": 1}, "left_today": 49976, "limits": {"plan": "free", "ends": null, "day": 50000, "request": 20000, "pack_left": 0, "pack_day": null, "keep": true}, "days": [ {"day": "2026-11-13", "characters": 24, "requests": 1} ] } ``` این همان کلیدی است که در [کلید و سقف‌ها](/docs/keys/) یک `check` با آن فرستاده شد. | فیلد | معنی | |---|---| | `today` | نویسه‌ها و درخواست‌های این کلید از ساعت ۰۰:۰۰ UTC. | | `left_today` | نویسه‌هایی که این کلید امروز هنوز می‌تواند بفرستد، با بسته‌ها. | | `limits.day` | نویسه‌های روزانه‌ی حساب، که همه‌ی کلیدهای حساب از آن خرج می‌کنند؛ برای همین `left_today` ممکن است از `day` منهای `today` همین کلید کمتر باشد. | | `limits.keep` | نگه داشتن متن برای این کلید. [جزئیات](/docs/keys/) | | `limits.request` | بیشترین نویسه در یک درخواست. | | `limits.pack_left` | نویسه‌های مانده در بسته‌های حساب. | | `limits.pack_day` | بیشترین نویسه‌ای که یک کلید در روز از بسته‌ها برمی‌دارد؛ بی‌بسته `null`. | | `limits.plan`، `limits.ends` | طرح حساب و پایانش به وقت UTC، مثل `"2026-12-13T09:30:00Z"`؛ طرح رایگان پایان ندارد. | | `days` | روزهایی از سی روز گذشته که این کلید در آن‌ها به کار رفته، از قدیم به جدید. | ## `GET /api/v1/rules` همه‌ی قاعده‌ها، به نام. هر قاعده `title` و `statement` به فارسی دارد، `source` (کتاب و صفحه، یا `null` برای قاعده‌های خود غزل) و `example` (`wrong` و `right`، یا `null`). همین‌ها، دسته‌بندی‌شده، در [فهرست قاعده‌ها](/docs/rules/) آمده است. ```sh curl -s https://ghazalai.ir/api/v1/rules | jq '."ghazal.mi_prefix"' ``` ```json {"title": "نیم‌فاصله‌ی «می» و «نمی»", "statement": "«می» و «نمی» پیش از فعل نیم‌فاصله می‌گیرند. صورت چسبیده فقط با شاهد پیکره و تحلیل فعل اصلاح می‌شود؛ نام‌ها و صورت‌های مبهم می‌مانند.", "source": null, "example": {"wrong": "میرود", "right": "می‌رود"}} ``` ## `GET /api/v1/openapi.json` توصیف OpenAPI همین نشانی‌ها (نسخه‌ی ۳٫۱)، با توضیح فیلدها و یک درخواست و پاسخ واقعی برای هر کدام: [`/api/v1/openapi.json`](/api/v1/openapi.json). --- # یکدست کردن متن: normalize https://ghazalai.ir/docs/normalize/ > POST /api/v1/normalize متن را به شکل متن یکدست پیکره‌ی غزل درمی‌آورد: فقط آنچه انتخاب نیست درست می‌شود و فهرست پیشنهادی در کار نیست. `normalize` یکدست‌ساز پیکره‌ی غزل است که تنها اجرا می‌شود، همان که در بسته‌ی ghazal-nlp آمده است. `fix` با قاعده‌های کمتر نیست. فقط آنچه را انتخاب نیست درست می‌کند و بقیه را همان‌طور که نوشته شده نگه می‌دارد: - حرف‌های عربی (ي، ك، و ة در واژه‌ی فارسی) و رقم‌های عربی (٢ ← ۲)؛ - نویسه‌های نامرئی و نیم‌فاصله‌هایی که چیزی را عوض نمی‌کنند؛ - فاصله‌ی پیش و پس از نشانه‌ها، فاصله‌ی آغاز و پایان سطر، tab و سطرهای خالی پشت سر هم؛ - نیم‌فاصله‌هایی که نویسندگان دقیق همیشه می‌گذارند: «می» پیش از فعل، «ها»، پسوند پس از «ه»، و ترکیب‌هایی که بیشترشان سر هم می‌نویسند. کد میان `` ` `` یا ```` ``` ```` دست نمی‌خورد. | | `normalize` | `fix` | |---|---|---| | املا، واژه‌های گفتاری، سبک | دست نمی‌زند | درست می‌کند یا پیشنهاد می‌دهد | | رقم لاتین («20») | می‌ماند | «۲۰» پیشنهاد می‌شود | | فهرست تغییرها | ندارد | `applied` و `left` | | پاسخ به یک متن | تا `normalizer` عوض نشود، همان است | با بهتر شدن قاعده‌ها ممکن است عوض شود | `normalize` برای یکدست کردن متن پیش از ذخیره، مقایسه یا جست‌وجوست. برای درست کردن نوشته، [`fix`](/docs/fix/) را به کار ببرید. ## فیلدها | فیلد | مقدار | پیش‌فرض | کارش | |---|---|---|---| | `text` | رشته | | متن، تا ۲۰٬۰۰۰ نویسه. | | `verse` | `true`، `false` | `false` | متن شعر است: «ای» پس از واژه جدا می‌ماند، چون در شعر بیشتر حرف ندا است. | پاسخ `text` (متن یکدست)، `normalizer` (نسخه‌ی یکدست‌ساز) و `left_today` دارد. هزینه‌اش نویسه‌هایی است که فرستادید، یک بار. ## نمونه ```sh curl https://ghazalai.ir/api/v1/normalize -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "او دانش اموز خوبی است و كتاب ها را با دقت ميخواند ."}' ``` ```json { "text": "او دانش اموز خوبی است و کتاب‌ها را با دقت می‌خواند.", "normalizer": "1.0.0", "left_today": 49949 } ``` `fix` همین متن را همین‌طور درست می‌کند، ولی «اموز» را هم نشان می‌دهد؛ `normalize` به املا کاری ندارد: ```sh curl https://ghazalai.ir/api/v1/fix -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "او دانش اموز خوبی است و كتاب ها را با دقت ميخواند .", "compact": true}' ``` ```json { "kind": "formal", "text": "او دانش اموز خوبی است و کتاب‌ها را با دقت می‌خواند.", "applied": [ "«كتاب ها» → «کتاب‌ها» ghazal.persian_letters error", "«ميخواند» → «می‌خواند» ghazal.mi_prefix error", "« » → «» ghazal.punctuation_spacing error" ], "left": ["@8 «اموز» → «آموز» spell.typo error"], "left_today": 49949 } ``` ## شعر ```sh curl https://ghazalai.ir/api/v1/normalize -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "پندم مده ای دوست که دیوانه سر از بند ٢ قدم پیش تر نهاد", "verse": true}' ``` ```json { "text": "پندم مده ای دوست که دیوانه سر از بند ۲ قدم پیش تر نهاد", "normalizer": "1.0.0", "left_today": 49946 } ``` بی `verse`، «مده ای» «مده‌ای» می‌شود، چون در نثر «ای» پس از واژه بیشتر پسوند است: ```sh curl https://ghazalai.ir/api/v1/normalize -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "پندم مده ای دوست که دیوانه سر از بند ٢ قدم پیش تر نهاد"}' ``` ```json { "text": "پندم مده‌ای دوست که دیوانه سر از بند ۲ قدم پیش تر نهاد", "normalizer": "1.0.0", "left_today": 49946 } ``` --- # اعراب‌گذاری: vowels https://ghazalai.ir/docs/vowels/ > POST /api/v1/vowels روی متن فارسی اعراب می‌گذارد، فقط جایی که مطمئن است، و برای هر واژه خوانش‌های ممکن را با وزنشان می‌دهد. خط فارسی بیشتر مصوت‌های کوتاه را نمی‌نویسد، پس «ملک» را می‌شود مُلک، مَلِک یا مِلک خواند. `vowels` با بخش `vowels` بسته‌ی [ghazal-nlp](https://github.com/ghazalai/ghazal-nlp) خوانشی را که جمله می‌خواهد پیدا می‌کند و اعرابش را می‌گذارد. جایی که مطمئن نیست، واژه همان‌طور که نوشته شده می‌ماند. اعرابی که بسته نداده باشد نوشته نمی‌شود. دقت این بخش در آزمون‌ها در README بسته آمده است. ## فیلدها | فیلد | مقدار | پیش‌فرض | کارش | |---|---|---|---| | `text` | رشته | | متن، تا ۸٬۰۰۰ نویسه. | | `mode` | `full`، `minimal` | `full` | `full`: هر اعرابی که بسته از آن مطمئن است. `minimal`: فقط اعرابی که واژه را از هم‌نویسه‌هایش جدا می‌کند. | | `offsets` | `utf16`، `codepoint` | `utf16` | مثل [check](/docs/check/). [offsets](/docs/offsets/) | | `compact` | `true`، `false` | `false` | پاسخ کوتاه برای مدل‌های زبانی. | ## پاسخ - `text`: متن با اعراب. - `words`: هر واژه‌ی فارسی، با `start` و `end` و `text`؛ `form`، بهترین خوانش در این جمله، یا `null` اگر بسته خوانشی برایش نمی‌شناسد؛ `confidence`، اطمینان از ۰ تا ۱؛ و `readings`. - `readings`: اگر `confidence` کمتر از ۰٫۹ باشد، خوانش‌هایی که بسته برای این واژه می‌شناسد، هر کدام با `weight`: سهمش از شاهدهای بسته برای این واژه در متن‌های ویراسته و فرهنگ‌ها. این وزن احتمال آن خوانش در همین جمله نیست. اگر اطمینان ۰٫۹ یا بیشتر باشد، فهرست خالی است. - `left_today`: مثل [check](/docs/check/). با `compact` پاسخ فقط `text` و `unsure` دارد: برای هر واژه‌ای که اطمینانش کمتر از ۰٫۹ است یک سطر، به شکل `@جا واژه: خوانش وزن | خوانش وزن`. ## نمونه ```sh curl https://ghazalai.ir/api/v1/vowels -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "ملک را به ملک بخشید و رفت."}' ``` ```json { "text": "مِلْک را بِه مَلِک بَخشید و رَفت.", "words": [ {"start": 0, "end": 3, "text": "ملک", "form": "مِلْک", "confidence": 0.93, "readings": []}, {"start": 4, "end": 6, "text": "را", "form": "را", "confidence": 1.0, "readings": []}, {"start": 7, "end": 9, "text": "به", "form": "بِه", "confidence": 1.0, "readings": []}, {"start": 10, "end": 13, "text": "ملک", "form": "مَلِک", "confidence": 0.98, "readings": []}, {"start": 14, "end": 19, "text": "بخشید", "form": "بَخشید", "confidence": 1.0, "readings": []}, {"start": 20, "end": 21, "text": "و", "form": "وَ", "confidence": 0.84, "readings": [{"form": "وَ", "weight": 0.98}, {"form": "وُ", "weight": 0.01}]}, {"start": 22, "end": 25, "text": "رفت", "form": "رَفت", "confidence": 1.0, "readings": []} ], "left_today": 49974 } ``` دو «ملک» دو خوانش گرفتند: آنچه بخشیده شد مِلک است و آن که گرفت مَلِک. «و» بی‌اعراب ماند، چون اطمینان به «وَ» در این جمله ۰٫۸۴ است. وزن ۰٫۹۸ می‌گوید در شاهدهای بسته «و» بیشتر وَ خوانده شده، نه اینکه اینجا هم چنین است. ## نمونه‌ی کوتاه ```sh curl https://ghazalai.ir/api/v1/vowels -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "کرم در باغ دیدم و از کرم او سپاس گفتم.", "compact": true}' ``` ```json { "text": "کرم دَر باغ دیدَم وَ اَز کَرَم او سِپاس گُفتَم.", "unsure": [ "@0 کرم: کَرَم 0.36 | کِرِم 0.35 | کِرْم 0.15 | کُرُم 0.09 | کُرَّم 0.02", "@25 او: اُو 0.59 | اَو 0.33 | اِو 0.08" ], "left_today": 49962 } ``` «کرم» دوم، در «از کرم او»، کَرَم خوانده شد. «کرم» اول بی‌اعراب ماند: در این جمله کِرم هم درست است، و ابزار مطمئن نبود. --- # وزن و قافیه: verse https://ghazalai.ir/docs/verse/ > POST /api/v1/verse وزن، قافیه و ردیف شعر فارسی را می‌خواند، همان‌طور که شعرکاوی می‌خواند، و می‌گوید هر مصراع کجا از وزن بیرون می‌رود. هر مصراع را در یک خط بفرستید، یا دو مصراع را در یک خط با tab میانشان. چهل مصراع اول خوانده می‌شود، هر کدام تا ۳۰۰ نویسه و همه با هم تا ۲٬۴۰۰ نویسه؛ مصراع بلندتر با `invalid_request` رد می‌شود و بیش از ۲٬۴۰۰ نویسه با `too_long`. پاسخ همان است که [شعرکاوی](/verse/) نشان می‌دهد. هرچه مصراع بیشتر باشد، وزن روشن‌تر است. ## فیلدها | فیلد | مقدار | پیش‌فرض | کارش | |---|---|---|---| | `text` | رشته | | شعر، هر مصراع در یک خط؛ کل متن تا ۲۰٬۰۰۰ نویسه. | | `compact` | `true`، `false` | `false` | پاسخ کوتاه برای مدل‌های زبانی. | ## پاسخ کوتاه ```sh curl https://ghazalai.ir/api/v1/verse -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "بشنو این نی چون شکایت می‌کند\nاز جدایی‌ها حکایت می‌کند", "compact": true}' ``` ```json { "metre": "فاعلاتن فاعلاتن فاعلن (رمل مسدس محذوف یا وزن مثنوی)", "pattern": "-u---u---u-", "confidence": 93, "form": "masnavi", "rhyme": ["qafiya «کایت» radif «می‌کند»"], "lines": ["1 fits, licences: 0", "2 fits, licences: 0"], "left_today": 49947 } ``` - `metre`: وزن شعر؛ `pattern`: الگوی هجاهایش، `-` بلند و `u` کوتاه. - `confidence`: در آزمون، وزن چند درصد شعرها با همین شمار مصراع درست درآمد. - `form`: قالب: `ghazal`، `masnavi`، `robai` یا `dobeyti`. - `rhyme`: قافیه و ردیف. - `prose`: فقط اگر متن به نثر می‌ماند، `true`. - `lines`: برای هر مصراع یک سطر. `fits, licences: n` یعنی با این وزن جور است و n اختیار شاعری لازم دارد. `breaks at` می‌گوید در کدام واژه از وزن بیرون می‌رود و چرا: `long_for_short` هجای بلند به‌جای کوتاه، `short_for_long` کوتاه به‌جای بلند، `extra_syllable` هجای اضافه، `missing_syllable` هجای کم. `fits only with an unusual reading` یعنی فقط اگر آن واژه را جور دیگری بخوانید جور می‌شود. اگر مصراعی قافیه نداشته باشد، `misses the rhyme` به آخرش می‌آید. - `left_today`: فقط با کلید. ## مصراعی که از وزن بیرون می‌رود ```sh curl https://ghazalai.ir/api/v1/verse -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "بشنو این نی چون شکایت می‌کند\nاز جدایی‌ها حکایت بسیار می‌کند", "compact": true}' ``` ```json { "metre": "فاعلاتن فاعلاتن فاعلن (رمل مسدس محذوف یا وزن مثنوی)", "pattern": "-u---u---u-", "confidence": 90, "form": "masnavi", "rhyme": ["qafiya «میکند»"], "lines": ["1 fits, licences: 0", "2 breaks at «می‌کند» extra_syllable"], "left_today": 49941 } ``` «بسیار» دو هجا به مصراع دوم افزود، ولی شکست روی «می‌کند» نشان داده شد. جای شکست همیشه همان واژه‌ای نیست که عوض شده: در آزمون، ۴۶٪ روی همان واژه بود و ۸۰٪ تا یک واژه آن‌طرف‌تر. با مصراع شکسته، قافیه و ردیف هم درست شناخته نشد. ## پاسخ کامل بی `compact`، پاسخ هر چه شعرکاوی نشان می‌دهد دارد: | فیلد | معنی | |---|---| | `written` | شمار مصراع‌های متن؛ چهل تای اول خوانده می‌شود. | | `metres` | وزن‌هایی که جور می‌شوند، بهترین اول، هر کدام با `label`، `pattern`، `support` (شمار مصراع‌هایی که با آن جورند)، `licences` (جمع اختیارها)، `poems` (شمار شعرهای گنجور در این وزن)، `feet` (رکن‌ها) و `usual` (میانه‌ی اختیارهای هر مصراع). | | `best` | وزن شعر؛ اگر دو وزن برابر باشند، هر دو. | | `form`، `prose`، `confidence` | مثل پاسخ کوتاه. | | `rhymes` | قافیه‌ها: `qafiya`، `radif`، `words` (واژه‌های قافیه)، `off` (مصراع‌هایی که قافیه ندارند)، `repeated` (قافیه‌های تکراری) و `abstention`. | | `lines` | برای هر مصراع: `text`؛ `own`، وزن‌هایی که این مصراع به‌تنهایی با آن‌ها جور است؛ `pieces`، واژه‌ها با نقش قافیه و ردیف؛ `readings`، هجاهای مصراع در هر وزن، با اختیارهای هر هجا (`devices`)؛ و `nearest`، نزدیک‌ترین خوانش در وزنی که مصراع با آن جور نیست، با `fault` روی هر هجای شکسته. | ```sh curl -s https://ghazalai.ir/api/v1/verse -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "بشنو این نی چون شکایت می‌کند\nاز جدایی‌ها حکایت می‌کند"}' | jq -c '.metres[0]' ``` ```json {"label": "فاعلاتن فاعلاتن فاعلن (رمل مسدس محذوف یا وزن مثنوی)", "pattern": "-u---u---u-", "support": 2, "licences": 0, "poems": 5503.0, "feet": [{"name": "فاعلاتن", "weights": "-u--"}, {"name": "فاعلاتن", "weights": "-u--"}, {"name": "فاعلن", "weights": "-u-"}], "usual": 0.0} ``` --- # ساختمان واژه: word https://ghazalai.ir/docs/word/ > POST /api/v1/word می‌گوید یک واژه از چه ساخته شده: بن و پسوندها، تحلیل فعل، «ه» پایانی، و صورت نوشتاری اگر واژه گفتاری است. یک واژه را با نیم‌فاصله‌هایش بفرستید. پاسخ همان تحلیلی است که [واژه‌کاوی](/word/) نشان می‌دهد، بی هیچ متنی از فرهنگ‌ها: نه معنی، نه تعریف، نه مثل. از فرهنگ‌ها فقط این می‌آید که واژه در آن‌ها سرواژه هست یا نه. ## فیلدها | فیلد | مقدار | کارش | |---|---|---| | `word` | رشته، تا ۶۰ نویسه | یک واژه‌ی فارسی. فاصله، رقم یا حرف لاتین با `invalid_request` رد می‌شود. | ## پاسخ | فیلد | معنی | |---|---| | `lemmas` | خود واژه اگر در فرهنگ‌ها سرواژه است، بعد مصدر فعل‌هایی که می‌تواند باشد، بعد بن‌هایی که در `parts` آمده است. | | `parts` | تا سه راه شکستن واژه به بن و پسوند، هر کدام با `lemma` و `parts`. نقش هر تکه (`role`): `stem` بن، `degree` «تر» و «ترین»، `plural` نشانه‌ی جمع، `indef` «ی» نکره، `clitic` ضمیر یا فعل پیوسته. | | `verb` | هر خوانش فعلی واژه: `lemma`، `tense`، `aspect`، `mood`، `person`، `number`، `polarity`، `form` و `anatomy`، تکه‌های فعل با نقششان (`preverb`، `imperfective`، `neg_imperfective`، `neg`، `subjunctive`، `stem_past`، `stem_present`، `ending`، `participle`). | | `silent_heh` | اگر واژه به «ه» ختم می‌شود، آیا این «ه» خوانده نمی‌شود؛ وگرنه `null`. | | `spelling` | آنچه قاعده‌های املا به‌جای این واژه پیشنهاد می‌کنند، با `suggestion`، `severity` و `rule`. | | `formal` | صورت نوشتاری، اگر واژه گفتاری است؛ وگرنه فهرست خالی. | | `left_today` | مثل [check](/docs/check/). | ## نمونه ```sh curl https://ghazalai.ir/api/v1/word -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"word": "کتاب‌هایمان"}' ``` ```json { "word": "کتاب‌هایمان", "lemmas": ["کتاب"], "parts": [ {"lemma": "کتاب", "parts": [{"text": "کتاب", "role": "stem"}, {"text": "های", "role": "plural"}, {"text": "مان", "role": "clitic"}]} ], "verb": [], "silent_heh": null, "spelling": [], "formal": [], "left_today": 49989 } ``` ## واژه‌ی گفتاری ```sh curl https://ghazalai.ir/api/v1/word -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"word": "نمی‌دونستم"}' ``` ```json { "word": "نمی‌دونستم", "lemmas": ["دانستن"], "parts": [], "verb": [ {"lemma": "دانستن", "tense": "past", "aspect": "imperfective", "mood": "indicative", "person": 1, "number": "sing", "polarity": "neg", "form": null, "anatomy": [{"text": "نمی", "role": "neg_imperfective"}, {"text": "دونست", "role": "stem_past"}, {"text": "م", "role": "ending"}]} ], "silent_heh": null, "spelling": [], "formal": ["نمی‌دانستم"], "left_today": 49990 } ``` جدول صرف فعل‌ها در [verb](/docs/verb/) است. --- # فعل و صرف آن: verb https://ghazalai.ir/docs/verb/ > POST /api/v1/verb فعل‌های یک متن کوتاه را تحلیل می‌کند، زمان‌هایی را که با دو واژه ساخته می‌شوند می‌شناسد و جدول صرف هر فعل را می‌دهد. یک فعل، یک مصدر یا متنی کوتاه بفرستید. پاسخ همان است که [واژه‌کاوی](/word/) برای فعل‌ها نشان می‌دهد. فعل‌های گفتاری هم شناخته می‌شوند («میشه»، «اومدم»، «نمی‌دونم»). ## فیلدها | فیلد | مقدار | کارش | |---|---|---| | `text` | رشته، تا ۱٬۰۰۰ نویسه | فعل، مصدر یا متن کوتاه؛ چهل واژه‌ی اول خوانده می‌شود. | ## پاسخ - `verbs`: هر واژه‌ای که می‌تواند فعل باشد، با `text` و همه‌ی خوانش‌هایش در `readings`: `lemma`، `tense`، `aspect`، `mood`، `person`، `number`، `polarity`، `form` و `anatomy`، مثل [word](/docs/word/). - `constructions`: زمان‌هایی که با دو واژه ساخته می‌شوند، مثل «رفته بود» و «خواهد رفت»: `words`، `construction`، `lemma`، `person`، `number`، `polarity`. - `tables`: برای هر مصدر، صورت‌های مثبت (`pos`) و منفی (`neg`) در `present`، `subjunctive`، `past`، `imperfect` و `imperative`، هر کدام در شش شخص: اول شخص، دوم شخص و سوم شخص مفرد، بعد همین سه در جمع. جایی که شخصی صورتی ندارد، `null`. - `left_today`: مثل [check](/docs/check/). ## نمونه ```sh curl https://ghazalai.ir/api/v1/verb -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "نمی‌گفتند"}' ``` ```json { "verbs": [ {"text": "نمی‌گفتند", "readings": [{"lemma": "گفتن", "tense": "past", "aspect": "imperfective", "mood": "indicative", "person": 3, "number": "plur", "polarity": "neg", "form": null, "anatomy": [{"text": "نمی", "role": "neg_imperfective"}, {"text": "گفت", "role": "stem_past"}, {"text": "ند", "role": "ending"}]}]} ], "constructions": [], "tables": { "گفتن": { "pos": { "present": ["می‌گویم", "می‌گویی", "می‌گوید", "می‌گوییم", "می‌گویید", "می‌گویند"], "subjunctive": ["بگویم", "بگویی", "بگوید", "بگوییم", "بگویید", "بگویند"], "past": ["گفتم", "گفتی", "گفت", "گفتیم", "گفتید", "گفتند"], "imperfect": ["می‌گفتم", "می‌گفتی", "می‌گفت", "می‌گفتیم", "می‌گفتید", "می‌گفتند"], "imperative": [null, "بگو", null, null, "بگویید", null] }, "neg": { "present": ["نمی‌گویم", "نمی‌گویی", "نمی‌گوید", "نمی‌گوییم", "نمی‌گویید", "نمی‌گویند"], "subjunctive": ["نگویم", "نگویی", "نگوید", "نگوییم", "نگویید", "نگویند"], "past": ["نگفتم", "نگفتی", "نگفت", "نگفتیم", "نگفتید", "نگفتند"], "imperfect": ["نمی‌گفتم", "نمی‌گفتی", "نمی‌گفت", "نمی‌گفتیم", "نمی‌گفتید", "نمی‌گفتند"], "imperative": [null, "نگو", null, null, "نگویید", null] } } }, "left_today": 49991 } ``` ## «خواهد رفت» ```sh curl -s https://ghazalai.ir/api/v1/verb -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "خواهد رفت"}' | jq -c '.constructions' ``` ```json [{"words": ["خواهد", "رفت"], "construction": "future", "lemma": "رفتن", "person": 3, "number": "sing", "polarity": "pos"}] ``` --- # عبارت‌های عربی: arabic https://ghazalai.ir/docs/arabic/ > POST /api/v1/arabic عبارت‌های عربی درون متن فارسی را پیدا می‌کند: آیه، حدیث، مصراع عربی و عبارت‌هایی مثل «علیه السلام». `arabic` با بخش `arabic` بسته‌ی [ghazal-nlp](https://github.com/ghazalai/ghazal-nlp) عبارت‌های عربی دو واژه یا بلندتر را در متن فارسی پیدا می‌کند. واژه‌ی عربی‌تبار در جمله‌ی فارسی فارسی است: «علم» و «ثلث» عبارت عربی نیستند. در آزمون من روی ۲۷۵ سطر از شش نوع متن، ۸۵٪ واژه‌هایی که عربی شمرده شد عربی بود و ۶۳٪ واژه‌های عربی پیدا شد. ## فیلدها | فیلد | مقدار | پیش‌فرض | کارش | |---|---|---|---| | `text` | رشته | | متن، تا ۲۰٬۰۰۰ نویسه. | | `offsets` | `utf16`، `codepoint` | `utf16` | مثل [check](/docs/check/). [offsets](/docs/offsets/) | ## پاسخ `spans` عبارت‌های عربی است، به ترتیب جا در متن، هر کدام با `start`، `end`، `text` و `kind`: `formula` برای عبارت‌های ثابتی مثل «علیه السلام» و `passage` برای بقیه. `left_today` مثل [check](/docs/check/) است. ## نمونه ```sh curl https://ghazalai.ir/api/v1/arabic -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "او گفت: «هذا هو الذی لم یکن له شریک» و رفت."}' ``` ```json { "spans": [{"start": 9, "end": 35, "text": "هذا هو الذی لم یکن له شریک", "kind": "passage"}], "left_today": 49957 } ``` ```sh curl https://ghazalai.ir/api/v1/arabic -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "امام علی علیه السلام فرمود: الناس اعداء ما جهلوا. این سخن را بسیار شنیده‌ایم."}' ``` ```json { "spans": [ {"start": 9, "end": 20, "text": "علیه السلام", "kind": "formula"}, {"start": 28, "end": 48, "text": "الناس اعداء ما جهلوا", "kind": "passage"} ], "left_today": 49923 } ``` اگر متن را به [check](/docs/check/) یا [fix](/docs/fix/) می‌دهید، می‌توانید پیشنهادهایی را که درون این بازه‌ها می‌افتند کنار بگذارید. --- # متن Markdown https://ghazalai.ir/docs/markdown/ > با format: markdown فقط نثر بررسی می‌شود و کد، نشانی‌ها و نشانه‌های Markdown دست نمی‌خورند. اگر متن Markdown است، در `check` یا `fix` فیلد `"format": "markdown"` را بفرستید. ## آنچه دست نمی‌خورد این‌ها هرگز پیشنهادی نمی‌گیرند و `fix` حتی یک نویسه‌شان را تغییر نمی‌دهد: - front matter، یعنی `---` در آغاز متن تا `---` بسته‌شدنش؛ - بلوک‌های کد میان ```` ``` ```` یا `~~~`، و کد درون خط؛ - نشانی‌های وب و ایمیل، مقصد و عنوان پیوندها و تصویرها، و پیوندهایی مثل ``؛ - برچسب‌ها و توضیح‌های HTML؛ - تعریف ارجاع‌ها (`[ref]: https://...`) و نشانه‌ی پانوشت (`[^1]`)؛ - نشانه‌های خود Markdown: `#` سرتیترها، `>` نقل‌قول، نشانه‌ی فهرست (`-`، `*`، `+`، `1.`)، خانه‌ی تیک (`[ ]`، `[x]`)، تأکید (`*`، `_`، `~~`)، `\`، خط افقی، `|` جدول و ردیف `---` آن، و فاصله‌های پایان خط. متن پیوند، متن جایگزین تصویر، سرتیترها، بندهای فهرست، نقل‌قول‌ها و خانه‌های جدول نثرند و بررسی می‌شوند. کد درون خط و نشانی‌ها در جمله مثل یک واژه‌ی خنثی می‌مانند، پس واژه‌های دوروبرشان همان‌طور که خوانده می‌شوند بررسی می‌شوند. پیشنهادی که به نشانه‌ای از Markdown برسد، مثلاً اصلاح فاصله درست کنار نشانه‌ی تأکید، کنار گذاشته می‌شود تا Markdown نشکند. بلوک کدی که فقط با چهار فاصله تورفته باشد شناخته نمی‌شود؛ کد را میان ```` ``` ```` بگذارید. ## نمونه ```sh curl https://ghazalai.ir/api/v1/fix -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "## نصب\n\nبرای نصب، `pip install ghazal-nlp` را اجرا کنید و [راهنما](https://example.com/guide) را بخوانید. این کتاب ها را میخوانم .\n", "format": "markdown"}' ``` ```json { "kind": "formal", "text": "## نصب\n\nبرای نصب، `pip install ghazal-nlp` را اجرا کنید و [راهنما](https://example.com/guide) را بخوانید. این کتاب‌ها را می‌خوانم.\n", "applied": [ {"start": 110, "end": 117, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 121, "end": 128, "text": "میخوانم", "suggestions": ["می‌خوانم"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 128, "end": 129, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ], "left": [], "left_today": 49869 } ``` سرتیتر، کد و پیوند همان‌طور که فرستاده شد برگشت. با `format: markdown` هم جای پیشنهادها در متن است، دقیقاً همان‌طور که فرستادید، با همه‌ی نشانه‌هایش. --- # جای پیشنهادها: offsets https://ghazalai.ir/docs/offsets/ > start و end با UTF-16 یا با code point شمرده می‌شوند؛ هر کدام را که زبان برنامه‌تان به کار می‌برد انتخاب کنید. `start` و `end` از صفر شمرده می‌شوند و خود `end` جزء پیشنهاد نیست. فیلد `offsets` واحد این شمارش را تعیین می‌کند: | `offsets` | واحد | زبان‌هایی که رشته را این‌طور می‌شمارند | |---|---|---| | `utf16` (پیش‌فرض) | UTF-16 code unit | JavaScript، Java، C#، `NSString` در Swift | | `codepoint` | Unicode code point | Python | حرف‌های فارسی، نیم‌فاصله و رقم‌های فارسی در هر دو یک واحدند، پس در بیشتر متن‌های فارسی این دو یکی‌اند. پس از نویسه‌ای بیرون از Basic Multilingual Plane، مثل بیشتر شکلک‌ها، فرق می‌کنند: چنین نویسه‌ای در `utf16` دو واحد است و در `codepoint` یک واحد. ## نمونه ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "این را دیدم 😀 و کتاب ها را خواندم."}' ``` ```json { "kind": "formal", "register": [0, 2], "findings": [ {"start": 17, "end": 24, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null} ], "left_today": 49966 } ``` همان متن با `"offsets": "codepoint"`: ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "این را دیدم 😀 و کتاب ها را خواندم.", "offsets": "codepoint"}' ``` ```json { "kind": "formal", "register": [0, 2], "findings": [ {"start": 16, "end": 23, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null} ], "left_today": 49966 } ``` شکلک پیش از پیشنهاد آمده، پس `start` در `utf16` یکی بیشتر است. با واحد درست، برش متن همان `text` پیشنهاد است. در JavaScript، با پیش‌فرض: ```js const f = answer.findings[0]; text.slice(f.start, f.end); // "کتاب ها" ``` و در Python، با `"offsets": "codepoint"`: ```python f = answer["findings"][0] text[f["start"]:f["end"]] # "کتاب ها" ``` با `format: markdown` هم جای پیشنهادها در متن است، همان‌طور که فرستادید. در `fix`، جای `applied` در متن فرستاده‌شده است و جای `left` در متن برگشتی. شمار نویسه‌ها برای سهمیه همیشه با code point است، هر `offsets` که انتخاب کنید. --- # نوع متن و سبک https://ghazalai.ir/docs/kinds/ > kind می‌گوید متن رسمی است یا محاوره، و style می‌گوید با سبک غزل بررسی شود یا با قاعده‌های فرهنگستان. ## نوع متن: `kind` فارسی گفتاری در گفت‌وگوی دوستانه درست است و در نامه‌ی رسمی نادرست. برای همین غزل باید بداند متن از چه نوعی است: | `kind` | در نوشت‌یار | چه بررسی می‌شود | |---|---|---| | `formal` | رسمی | نوشتار ویراسته. صورت‌های گفتاری توصیه می‌گیرند: «میگم» ← «می‌گویم». | | `colloquial` | محاوره | گفتار نوشته‌شده. صورت‌های گفتاری پیشنهاد نمی‌گیرند؛ املا و فاصله و نیم‌فاصله با همان املای گفتاری بررسی می‌شوند: «خونه ت» ← «خونه‌ت». | | `mixed` | نیمه‌رسمی | بیشتر نوشتاری، با چند صورت گفتاری. با هر دو دسته قاعده بررسی می‌شود و صورت‌های گفتاری پیشنهاد نمی‌گیرند. | | `auto` (پیش‌فرض) | خودکار | از روی واژه‌ها تشخیص داده می‌شود. | `register` در پاسخ `[spoken, written]` است: شمار نشانه‌های گفتار و نوشتار در همه‌ی متن‌های درخواست. `auto` با این دو عدد تصمیم می‌گیرد: 1. اگر دو برابر نشانه‌های گفتار از سه برابر نشانه‌های نوشتار بیشتر باشد، `colloquial`؛ 2. وگرنه اگر نشانه‌های گفتار دست‌کم ۳ باشد و کمتر از نشانه‌های نوشتار نباشد، `mixed`؛ 3. وگرنه `formal`. `kind` پاسخ می‌گوید چه تصمیمی گرفته شد. اگر نوع متن را می‌دانید، خودتان بفرستید؛ متن کوتاه نشانه‌ی کمی دارد. ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "کتاب ها رو بهت میدم، فردا میام خونه ت."}' ``` ```json { "kind": "colloquial", "register": [5, 0], "findings": [ {"start": 0, "end": 7, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 15, "end": 19, "text": "میدم", "suggestions": ["می‌دم"], "rule": "spacing.mi", "severity": "error", "confidence": null}, {"start": 31, "end": 37, "text": "خونه ت", "suggestions": ["خونه‌ت"], "rule": "spacing.clitic", "severity": "error", "confidence": null} ], "left_today": 49962 } ``` همان متن با `"kind": "formal"`: ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "کتاب ها رو بهت میدم، فردا میام خونه ت.", "kind": "formal"}' ``` ```json { "kind": "formal", "register": [5, 0], "findings": [ {"start": 0, "end": 7, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 8, "end": 10, "text": "رو", "suggestions": ["را", "روی"], "rule": "register.ra", "severity": "advice", "confidence": null}, {"start": 11, "end": 14, "text": "بهت", "suggestions": ["به تو"], "rule": "register.clitic", "severity": "advice", "confidence": null}, {"start": 15, "end": 19, "text": "میدم", "suggestions": ["می‌دهم"], "rule": "register.verb", "severity": "advice", "confidence": null}, {"start": 26, "end": 30, "text": "میام", "suggestions": ["می‌آیم"], "rule": "register.verb", "severity": "advice", "confidence": null}, {"start": 31, "end": 35, "text": "خونه", "suggestions": ["خانه"], "rule": "register.un", "severity": "advice", "confidence": null} ], "left_today": 49962 } ``` ## سبک: `style` | `style` | در نوشت‌یار | چه می‌خواهد | |---|---|---| | `ghazal` (پیش‌فرض) | سبک غزل | آن قاعده‌های فرهنگستان که نویسندگان دقیق رعایت می‌کنند، و قاعده‌های خود غزل جایی که رعایت نمی‌کنند. هر جا دو صورت درست است، یکی را ترجیح می‌دهد: «آن‌ها» به‌جای «آنها»، «خانه‌ی» به‌جای «خانهٔ». | | `academy` | فرهنگستان | قاعده‌های دستور خط فارسی فرهنگستان زبان و ادب فارسی. | ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "خانهٔ ما بزرگترین خانهٔ این کوچه است."}' ``` ```json { "kind": "formal", "register": [0, 1], "findings": [ {"start": 0, "end": 5, "text": "خانهٔ", "suggestions": ["خانه‌ی"], "rule": "ghazal.ezafe_after_silent_he", "severity": "style", "confidence": null}, {"start": 9, "end": 17, "text": "بزرگترین", "suggestions": ["بزرگ‌ترین"], "rule": "ghazal.house_forms", "severity": "style", "confidence": null}, {"start": 18, "end": 23, "text": "خانهٔ", "suggestions": ["خانه‌ی"], "rule": "ghazal.ezafe_after_silent_he", "severity": "style", "confidence": null} ], "left_today": 49963 } ``` ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "خانهٔ ما بزرگترین خانهٔ این کوچه است.", "style": "academy"}' ``` ```json { "kind": "formal", "register": [0, 1], "findings": [ {"start": 9, "end": 17, "text": "بزرگترین", "suggestions": ["بزرگ‌ترین"], "rule": "academy.comparative_tar", "severity": "advice", "confidence": null} ], "left_today": 49963 } ``` فرهنگستان «خانهٔ» را می‌پذیرد و «بزرگ‌ترین» را فقط توصیه می‌کند. سبک غزل هر سه را پیشنهاد می‌دهد، ولی با سطح «سبک»: هیچ‌کدام خطا نیست و `fix` با `apply: sure` به آن‌ها دست نمی‌زند. --- # خطاها https://ghazalai.ir/docs/errors/ > هر خطای API یک بدنه‌ی یکسان دارد؛ اینجا هر کد، وضعیت HTTP آن و کاری که باید کرد. هر خطا در هر نشانی `/api/v1/` این بدنه را دارد، با یک وضعیت HTTP: ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H "authorization: Bearer $GHAZAL_KEY" \ -d '{"text": "سلام", "kind": "spoken"}' ``` ```json {"error": {"code": "invalid_request", "message": "kind: Input should be 'auto', 'formal', 'mixed' or 'colloquial'", "message_fa": "مقدار kind درست نیست.", "request_id": "req_3deec0756a6d59c3"}} ``` - `code`: ثابت است؛ برنامه‌تان را بر پایه‌ی آن بنویسید. - `message`: به انگلیسی، برای خودتان یا لاگ‌ها. در `invalid_request` با نام فیلد شروع می‌شود: `texts.2` یعنی سومین عضو `texts`، و `body` یعنی کل درخواست. - `message_fa`: به فارسی، مناسب نشان دادن به نویسنده. - `request_id`: در سرآیند `X-Request-Id` هر پاسخ `/api/v1/` هم می‌آید، چه درست چه خطا. اگر مشکلی را گزارش می‌کنید، آن را بفرستید. پیام خطا متن شما و مقدارهایی را که فرستادید تکرار نمی‌کند؛ حداکثر نام فیلد را می‌آورد. ## کدها | `code` | وضعیت | کی | چه باید کرد | |---|---|---|---| | `invalid_request` | `422` | فیلدی نیست، ناشناخته است، یا نوع یا مقدارش نادرست است؛ بدنه JSON نیست؛ هر دو یا هیچ‌یک از `text` و `texts` آمده؛ نام قاعده ناشناخته است. | فیلدی را که نام برده شده درست کنید. همان درخواست را دوباره نفرستید. | | `unauthorized` | `401` | مقدار `Authorization` کلیدی نیست که می‌شناسیم: نادرست است، باطل شده، یا حسابش پاک شده؛ یا `usage` را بی‌کلید صدا زده‌اید. | کلید معتبر را در سرآیند `Authorization` بفرستید. | | `too_long` | `413` | متن بیش از ۲۰٬۰۰۰ نویسه است (برای `vowels` ۸٬۰۰۰؛ در `check` و `fix` با کلید طرح شخصی، سازمانی یا بسته ۲۰۰٬۰۰۰)، بدنه بیش از ۲۵۶ کیلوبایت است (برای همان سند بلند ۱٬۲۰۴٬۰۹۶ بایت)، یا متن برای یک درخواست سنگین است، مثل رشته‌ای بلند از نیم‌فاصله یا اعراب پشت سر هم. | متن را بند به بند، با `texts` یا در چند درخواست، بفرستید. | | `rate_limited` | `429` | درخواست‌های این فرستنده زیاد است، یا بیش از ۳ درخواست هم‌زمان. | به اندازه‌ی `Retry-After` ثانیه صبر کنید و دوباره بفرستید. | | `quota_exceeded` | `429` | نویسه‌های امروز این کلید تمام شده است. | تا ۰۰:۰۰ UTC صبر کنید (`Retry-After` ثانیه‌ها را می‌گوید). | | `pack_day_exceeded` | `429` | این کلید امروز هر چه می‌توانست از بسته‌ها برداشته است. | تا ۰۰:۰۰ UTC صبر کنید، یا کلید دیگری از همان حساب را به کار ببرید. | | `key_required` | `401` | برنامه بدون کلید متن فرستاده است. | در صفحه‌ی [حساب کاربری](/account/) وارد شوید و کلید رایگان بسازید؛ آن را در `Authorization: Bearer gz_...` بفرستید. | | `text_cap` | `413` | فقط در برنامه‌ی غزل و افزونه‌ی Word: متن از سقف یک متن برای این حساب، یا بدون حساب، بلندتر است. `typing` در خطا سقف‌ها را می‌گوید. | فقط بخش اول متن را، تا `typing.text` نویسه، بفرستید. | | `day_cap` | `429` | فقط در برنامه‌ی غزل و افزونه‌ی Word: سهمیه‌ی امروز نوشتن تمام شده است. | تا ۰۰:۰۰ UTC صبر کنید، یا وارد حساب شوید. | | `plan_required` | `403` | افزونه‌ی Word بدون طرح شخصی یا سازمانی. | با حسابی که طرح شخصی یا سازمانی دارد وارد شوید. | | `busy` | `503` | سرور پر است، یا کار درخواست بیش از ۹ ثانیه طول کشید. | به اندازه‌ی `Retry-After` ثانیه صبر کنید و دوباره بفرستید. | | `not_found` | `404` | چنین نشانی‌ای نیست، یا این نشانی این روش را نمی‌پذیرد، مثلاً `GET /api/v1/check`. | نشانی و روش را بررسی کنید. | | `method_not_allowed` | `405` | روشی که هیچ نشانی‌ای نمی‌پذیرد، مثلاً `OPTIONS`. | `GET` یا `POST` را همان‌طور که آمده به کار ببرید. | | `internal` | `500` | خطایی در سرور غزل. | یک بار کمی بعد دوباره بفرستید؛ اگر ماند، با `request_id` گزارش کنید. | هر پاسخ `429` و `503` سرآیند `Retry-After` دارد. در خطای `429`، فیلد `retry_after` هم شمار ثانیه‌های انتظار است. خطاهای سقف روزانه‌ی نویسه، `left_today` و `reset_at` هم دارند: نویسه‌های مانده و زمان شروع روز بعد به وقت UTC. این دو مقدار در سرآیندهای `X-RateLimit-Remaining` و `X-RateLimit-Reset` هم می‌آیند. سهمیه‌ی مانده ممکن است صفر نباشد؛ متنی کوتاه‌تر می‌تواند در آن جا شود. [سقف‌ها](/docs/keys/) ## دو نمونه‌ی دیگر روش نادرست: ```sh curl https://ghazalai.ir/api/v1/check ``` ```json {"error": {"code": "not_found", "message": "No such endpoint for this HTTP method. The list is at /api/v1/openapi.json.", "message_fa": "چنین نشانی‌ای با این نوع درخواست در API نیست.", "request_id": "req_242a146231183648"}} ``` کلید نادرست: ```sh curl https://ghazalai.ir/api/v1/check -H 'content-type: application/json' \ -H 'authorization: Bearer gz_wrong' -d '{"text": "سلام"}' ``` ```json {"error": {"code": "unauthorized", "message": "Unknown or revoked API key. Send a valid key in Authorization: Bearer gz_...", "message_fa": "این کلید شناخته نشد یا باطل شده است.", "request_id": "req_fb787c37eb1f1a24"}} ``` --- # فهرست قاعده‌ها https://ghazalai.ir/docs/rules/ > قاعده‌هایی که API امروز اجرا می‌کند، با نام، سطح، توضیح، نمونه و منبع هر کدام. نام هر قاعده یک خانواده دارد و یک نام، با نقطه میانشان: `ghazal.mi_prefix`. در `only` و `disable` می‌توانید نام کامل یا خانواده را با نقطه‌ی پایانش بفرستید، مثلاً `"disable": ["prose."]`. سطح هر قاعده یکی از چهار سطح خطا، توصیه، احتمالی و سبک است. بعضی قاعده‌ها دو سطح دارند: مثلاً پیشنهاد املایی وقتی مدل مطمئن است خطاست و وقتی مطمئن نیست احتمالی. این فهرست از همان کارت‌هایی ساخته شده که `GET /api/v1/rules` برمی‌گرداند. آن نشانی چند قاعده‌ی دیگر هم دارد که اجرا نمی‌شوند و پیشنهادی نمی‌دهند. The list itself: https://ghazalai.ir/docs/rules.md, or GET /api/v1/rules. --- # نسخه و تغییرات https://ghazalai.ir/docs/versions/ > آنچه نسخه‌ی ۱ API قول می‌دهد، و هر چه از ۲۲ آبان ۱۴۰۵ در آن تغییر کرده است. ## قول نسخه‌ی ۱ نشانی‌های `/api/v1/` فقط بزرگ‌تر می‌شوند: - نشانی، فیلد یا مقدار تازه ممکن است اضافه شود. برنامه‌تان فیلدهای ناشناخته‌ی پاسخ را نادیده بگیرد. - هیچ نشانی یا فیلدی برداشته نمی‌شود و معنایش عوض نمی‌شود. `code` خطاها هم ثابت است. - نام هر قاعده همیشه همان معنا را دارد. قاعده‌ی تازه نام تازه می‌گیرد. پیشنهادها با بهتر شدن قاعده‌ها عوض می‌شوند، پس پاسخ امروز به یک متن ممکن است با پاسخ فردا فرق کند. اگر برای یک متن همیشه همان خروجی را می‌خواهید، [`normalize`](/docs/normalize/) را به کار ببرید: تا `normalizer` پاسخ عوض نشود، خروجی‌اش همان است. ## تغییرات ### ۲۲ آبان ۱۴۰۵ - نشانی‌های تازه: [`normalize`](/docs/normalize/)، [`vowels`](/docs/vowels/)، [`verse`](/docs/verse/)، [`word`](/docs/word/)، [`verb`](/docs/verb/) و [`arabic`](/docs/arabic/). - فیلد `compact` در `check`، `fix`، `vowels` و `verse`: پاسخ کوتاه برای مدل‌های زبانی. - فراخوانی‌ای که بیش از ۹ ثانیه طول بکشد، `503` با کد `busy` می‌گیرد. [خطاها](/docs/errors/) - سه ابزار تازه در [سرور MCP](/docs/mcp/): `add_vowels`، `scan_verse` و `conjugate_verb`. --- # برای مدل‌های زبانی https://ghazalai.ir/docs/agents/ > غزل را به عامل هوش مصنوعی‌تان بدهید تا فارسی درست‌تری بنویسد: روال کار، آنچه نباید درست شود، متنی برای پرامپت سیستمی و تعریف ابزار. عامل هوش مصنوعی نثر فارسی را که نوشته‌ای یا ویرایش کرده‌ای پیش از تحویل به fix غزل بده: {"text": "<متن>", "apply": "house"}. برای Markdown، format: markdown بفرست؛ اگر فارسی گفتاری خواسته شده، kind: colloquial و اگر متن از پیش «خانهٔ» می‌نویسد، style: academy. متن برگشتی را به کار ببر. درباره‌ی توصیه‌ها و حدس‌های املایی در left تصمیم بگیر؛ حدس را فقط وقتی بپذیر که مطمئنی همان واژه را می‌خواستی. نقل‌قول، نام‌ها، شعر، کد و نشانی‌ها را تغییر نده. فقط نثر خودت را بفرست؛ اگر متن چنین بخش‌هایی دارد، check را صدا بزن و پیشنهادهای بیرون از آن‌ها را اعمال کن. فقط اگر متن را تغییر دادی، دوباره fix را اجرا کن. ```fa هر متن فارسی را پیش از تحویل با ابزار غزل درست کن: POST https://ghazalai.ir/api/v1/fix با بدنه‌ی JSON {"text": "<متن>"} و سرآیند Authorization: Bearer gz_...؛ اگر متن Markdown است، "format": "markdown" را هم بفرست. "text" پاسخ را به‌جای متن خودت بگذار. در "left"، پیشنهادهای style و advice اختیاری‌اند و پیشنهادهای spell.* و guess را فقط وقتی بپذیر که مطمئنی. نقل‌قول، نام‌ها، شعر و کد را نفرست و تغییر نده. برای متن بلند، همان متن اولیه را با from: checked_to بفرست تا بررسی به پایان برسد. اگر پاسخ 429 یا 503 بود، به اندازه‌ی Retry-After ثانیه صبر کن. ``` ## سند بلند با کلید طرح شخصی یا بسته، `fix` و `check` متن تا ۲۰۰٬۰۰۰ نویسه می‌پذیرند و بخش‌بخش پاسخ می‌دهند. تا وقتی `checked_to` به پایان متن نرسیده، همان متن اولیه را با `from: checked_to` بفرستید و `text` پاسخ‌ها را بی هیچ فاصله‌ای پشت هم بگذارید. `fix.py` در پوشه‌ی مهارت همین کار را می‌کند. [سند بلند](/docs/keys/#سند-بلند) ## متن نوشته‌شده با مدل زبانی برای فارسی‌ای که مدل زبانی نوشته، `"profile": "llm"` را به `check`، `fix`، `check_persian` یا `fix_persian` بدهید. برای نثر صمیمی با صورت‌های نوشتاری، `"kind": "formal"` و برای متن گفتاری، `"kind": "colloquial"` بفرستید. این تنظیم تشخیص نوع متن را عوض نمی‌کند. ```json {"text": "این سوال می‌باشد.", "profile": "llm", "kind": "formal"} ``` پیش از انتخاب سطح هر قاعده، نمونه‌ای از پیشنهادهایش را خواندم. این تنظیم قاعده‌ها و سطحشان را تعیین می‌کند. تشخیص قاعده، جای پیشنهاد و صورت پیشنهادی همان می‌ماند. اگر `profile` را نفرستید، پاسخ مثل قبل است. | precision در نمونه‌ی خوانده‌شده | سطح | |---|---| | دست‌کم ۹۵٪ | `error` | | دست‌کم ۸۵٪ و کمتر از ۹۵٪ | `advice` | | کمتر از ۸۵٪ یا بی‌نمونه | حذف | یافته‌های سبکی، که هر دو صورت در آن‌ها درست است، `style` می‌مانند و `apply: house` مثل قبل اصلاحشان می‌کند. سطح‌ها را از همان متن‌هایی انتخاب کردم که پیشنهادها را در آن‌ها خواندم؛ روی متن‌های جداگانه نسنجیده‌ام. بعضی قاعده‌ها فقط یک یا دو نمونه داشتند. ابتدا `house` ترجیح‌های نوشتاری را تعیین می‌کند و سپس `profile` پیشنهادها را محدود می‌کند. `only` از قاعده‌های این مجموعه انتخاب می‌کند، `disable` قاعده‌ها را حذف می‌کند و `min_severity` سطح تازه را می‌سنجد. هیچ‌کدام قاعده‌ای بیرون از این مجموعه اضافه نمی‌کند. `max_findings` مثل قبل شمار پیشنهادهای مانده را محدود می‌کند. برای نمونه، `house.quotes: keep` تغییر گیومه را کنار می‌گذارد. `house.ezafe: hamza` املای فرهنگستان را انتخاب می‌کند؛ قاعده‌ی اضافه‌ی آن در این مجموعه نیست. `fix` برای `apply` همین سطح‌ها را به کار می‌برد. `sure` خطاهای دارای پیشنهاد را اصلاح می‌کند، به‌جز `spell.*`. `house` یافته‌های سبکی با یک پیشنهاد را هم اصلاح می‌کند. `all` توصیه‌ها و پیشنهادهای املایی را هم اعمال می‌کند. یافته‌هایی که پیشنهاد اصلاح ندارند، در `left` می‌مانند؛ پیش از تحویل درباره‌شان تصمیم بگیرید. قاعده‌های سه‌نقطه، رقم لاتین و فاصله‌ی نشانه‌گذاری در این مجموعه نیستند. جای خالی فرم‌ها، ایموجی و نقل‌قول انگلیسی باعث شد پیشنهادهای نادرستشان زیاد باشد. انتخاب از قاعده‌های موجود، قاعده‌ای برای گرته‌برداری اضافه نمی‌کند. [شناسه و سطح قاعده‌ها](/docs/agents-en/#rules-in-the-profile) در جدول صفحه‌ی انگلیسی آمده است. ## تعریف ابزارها یکی از دو بلوک `tools` را در درخواست خود بگذارید. هر کدام `ghazal_fix` و `ghazal_check` دارد؛ آرگومان‌هایشان را به `/api/v1/fix` و `/api/v1/check` بفرستید. توضیح‌ها و schema از [OpenAPI](/api/v1/openapi.json) می‌آیند. برای ساختن دوباره‌ی بلوک‌ها، از ریشه‌ی مخزن `python scripts/build_agent_tools.py` را اجرا کنید. ### 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" } } ] } ``` وقتی مدل ابزار را صدا زد، برنامه‌ی شما آرگومان‌ها را به نشانی همان ابزار می‌فرستد و پاسخ را به مدل برمی‌گرداند: ```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) ``` برای همه‌ی فیلدهای دیگر، مثل `only` و `apply`، صفحه‌ی [fix](/docs/fix/) را ببینید. سقف‌ها در [کلید و سقف‌ها](/docs/keys/) است. ## توکن کمتر، و ابزارهای دیگر با `"compact": true` پاسخ `check` و `fix` کوتاه می‌شود: هر پیشنهاد یک سطر، بی `null` و بی فیلدهایی که مدل لازم ندارد. [پاسخ کوتاه](/docs/check/) عاملی که فارسی می‌نویسد این‌ها را هم به کار می‌برد: [`vowels`](/docs/vowels/) برای اعراب واژه‌هایی که چند خوانش دارند، [`verse`](/docs/verse/) برای وزن و قافیه‌ی شعری که می‌نویسد، و [`verb`](/docs/verb/) وقتی از صورت یک فعل مطمئن نیست. نویسه‌ها با Unicode code point شمرده می‌شوند، مثل `len` در Python. خطای سقف روزانه، `left_today` و `reset_at` را دارد: نویسه‌های مانده و زمان شروع روز بعد به وقت UTC. همین مقدارها در `X-RateLimit-Remaining` و `X-RateLimit-Reset` می‌آیند؛ `retry_after` هم مثل `Retry-After` شمار ثانیه‌های انتظار است. متنی کوتاه‌تر ممکن است در سهمیه‌ی مانده جا شود. [سقف‌ها](/docs/keys/) API را از سرور خودتان صدا بزنید و کلید را همان‌جا نگه دارید. API سرآیند CORS نمی‌فرستد؛ فراخوانی بی‌کلید برای سایت، برنامه و افزونه‌ی Word غزل است. توکن‌کاوی و جست‌وجوی پیکره فقط در سایت‌اند؛ نشانی v1 یا ابزار MCP ندارند. متنی که می‌فرستید برای بهتر شدن غزل نگه داشته می‌شود؛ [حریم خصوصی](/privacy/). --- # سرور MCP https://ghazalai.ir/docs/mcp/ > غزل را با MCP به عامل هوش مصنوعی‌تان وصل کنید: نشانی، کلید رایگان، شش ابزار، فایل تنظیمات و سقف‌ها. برنامه‌ها و عامل‌هایی که از MCP پشتیبانی می‌کنند می‌توانند غزل را مستقیم به کار ببرند: نشانی سرور را به عامل بدهید تا فارسی‌اش را پیش از تحویل بررسی و درست کند. سرور همان `fix` و `check` و توضیح قاعده‌ها، و `vowels` و `verse` و `verb` را به شکل شش ابزار می‌دهد. کلید رایگان لازم است؛ در صفحه‌ی [حساب کاربری](/account/) وارد شوید و کلید بسازید. ```text https://ghazalai.ir/mcp ``` سرآیند `Authorization: Bearer gz_...` را بفرستید؛ هر فراخوانی ابزاری که متن می‌گیرد نویسه‌هایش را یک بار از سهمیه‌ی روزانه‌ی حساب خرج می‌کند و `left_today` در پاسخ می‌گوید چه مانده است. `explain_rule` و فهرست ابزارها کلید نمی‌خواهند و چیزی خرج نمی‌کنند. [کلید و سقف‌ها](/docs/keys/) ## افزودن به عامل ابزارهای `check_persian` و `fix_persian` همان شیء [`house`](/docs/check/#تنظیمات-نوشتن) را می‌گیرند: `ezafe`، `digits` و `quotes`. فهرست [`words`](/docs/check/#واژههای-من) هم پذیرفته می‌شود؛ فقط پیشنهادهای `spell.*` و `confuse.*` برای واژه‌های آن پنهان می‌شوند. بیشتر برنامه‌ها سرورها را از یک فایل JSON با کلید `mcpServers` می‌خوانند: ```json { "mcpServers": { "ghazal": { "type": "http", "url": "https://ghazalai.ir/mcp", "headers": {"Authorization": "Bearer gz_..."} } } } ``` در `headers`، به‌جای `gz_...` کلید خودتان را بگذارید. نام و جای این فایل، و جزئیاتی مثل `type`، در هر برنامه کمی فرق می‌کند؛ راهنمای همان برنامه را ببینید. در Claude Code یک فرمان کافی است: ```sh claude mcp add --transport http ghazal https://ghazalai.ir/mcp --header "Authorization: Bearer gz_..." ``` روال کار و آنچه نباید درست شود همان است که در [برای مدل‌های زبانی](/docs/agents/) آمده است. ## ابزارها | ابزار | کار | در API | |---|---|---| | `fix_persian` | متن را درست می‌کند و متن درست‌شده را برمی‌گرداند. | [`fix`](/docs/fix/) | | `check_persian` | بی‌آنکه متن را تغییر دهد، فهرست می‌کند چه چیزی باید درست شود. | [`check`](/docs/check/) | | `explain_rule` | قاعده‌ی پشت یک پیشنهاد را توضیح می‌دهد. | [`rules`](/docs/feedback/) | | `add_vowels` | روی متن اعراب می‌گذارد، جایی که مطمئن است. | [`vowels`](/docs/vowels/) | | `scan_verse` | وزن و قافیه‌ی شعر را می‌خواند و می‌گوید هر مصراع کجا می‌شکند. | [`verse`](/docs/verse/) | | `conjugate_verb` | فعل را تحلیل می‌کند و جدول صرفش را می‌دهد. | [`verb`](/docs/verb/) | `normalize`، `word` و `arabic` ابزار MCP ندارند: عاملی که می‌نویسد به‌جای `normalize` همان `fix_persian` را لازم دارد، املای واژه در `check_persian` هست، و پیدا کردن عبارت‌های عربی کار تحلیل متن است نه نوشتن. این‌ها از API در دسترس‌اند. `fix_persian` و `check_persian` همان فیلدهای API را می‌گیرند: `text`، `format`، `kind`، `style`، `only`، `disable`، `min_severity`، `max_findings` و `compact`؛ `fix_persian` فیلد `apply` را هم می‌گیرد. `add_vowels` فیلدهای `text`، `mode` و `compact` را می‌گیرد، `scan_verse` فیلدهای `text` و `compact` را، و `conjugate_verb` فقط `text` را. `texts` و `offsets` در کار نیست: هر فراخوانی یک متن است و جای پیشنهادها همیشه با code point شمرده می‌شود، مثل اندیس رشته در Python. پاسخ هر ابزار همان پاسخ API است، یک بار در `structuredContent` و یک بار به شکل متن JSON در `content`. ### `fix_persian` ```json {"name": "fix_persian", "arguments": {"text": "او دانش اموز خوبی است و کتاب ها را با دقت میخواند ."}} ``` ```json { "kind": "formal", "text": "او دانش اموز خوبی است و کتاب‌ها را با دقت می‌خواند.", "applied": [ {"start": 24, "end": 31, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 42, "end": 49, "text": "میخواند", "suggestions": ["می‌خواند"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null}, {"start": 49, "end": 50, "text": " ", "suggestions": [""], "rule": "ghazal.punctuation_spacing", "severity": "error", "confidence": null} ], "left": [ {"start": 8, "end": 12, "text": "اموز", "suggestions": ["آموز"], "rule": "spell.typo", "severity": "error", "confidence": null} ], "left_today": 49949 } ``` «اموز» غلط است، ولی پیشنهاد املایی حدسی است درباره‌ی واژه‌ای که نویسنده در نظر داشته؛ برای همین در `left` مانده است. با `"apply": "all"` آن هم اعمال می‌شود. ### `check_persian` ```json {"name": "check_persian", "arguments": {"text": "این کتاب ها را میخوانم و آنها را دوست دارم .", "min_severity": "error", "max_findings": 2}} ``` ```json { "kind": "formal", "register": [0, 3], "findings": [ {"start": 4, "end": 11, "text": "کتاب ها", "suggestions": ["کتاب‌ها"], "rule": "ghazal.plural_space", "severity": "error", "confidence": null}, {"start": 15, "end": 22, "text": "میخوانم", "suggestions": ["می‌خوانم"], "rule": "ghazal.mi_prefix", "severity": "error", "confidence": null} ], "left_today": 49956 } ``` ### `explain_rule` ```json {"name": "explain_rule", "arguments": {"rule": "ghazal.plural_space"}} ``` ```json { "title": "«ها» با فاصله‌ی کامل", "statement": "«ها» و صورت‌های صرفی آن با نیم‌فاصله یا چسبیده نوشته می‌شوند، نه با فاصله‌ی کامل.", "source": null, "example": {"wrong": "کتاب ها", "right": "کتاب‌ها"} } ``` ### `scan_verse` ```json {"name": "scan_verse", "arguments": {"text": "بشنو این نی چون شکایت می‌کند\nاز جدایی‌ها حکایت بسیار می‌کند", "compact": true}} ``` ```json { "metre": "فاعلاتن فاعلاتن فاعلن (رمل مسدس محذوف یا وزن مثنوی)", "pattern": "-u---u---u-", "confidence": 90, "form": "masnavi", "rhyme": ["qafiya «میکند»"], "lines": ["1 fits, licences: 0", "2 breaks at «می‌کند» extra_syllable"], "left_today": 49941 } ``` ## خطاها اگر متن از سقف طرح بلندتر باشد، نویسه‌های امروز کلید تمام شده باشد، فیلدی نادرست باشد، قاعده‌ای با آن شناسه نباشد یا کار بیش از ۹ ثانیه طول بکشد، پاسخ ابزار `isError: true` دارد و `structuredContent` همان خطای API است، با همان `code` و `message`: ```json {"error": {"code": "invalid_request", "message": "rule: Value error, no rule has this id; the ids are in GET /api/v1/rules", "message_fa": "مقدار rule درست نیست.", "request_id": "req_5c0f6b1e2a9d4e37"}} ``` درخواست‌های زیاد (`429`)، سرور پر (`503`)، کلید نادرست یا نفرستادن کلید (`401`) و بدنه‌ی بزرگ‌تر از سقف درخواست (`413`) به شکل خطای JSON-RPC می‌آیند، با همان وضعیت HTTP: `code` خطا همان وضعیت است و `data` همان خطای API. با `429` و `503` به اندازه‌ی `Retry-After` ثانیه صبر کنید. پیام خطا متن شما را تکرار نمی‌کند. [خطاها](/docs/errors/) ابزاری که متن می‌گیرد، بدون کلید `401` می‌دهد و `data.code` برابر `key_required` است. پس از ورود، در صفحه‌ی [حساب کاربری](/account/) کلید رایگان بسازید و در تنظیمات عامل بگذارید. برای سند بلند، `from` و `checked_to` همان‌اند که در API: [سند بلند](/docs/keys/#سند-بلند). ## سقف‌ها و نسخه‌ها سقف‌ها همان سقف‌های API است: برای هر حساب تا ۱۲۰ درخواست پشت سر هم و پس از آن حدود ۵ در ثانیه و ۳ درخواست هم‌زمان؛ متن رایگان تا ۲۰٬۰۰۰ نویسه و متن با کلید طرح شخصی یا بسته تا ۲۰۰٬۰۰۰ نویسه. سهمیه‌ی روزانه به طرح حساب بستگی دارد. هر پیام MCP، حتی فهرست ابزارها، یک درخواست به شمار می‌آید. سرور نسخه‌ی `2026-07-28` پروتکل را پیاده می‌کند، و برای برنامه‌هایی که با `initialize` شروع می‌کنند `2025-11-25` و `2025-06-18` را. هر درخواست یک پاسخ JSON می‌گیرد؛ نشست و SSE ندارد. `GET` و `DELETE` روی این نشانی `405` می‌گیرند. متنی که می‌فرستید برای بهتر شدن غزل نگه داشته می‌شود؛ [حریم خصوصی](/privacy/). --- # 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 /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": "", "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. ### 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" } } ] } ``` 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).