> ## Documentation Index
> Fetch the complete documentation index at: https://venator-06aff335.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Document Extraction

Extract structured data from documents using AI-powered OCR and layout understanding. Supports multi-page documents and returns page-level extracted fields, classification, and confidence scores.

<div
  style={{
display: "inline-flex",
alignItems: "center",
background: "#fff",
borderRadius: "12px",
padding: "16px 24px",
border: "1px solid #e5e7eb",
boxShadow: "0 1px 3px rgba(0,0,0,0.05)",
fontFamily: "monospace",
gap: "16px"
}}
>
  <span
    style={{
color: "#2563eb",
fontWeight: "700",
fontSize: "18px",
letterSpacing: "0.5px"
}}
  >
    POST
  </span>

  <span
    style={{
fontSize: "14px",
color: "#4b5563"
}}
  >
    /api/gw/services/document\_extraction
  </span>
</div>

***

### Authorizations

<ResponseField name="x-api-key" type="string" required>
  API key used to authenticate requests.
</ResponseField>

***

### Body

<ResponseField name="imageBase64" type="string" required>
  Base64 encoded document image or file.
</ResponseField>

<ResponseField name="filename" type="string">
  Original filename of the document.
</ResponseField>

***

### Response

<Tabs>
  <Tab title="200">
    <ResponseField name="success" type="boolean">
      Indicates whether the request was processed successfully.
    </ResponseField>

    <ResponseField name="requestId" type="string">
      Unique identifier for the API request.
    </ResponseField>

    <ResponseField name="correlationId" type="string">
      Identifier used for tracing the request across systems.
    </ResponseField>

    <ResponseField name="data" type="object">
      Contains OCR processing results and metadata.
    </ResponseField>

    <ResponseField name="data.pages" type="number">
      Total number of processed pages.
    </ResponseField>

    <ResponseField name="data.ocrTotalMs" type="number">
      Total OCR processing time in milliseconds.
    </ResponseField>

    <ResponseField name="data.artifactsId" type="string">
      Identifier for stored artifacts/results.
    </ResponseField>

    <ResponseField name="data.results" type="array">
      List of extracted page-level results.
    </ResponseField>

    <ResponseField name="data.results[].pageIndex" type="number">
      Index of the processed page.
    </ResponseField>

    <ResponseField name="data.results[].status" type="string">
      Processing status of the page (e.g., SUCCESS, FAILED).
    </ResponseField>

    <ResponseField name="data.results[].docType" type="string">
      Detected document type (e.g., INVOICE).
    </ResponseField>

    <ResponseField name="data.results[].docSide" type="string">
      Document side processed (e.g., FRONT, BACK).
    </ResponseField>

    <ResponseField name="data.results[].fields" type="object">
      Key-value pairs of extracted fields (e.g., invoice\_number, total\_amount).
    </ResponseField>

    <ResponseField name="data.results[].confidence" type="number">
      Confidence score for the extracted data (0 to 1).
    </ResponseField>

    <ResponseField name="data.results[].warnings" type="array">
      List of warnings encountered during processing.
    </ResponseField>

    <ResponseField name="data.results[].pageImages" type="string">
      Base64 or reference string for the processed page image.
    </ResponseField>

    <ResponseField name="data.failureReason" type="string">
      Reason for failure if processing was not successful.
    </ResponseField>

    <ResponseField name="error" type="object | null">
      Contains error details if the request fails; otherwise null.
    </ResponseField>

    <ResponseField name="durationMs" type="number">
      Time taken to process the request in milliseconds.
    </ResponseField>

    <ResponseField name="processedAt" type="string">
      Timestamp when the request was processed (ISO 8601 format).
    </ResponseField>
  </Tab>
</Tabs>

***

<RequestExample>
  ```bash Curl theme={null}
  curl -X POST "https://dev-idf-gw.cognetlabs.org/api/gw/services/document_extraction" \
    -H "Content-Type: application/json" \
    -d '{
      "imageBase64": "<base64-document>",
      "filename": "invoice.pdf"
  }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://dev-idf-gw.cognetlabs.org/api/gw/services/document_extraction"

  payload = {
      "imageBase64": "<base64-document>",
      "filename": "invoice.pdf"
  }

  print(requests.post(url, json=payload).json())
  ```

  ```javascript JavaScript theme={null}
  fetch("https://dev-idf-gw.cognetlabs.org/api/gw/services/document_extraction", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      imageBase64: "<base64-document>",
      filename: "invoice.pdf"
    })
  })
  .then(res => res.json())
  .then(console.log);
  ```

  ```php PHP theme={null}
  <?php
  $url = "https://dev-idf-gw.cognetlabs.org/api/gw/services/document_extraction";

  $data = [
    "imageBase64" => "<base64-document>",
    "filename" => "invoice.pdf"
  ];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ?>
  ```

  ```go Go theme={null}
  package main

  import (
    "bytes"
    "net/http"
  )

  func main() {
    json := []byte(`{
      "imageBase64":"<base64-document>",
      "filename":"invoice.pdf"
    }`)

    http.Post(
      "https://dev-idf-gw.cognetlabs.org/api/gw/services/document_extraction",
      "application/json",
      bytes.NewBuffer(json),
    )
  }
  ```

  ```java Java theme={null}
  import okhttp3.*;

  public class Main {
    public static void main(String[] args) throws Exception {

      OkHttpClient client = new OkHttpClient();

      String json = "{\"imageBase64\":\"<base64-document>\", \"filename\":\"invoice.pdf\" }";

      RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));

      Request request = new Request.Builder()
        .url("https://dev-idf-gw.cognetlabs.org/api/gw/services/document_extraction")
        .post(body)
        .build();

      Response response = client.newCall(request).execute();
      System.out.println(response.body().string());
    }
  }
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'uri'
  require 'json'

  uri = URI("https://dev-idf-gw.cognetlabs.org/api/gw/services/document_extraction")

  payload = {
    imageBase64: "<base64-document>",
    filename: "invoice.pdf"
  }

  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri, {'Content-Type': 'application/json'})
  request.body = payload.to_json

  response = http.request(request)
  puts response.body
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
  "success":true,
  "requestId":"909ca3d2fe34",
  "correlationId":"3f1b300063d94ed9a4ea4460a5656c2c",
  "data":{
  "pages":1,
  "ocrTotalMs":320,
  "artifactsId":"art_12345",
  "results":[
  {
  "pageIndex":0,
  "status":"SUCCESS",
  "docType":"INVOICE",
  "docSide":"FRONT",
  "fields":{
  "invoice_number":"12345",
  "total_amount":"450.00"
  },
  "confidence":0.95,
  "warnings":[
  "string",
  "string"
  ],
  "pageImages":"string"
  }
  ],
  "failureReason":"string"
  },
  "error":null,
  "durationMs":274,
  "processedAt":"2026-04-29T13:58:18.7342517Z"
  }
  ```

  ```json 400 theme={null}
  {
      "error": "ImageBase64 is required"
  }
  ```
</ResponseExample>
