{
  "openapi": "3.1.0",
  "info": {
    "title": "OCR-AI Arabic API",
    "version": "1",
    "description": "Read Arabic documents and transcribe Arabic speech. One unit reads one page or transcribes one started minute; an account's first key comes with 50 free units. Packs: 100 units $9, 500 units $29, 2000 units $89. The same tools over MCP: https://ocr-ai.com/ar/mcp. Reference: https://ocr-ai.com/ar/docs.md.",
    "contact": {
      "email": "hello@ocr-ai.com",
      "url": "https://ocr-ai.com/ar/developers"
    },
    "termsOfService": "https://ocr-ai.com/ar/terms"
  },
  "servers": [
    {
      "url": "https://ocr-ai.com"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/ar/api/v1/read": {
      "post": {
        "operationId": "readDocument",
        "summary": "Read a document",
        "description": "A PDF or an image (application/pdf, image/jpeg, image/png, image/webp) up to 20 MB in; its pages as text, fields and tables out. Up to 20 pages per call: read longer PDFs in ranges with \"pages\" and follow next_pages. Send multipart (field \"file\"), JSON (file_base64 or file_url), or the raw file with its own Content-Type and the options in the query string.",
        "parameters": [
          {
            "name": "pages",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "description": "PDF pages to read, for example \"1-5,8\". Default: from page 1, up to the per-call limit."
            },
            "description": "With a raw file body only."
          },
          {
            "name": "hint",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "auto",
                "invoice",
                "receipt",
                "card",
                "table",
                "text",
                "handwriting"
              ],
              "description": "What the document is, if known (handwriting: a handwritten page). Default: auto."
            },
            "description": "With a raw file body only."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "contentMediaType": "application/octet-stream"
                  },
                  "pages": {
                    "type": "string",
                    "description": "PDF pages to read, for example \"1-5,8\". Default: from page 1, up to the per-call limit."
                  },
                  "hint": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "invoice",
                      "receipt",
                      "card",
                      "table",
                      "text",
                      "handwriting"
                    ],
                    "description": "What the document is, if known (handwriting: a handwritten page). Default: auto."
                  }
                },
                "required": [
                  "file"
                ]
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "file_url": {
                    "type": "string",
                    "description": "A public https URL of the document. Use this or file_base64."
                  },
                  "file_base64": {
                    "type": "string",
                    "description": "The document's bytes, base64-encoded. Use this or file_url."
                  },
                  "pages": {
                    "type": "string",
                    "description": "PDF pages to read, for example \"1-5,8\". Default: from page 1, up to the per-call limit."
                  },
                  "hint": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "invoice",
                      "receipt",
                      "card",
                      "table",
                      "text",
                      "handwriting"
                    ],
                    "description": "What the document is, if known (handwriting: a handwritten page). Default: auto."
                  }
                },
                "additionalProperties": false
              }
            },
            "application/pdf": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/octet-stream"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/octet-stream"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/octet-stream"
              }
            },
            "image/webp": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/octet-stream"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The pages, in page order.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Document"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "402": {
            "$ref": "#/components/responses/E402"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "415": {
            "$ref": "#/components/responses/E415"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          }
        }
      }
    },
    "/ar/api/v1/transcribe": {
      "post": {
        "operationId": "transcribeAudio",
        "summary": "Transcribe a recording",
        "description": "A recording in (audio/wav or audio/ogg: 16-bit PCM WAV, or Ogg Opus such as a WhatsApp voice note), up to 10 minutes per call; its transcript out. Units for the whole recording are taken before the answer starts and given back if it fails or holds no speech. A silent or near-silent WAV is recognized before reading. An Ogg Opus file cannot be measured on the server, so one that holds only silence or room noise is read like any other and the engine may write words for it: send Ogg Opus only when it holds speech. Send multipart (field \"file\"), JSON (file_base64 or file_url), or the raw file with the task in the query string.",
        "parameters": [
          {
            "name": "task",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "transcript",
                "summary",
                "order"
              ],
              "description": "transcript (default): the words, with timestamps and speakers. summary: also a short summary and action items. order: also each thing the speaker asks for, with quantity and details."
            },
            "description": "With a raw file body only."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "contentMediaType": "application/octet-stream"
                  },
                  "task": {
                    "type": "string",
                    "enum": [
                      "transcript",
                      "summary",
                      "order"
                    ],
                    "description": "transcript (default): the words, with timestamps and speakers. summary: also a short summary and action items. order: also each thing the speaker asks for, with quantity and details."
                  }
                },
                "required": [
                  "file"
                ]
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "file_url": {
                    "type": "string",
                    "description": "A public https URL of the recording. Use this or file_base64."
                  },
                  "file_base64": {
                    "type": "string",
                    "description": "The recording's bytes, base64-encoded. Use this or file_url."
                  },
                  "task": {
                    "type": "string",
                    "enum": [
                      "transcript",
                      "summary",
                      "order"
                    ],
                    "description": "transcript (default): the words, with timestamps and speakers. summary: also a short summary and action items. order: also each thing the speaker asks for, with quantity and details."
                  }
                },
                "additionalProperties": false
              }
            },
            "audio/wav": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/octet-stream"
              }
            },
            "audio/ogg": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/octet-stream"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The transcript.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Transcript"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "402": {
            "$ref": "#/components/responses/E402"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "415": {
            "$ref": "#/components/responses/E415"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "503": {
            "$ref": "#/components/responses/E503"
          }
        }
      }
    },
    "/ar/api/v1/balance": {
      "get": {
        "operationId": "checkBalance",
        "summary": "Units left, and where to add more",
        "responses": {
          "200": {
            "description": "The key's balance.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "An API key, ocrar_sk_…, created at https://ocr-ai.com/ar/account."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "A stable code, for example unauthorized, payment_required, too_large."
          },
          "message": {
            "type": "string",
            "description": "A sentence an agent can relay to its user."
          },
          "buy_url": {
            "type": "string",
            "description": "402 only: the page where the key's owner adds units."
          },
          "needed": {
            "type": "integer",
            "description": "402 only: the units this call needs."
          },
          "balance": {
            "type": "integer",
            "description": "402 only: the units the key's account has."
          },
          "packs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Pack"
            },
            "description": "402 only: the packs on offer, each with its own buy link."
          },
          "get_key_url": {
            "type": "string",
            "description": "401 without a key: where to get one."
          }
        },
        "required": [
          "error",
          "message"
        ]
      },
      "Pack": {
        "type": "object",
        "properties": {
          "pack": {
            "type": "string",
            "enum": [
              "p100",
              "p500",
              "p2000"
            ]
          },
          "units": {
            "type": "integer"
          },
          "price": {
            "type": "number"
          },
          "currency": {
            "const": "USD"
          },
          "buy_url": {
            "type": "string",
            "description": "The page where a person buys this pack."
          }
        },
        "required": [
          "pack",
          "units",
          "price",
          "currency",
          "buy_url"
        ]
      },
      "Field": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "description": "A stable name, for example total, invoice_date, vat_number."
          },
          "label": {
            "type": "string",
            "description": "The label as printed on the document."
          },
          "value": {
            "type": "string",
            "description": "The value as written, Arabic-Indic digits kept. A word the engine was unsure of is written between ⟦ and ⟧ with its best reading inside; ⟦…⟧ is a word it could not read. Strip the brackets for display."
          },
          "normalized": {
            "type": "string",
            "description": "The value for computation, when it has one: 1250.00, 2026-11-07."
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "date",
              "money",
              "number",
              "percent",
              "id",
              "phone",
              "email",
              "address"
            ]
          },
          "uncertain": {
            "type": "boolean",
            "description": "True when the engine marked the value as hard to read. A hint, not a guarantee: a misread digit is often not marked, so compare identifiers (tax and invoice numbers) and amounts with the original wherever they matter."
          },
          "box": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000
            },
            "minItems": 4,
            "maxItems": 4,
            "description": "[ymin, xmin, ymax, xmax], each 0 to 1000, relative to the page image."
          }
        },
        "required": [
          "key",
          "label",
          "value",
          "type"
        ]
      },
      "Table": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "description": "One array of cells per row, in column order. A word the engine was unsure of is written between ⟦ and ⟧ with its best reading inside; ⟦…⟧ is a word it could not read. Strip the brackets for display."
          },
          "box": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000
            },
            "minItems": 4,
            "maxItems": 4,
            "description": "[ymin, xmin, ymax, xmax], each 0 to 1000, relative to the page image."
          }
        },
        "required": [
          "columns",
          "rows"
        ]
      },
      "PageRead": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "description": "The page number in the file, from 1."
          },
          "status": {
            "const": "done"
          },
          "partial": {
            "type": "boolean",
            "description": "True when the reading was cut off before the page's end."
          },
          "document_type": {
            "type": "string",
            "enum": [
              "invoice",
              "receipt",
              "purchase_order",
              "delivery_note",
              "quote",
              "bank_statement",
              "payslip",
              "id_document",
              "business_card",
              "contract",
              "letter",
              "form",
              "table",
              "other"
            ]
          },
          "language": {
            "type": "string",
            "enum": [
              "ar",
              "en",
              "mixed",
              "other"
            ]
          },
          "summary": {
            "type": "string"
          },
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Field"
            }
          },
          "tables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Table"
            }
          },
          "text": {
            "type": "string",
            "description": "The page's full text, in reading order. A word the engine was unsure of is written between ⟦ and ⟧ with its best reading inside; ⟦…⟧ is a word it could not read. Strip the brackets for display."
          }
        },
        "required": [
          "page",
          "status",
          "partial",
          "document_type",
          "language",
          "summary",
          "fields",
          "tables",
          "text"
        ]
      },
      "PageFailed": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer"
          },
          "status": {
            "const": "failed"
          },
          "error": {
            "type": "string"
          },
          "refunded": {
            "const": true
          }
        },
        "required": [
          "page",
          "status",
          "error",
          "refunded"
        ]
      },
      "PageNotCovered": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer"
          },
          "status": {
            "const": "no_pages",
            "description": "The balance ran out before this page."
          }
        },
        "required": [
          "page",
          "status"
        ]
      },
      "Document": {
        "type": "object",
        "properties": {
          "object": {
            "const": "document"
          },
          "total_pages": {
            "type": "integer",
            "description": "Pages in the file."
          },
          "pages_read": {
            "type": "integer",
            "description": "Pages read in this call."
          },
          "pages_charged": {
            "type": "integer",
            "description": "Units taken: one per page read. Failed pages are not charged."
          },
          "balance": {
            "type": "integer",
            "description": "Units left on the key's account."
          },
          "next_pages": {
            "type": [
              "string",
              "null"
            ],
            "description": "The pages still to read (send them as \"pages\" in the next call), or null."
          },
          "buy_url": {
            "type": "string",
            "description": "Present when the balance ran out: the page where the key's owner adds units."
          },
          "pages": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/PageRead"
                },
                {
                  "$ref": "#/components/schemas/PageFailed"
                },
                {
                  "$ref": "#/components/schemas/PageNotCovered"
                }
              ]
            }
          }
        },
        "required": [
          "object",
          "total_pages",
          "pages_read",
          "pages_charged",
          "balance",
          "next_pages",
          "pages"
        ]
      },
      "Transcript": {
        "type": "object",
        "properties": {
          "object": {
            "const": "transcript"
          },
          "status": {
            "type": "string",
            "enum": [
              "done",
              "failed"
            ]
          },
          "partial": {
            "type": "boolean"
          },
          "seconds": {
            "type": "number",
            "description": "The recording's length."
          },
          "units_charged": {
            "type": "integer",
            "description": "One unit per started minute; 0 when the transcription failed or heard no speech."
          },
          "balance": {
            "type": "integer",
            "description": "Units left on the key's account."
          },
          "buy_url": {
            "type": "string",
            "description": "Present when the balance is 0."
          },
          "error": {
            "type": "string",
            "description": "When status is \"failed\": the reason, for example no_speech. Nothing was charged."
          },
          "refunded": {
            "const": true
          },
          "language": {
            "type": "string",
            "enum": [
              "ar",
              "en",
              "mixed",
              "other"
            ]
          },
          "dialect": {
            "type": "string",
            "enum": [
              "msa",
              "gulf",
              "egyptian",
              "levantine",
              "iraqi",
              "maghrebi",
              "sudanese",
              "yemeni",
              "mixed",
              "other"
            ],
            "description": "Speech is written as spoken, in its dialect, never translated."
          },
          "summary": {
            "type": "string"
          },
          "segments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "start": {
                  "type": "string",
                  "description": "\"MM:SS\" from the start of the recording."
                },
                "speaker": {
                  "type": "string",
                  "description": "\"المتحدث 1\", \"المتحدث 2\" and so on when more than one person speaks; empty otherwise."
                },
                "text": {
                  "type": "string",
                  "description": "A word the engine was unsure of is written between ⟦ and ⟧ with its best reading inside; ⟦…⟧ is a word it could not read. Strip the brackets for display."
                }
              },
              "required": [
                "start",
                "speaker",
                "text"
              ]
            }
          },
          "requests": {
            "type": "array",
            "description": "task \"order\": each thing the speaker asks for.",
            "items": {
              "type": "object",
              "properties": {
                "item": {
                  "type": "string"
                },
                "quantity": {
                  "type": "string"
                },
                "details": {
                  "type": "string"
                }
              },
              "required": [
                "item",
                "quantity",
                "details"
              ]
            }
          },
          "action_items": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "object",
          "status",
          "seconds",
          "units_charged",
          "balance"
        ]
      },
      "Balance": {
        "type": "object",
        "properties": {
          "object": {
            "const": "balance"
          },
          "balance": {
            "type": "integer",
            "description": "Units left."
          },
          "expired": {
            "type": "boolean",
            "description": "True when the account's units passed their validity (365 days from the last purchase)."
          },
          "key": {
            "type": "string",
            "description": "The key's id."
          },
          "buy_url": {
            "type": "string",
            "description": "The page where the key's owner adds units. Calling the API never charges anything."
          },
          "packs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Pack"
            }
          }
        },
        "required": [
          "object",
          "balance",
          "key",
          "buy_url",
          "packs"
        ]
      }
    },
    "responses": {
      "E400": {
        "description": "The request is malformed: bad_request, missing_file, bad_pages, bad_base64, bad_url, too_short.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E401": {
        "description": "No API key, or a key that is unknown or revoked. Send \"Authorization: Bearer ocrar_sk_…\".",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E402": {
        "description": "payment_required: the account has fewer units than the call needs. Nothing was charged; buy_url and packs say where to add units.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E413": {
        "description": "too_large (a file over 20 MB) or too_long (a recording over 10 minutes).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E415": {
        "description": "unsupported_type: the body or the file is not a type this endpoint reads.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E422": {
        "description": "The file was received but cannot be read: fetch_failed, too_many_pages, unreadable_pdf.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E429": {
        "description": "rate_limited: too many calls in the last minute. Wait a minute and retry.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E503": {
        "description": "engine_unavailable: reading or transcription is not available right now. Nothing was charged.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
