AIVAX

Extraction

Use Extraction to turn text, images, and PDFs into JSON shaped by a schema you define. It fits invoices, receipts, forms, contracts, and other documents where your application needs the same fields from every document, such as a number, a company name, a total, or a list of line items.

Before calling this endpoint, create an API key and make sure the account has a positive balance.

Extraction, Fetch, or Media Descriptions #

These three services read documents, but they return different things:

ExtractionFetch and OCRMedia Descriptions
Main purposeFind specific fields in each document and return them as JSON.Retrieve the readable text of web pages and documents, using OCR when needed.Interpret media with AI and return a text description guided by your instructions.
InputText, JPEG, PNG, TIFF, and PDF content.Web pages and many document formats, including Office files, spreadsheets, and e-books.Images, PDFs, audio, and video.
OutputOne JSON object per document, shaped by your schema.Extracted text, plus optional JSON converted from that text.Generated text.
BillingInput tokens only.Processing units with daily plan allowances; JSON conversion is billed separately.AI usage charges for input and output.

Choose Extraction when you already know which fields you need and want them read directly from the document. Choose Fetch when you need the document’s full text, for example to index it or to read a web page. Choose Media Descriptions when you need an explanation of visual or audiovisual content, such as a chart, a photo, or a video, rather than specific fields.

For a request pattern that keeps a failed document from costing the rest, see extract structured data from a PDF, one document per request.

Endpoint #

POST /api/v1/generations/extract

Build the request #

PropertyTypeRequiredDescription
responseSchemaJSON Schema objectYesObject schema whose properties describe the fields to extract. It must have at least one property.
documentsContent part arrayYesOne or more documents as OpenAI-compatible content parts: text, image_url, or file.
instructionsStringNoGuidance that applies to every document, such as which party counts as the vendor.

Each property in responseSchema is one field to find. Its description is the search criterion, so write it as a short, specific definition, such as “total amount due” instead of “total”. Nested objects and arrays of objects are supported. $ref and $defs are not; inline every definition instead.

Images and files accept base64 data URLs or public HTTP(S) URLs:

  • Supported formats are JPEG, PNG, TIFF, and PDF, including multi-page PDFs.
  • The resource must be reachable without sign-in.
  • Other content types, such as audio or video, return 400 Bad Request.

The following request extracts invoice fields from a text document and a PDF:

JSON
{
  "instructions": "Only consider the issuing company as the vendor.",
  "responseSchema": {
    "type": "object",
    "properties": {
      "invoice_number": { "type": "string", "description": "invoice number" },
      "vendor": { "type": "string", "description": "company that issued the invoice" },
      "total": { "type": "number", "description": "total amount due" },
      "line_items": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "product": { "type": "string", "description": "product name" },
            "quantity": { "type": "integer", "description": "number of units" }
          }
        }
      }
    }
  },
  "documents": [
    {
      "type": "text",
      "text": "Invoice 1042 from Acme Corp. 2 x Widget at $10.00. Total: 20.00 USD."
    },
    {
      "type": "file",
      "file": {
        "filename": "invoice.pdf",
        "file_data": "https://example.com/invoice.pdf"
      }
    }
  ]
}

Read the response #

data contains one object per document, in the same order as documents. Each object uses the property names from your schema. A field that is not found is null, and an array with no matches is empty.

JSON
{
  "message": null,
  "data": [
    {
      "invoice_number": "1042",
      "vendor": "Acme Corp",
      "total": 20,
      "line_items": [
        { "product": "Widget", "quantity": 2 }
      ]
    }
  ]
}

Documents are processed independently. If any document fails, the whole request returns an error instead of partial results. Documents that finished before the failure are still billed and count toward your quota, so fix or remove the failing document before retrying.

Extracted values are model-generated. Verify consequential values, such as amounts and identifiers, against the original document.

Async generation #

Add "async": true to queue the extraction. The API answers with HTTP 202 and an ID, and you fetch the stored result later or receive a webhook when it is done. See Async generations.

JSON
{
  "schema": {
    "type": "object",
    "properties": {
      "total": { "type": "number", "description": "invoice total" }
    }
  },
  "documents": [
    { "type": "text", "text": "Invoice 1042 from Acme Corp. Total: 20.00 USD." }
  ],
  "async": true
}

Pricing and limits #

Extraction is billed for the input tokens of each document. Output tokens are not billed.

DescriptionPricing
Extraction input$0.04/M tokens

Extraction and Summarization share the same document limits. Remote files are limited to 5 MB each. The number of processed documents per minute and per day depends on the plan; see Data processing limits.

The quota counts every item in the request’s documents array, not each HTTP request. A request that would exceed any active window returns 429 Too Many Requests.

The embedded API reference contains the server-maintained request, response, authentication, and error details:

Type to search the documentation.