Rules for AI agents
Instructions for an AI agent (or any automated client) that calls this API for a user. Every paid call spends the user's real money (Fara). Follow these rules exactly.
At a glance#
- Read first: this page, then Conventions, then the guide for the task (see the table on the overview).
- Machine-readable: OpenAPI, error catalog, all docs as one Markdown file.
- Branch on the error
code, never on the humandetailtext.
Getting access#
The user only needs an account with Fara on https://faraatarjomeh.com (new accounts get a sign-up gift). Then, in this order of preference:
- You speak MCP (Claude, ChatGPT, Cursor, Claude Code and others): connect to
https://faraatarjomeh.com/api/v1/mcp. The user signs in in the browser, picks a spending limit for you (500 Fara is suggested; it counts over the whole connection) and allows you; nothing to copy. See AI assistants (MCP). - Any other agent or script: sign in with a code. POST to
https://faraatarjomeh.com/api/v1/oauth/device, show the user the code and link, pollhttps://faraatarjomeh.com/api/v1/oauth/token, and you get your own key with the monthly limit the user chose. See Sign an agent in with a code. - The user already has a key: use it as
Authorization: Bearer fara_sk_....
Files: send a public https link (fileUrl for documents, audioUrl for recordings); you never need a multipart upload.
Spending rules#
- Price before spending. Get the price first (analysis, estimate, or pricing endpoint — each guide names it). Never start paid work without a price.
- Stay inside the approved budget. Only spend what the user approved for this task. If the price is above that, stop and ask the user. If the user gave no budget, ask before the first paid call.
- Check the balance.
GET /api/v1/account→credits.balanceis what can be spent now. If the price is more than the balance, tell the user to top up at https://faraatarjomeh.com; an API key cannot buy Fara. - One job per intent. Send a fresh
Idempotency-Key(a UUID) with every POST that can spend Fara, store it with the task, and reuse the same key on every retry of that POST. A retry with the same key returns the first answer and never charges twice. Never create a second job to "retry" a job that is still running. - Paid calls in the reference are marked
x-spends-fara: truein the OpenAPI document and "spends Fara" in the reference. - Account for what was spent. The real cost of a job is the sum of
balanceChangeover its ledger rows:GET /api/v1/account/transactions?jobId={jobId}(see Billing). Report it to the user.
Waiting rules#
- Prefer webhooks if you have a public https endpoint (Webhooks). Otherwise poll.
- Polling intervals: first check after 10 s, then back off to every 30–60 s. Never poll faster than every 5 s per job.
- Unknown status values: treat them as "still running". Only the terminal statuses listed in each guide's state machine end a job.
- Review statuses (
awaiting_review): the job waits for a decision. Approve automatically only if the user told you to; otherwise show the user what to review and wait.
Error rules#
Every error is application/problem+json with a stable code. Look the code up in the error catalog and follow its retry rule:
retry |
What to do |
|---|---|
do_not_retry |
Stop. Fix what the error names (or ask the user if needsUser is true). Sending it again fails the same way. |
refresh_then_retry |
GET the resource again, rebuild the request from the fresh data, send it once more. |
retry_later |
Send the same request with the same Idempotency-Key after Retry-After seconds, or back off 2 s, 4 s, 8 s … up to 5 minutes. Give up after about 30 minutes and tell the user. |
check_then_retry |
500/502/504: the work may have happened and this answer is replayed for the same key. List the jobs (or the ledger) to see if it happened. Only if not, send again with a new Idempotency-Key. |
wait |
Send nothing. The job already runs; poll it. |
Special cases:
402 INSUFFICIENT_CREDITS— stop and tell the user the price and the balance (the body hasbalanceandestimatedCost,costorrequired). Give the usertopUpUrlfrom the body: the website page where they add Fara (it suggests a pack that coversshortfall). An API key cannot buy Fara. After they pay, send the same request again.402 SPEND_LIMIT_REACHED— the key's own limit, not the balance. Give the account ownerlimitsUrlto raise it.429 RATE_LIMITED— waitRetry-Afterseconds. Read theRateLimitheader to slow down before you hit the limit.- Network error or timeout on a POST — resend it with the same
Idempotency-Key. You get the stored first answer or409 IDEMPOTENCY_KEY_IN_USE(wait and resend).
Safety rules#
- The API key is a secret with access to the user's money. Never print it, log it, put it in a URL, or send it to any host other than
https://faraatarjomeh.com. - Never send the key from a browser or a mobile app; only from a server or a local script.
- Files you upload and results you download belong to the user. Do not share them elsewhere unless the user asked.
- Deleting a result (
DELETEcalls) cannot be undone. Only delete when the user asked.