# Run OCR
URL: https://docs.munito.ai/api/createOcr

POST /ocr

Document-AI workload: send a handwritten, scanned, or printed document (PDF or image) by URL or as base64, and get page Markdown back. Optional document annotations return validated JSON. The flat OCR page price includes annotations.

```json
{
  "operationId": "createOcr",
  "summary": "Run OCR",
  "tags": [
    "OCR"
  ],
  "description": "Document-AI workload: send a handwritten, scanned, or printed document (PDF or image) by URL or as base64, and get page Markdown back. Optional document annotations return validated JSON. The flat OCR page price includes annotations.",
  "parameters": [
    {
      "name": "munito-service-tier",
      "in": "header",
      "description": "priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit. See [Service tiers](https://docs.munito.ai/service-tiers).",
      "schema": {
        "type": "string",
        "enum": [
          "priority",
          "standard",
          "flex"
        ],
        "default": "standard"
      }
    },
    {
      "name": "prefer",
      "in": "header",
      "description": "`respond-async`: answer 202 at once. Then poll the `location` until the request finishes.",
      "schema": {
        "type": "string",
        "enum": [
          "respond-async"
        ]
      }
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "document"
          ],
          "additionalProperties": false,
          "properties": {
            "document": {
              "type": "object",
              "required": [
                "type"
              ],
              "additionalProperties": false,
              "description": "The document to read, by `url` or as `base64` data.",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "url",
                    "base64"
                  ]
                },
                "url": {
                  "type": "string",
                  "description": "The document URL, when `type` is `url`. Use a public https URL on port 443. The API follows up to 3 redirects to such URLs."
                },
                "data": {
                  "type": "string",
                  "description": "The document as base64, when `type` is `base64`."
                },
                "filename": {
                  "type": "string",
                  "description": "The file name. Optional. Munito AI reads the format from the bytes of the document."
                }
              }
            },
            "model": {
              "type": "string",
              "description": "An OCR model id from GET /models. Omit it, or send `munito/ocr-auto`, to let Munito pick."
            },
            "pages": {
              "type": "array",
              "items": {
                "type": "integer"
              },
              "description": "Zero-based page numbers to read, each one time, at most 1000. A negative or repeated number, or a number past the last page, answers 422. Omit it to read every page."
            },
            "tables": {
              "type": "object",
              "additionalProperties": false,
              "description": "How to return each table.",
              "properties": {
                "mode": {
                  "type": "string",
                  "enum": [
                    "inline",
                    "extracted"
                  ],
                  "default": "inline",
                  "description": "`inline` keeps each table in the page text. `extracted` moves it to `tables`."
                },
                "format": {
                  "type": "string",
                  "enum": [
                    "markdown",
                    "html"
                  ],
                  "default": "markdown"
                }
              }
            },
            "images": {
              "type": "object",
              "additionalProperties": false,
              "description": "How to return each image on a page.",
              "properties": {
                "annotate": {
                  "type": "boolean",
                  "default": false,
                  "description": "Read the text of each image into `alt_text`."
                },
                "include_base64": {
                  "type": "boolean",
                  "default": false,
                  "description": "Include each image as base64."
                },
                "limit": {
                  "type": "integer",
                  "default": 10,
                  "description": "The maximum number of images on each page."
                },
                "min_size": {
                  "type": "integer",
                  "default": 64,
                  "description": "Ignore an image smaller than this number of pixels on either side."
                }
              }
            },
            "confidence_scores": {
              "type": "boolean",
              "default": false,
              "description": "Return a confidence per page."
            },
            "extract": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "header",
                  "footer",
                  "page_number",
                  "aside"
                ]
              },
              "description": "Page parts to move from the page text into their own fields."
            },
            "document_annotation_format": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "type"
              ],
              "description": "Extract one annotation from all selected pages. Use json_schema for schema-validated JSON, or json_object for a JSON object. The response contains document_annotation as a JSON string. Requires an available fast model in the permitted region.",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "json_schema",
                    "json_object"
                  ]
                },
                "json_schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "schema"
                  ],
                  "description": "Required for json_schema; omit for json_object. The schema must fit within 64 KiB and use local references only.",
                  "properties": {
                    "name": {
                      "type": "string",
                      "default": "document_annotation",
                      "pattern": "^[a-zA-Z0-9_-]{1,64}$"
                    },
                    "schema": {
                      "type": "object",
                      "additionalProperties": true
                    },
                    "description": {
                      "type": "string",
                      "maxLength": 8000
                    },
                    "strict": {
                      "type": "boolean",
                      "enum": [
                        true
                      ],
                      "default": true
                    }
                  }
                }
              }
            },
            "document_annotation_prompt": {
              "type": "string",
              "maxLength": 8000,
              "description": "Instructions for document annotation. Requires document_annotation_format."
            },
            "preferred_region": {
              "type": "string",
              "enum": [
                "global",
                "eu",
                "us"
              ],
              "description": "Where the request can run. Omit it to use the default region of the organization."
            }
          }
        },
        "example": {
          "document": {
            "type": "url",
            "url": "https://example.com/invoice.pdf"
          },
          "model": "lightonai/lightonocr-3-4b"
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "The OCR result, when the request finishes within the synchronous wait.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "pages": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "document_annotation": {
                "type": "string",
                "description": "A JSON string that matches the requested annotation format. Present only when requested."
              },
              "usage": {
                "type": "object",
                "properties": {
                  "cost_usd": {
                    "type": "number",
                    "description": "Estimated cost of the OCR pages. Document annotation adds no charge."
                  }
                }
              }
            }
          }
        }
      },
      "headers": {
        "x-request-id": {
          "description": "The id that Munito makes for each request. Quote it to support. OpenAI sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "munito-region": {
          "description": "The jurisdiction that served the request.",
          "schema": {
            "type": "string"
          }
        },
        "munito-service-tier": {
          "description": "priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-over-limit": {
          "description": "yes when the request exceeded a rate limit and ran on spare capacity: a free seat of its own tier, or the flex band for background work and OCR. Fireworks sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-pages": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-pages": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-pages": {
          "description": "",
          "schema": {
            "type": "string"
          }
        }
      }
    },
    "202": {
      "description": "Accepted. Poll the `location` until the request finishes.",
      "headers": {
        "x-request-id": {
          "description": "The id that Munito makes for each request. Quote it to support. OpenAI sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "munito-region": {
          "description": "The jurisdiction that served the request.",
          "schema": {
            "type": "string"
          }
        },
        "munito-service-tier": {
          "description": "priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-over-limit": {
          "description": "yes when the request exceeded a rate limit and ran on spare capacity: a free seat of its own tier, or the flex band for background work and OCR. Fireworks sends the same header.",
          "schema": {
            "type": "string"
          }
        },
        "location": {
          "description": "Where the result or the redirect target is.",
          "schema": {
            "type": "string"
          }
        },
        "preference-applied": {
          "description": "RFC 7240: the preference that the server applied.",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-requests": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-limit-pages": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-remaining-pages": {
          "description": "",
          "schema": {
            "type": "string"
          }
        },
        "x-ratelimit-reset-pages": {
          "description": "",
          "schema": {
            "type": "string"
          }
        }
      }
    }
  }
}
```

# Shared API schemas
{
  "securitySchemes": {
    "BearerAuth": {
      "type": "http",
      "scheme": "bearer",
      "description": "Your Munito API key."
    },
    "ApiKeyAuth": {
      "type": "apiKey",
      "in": "header",
      "name": "x-api-key",
      "description": "Your Munito API key."
    }
  }
}