Docusure.AIIntelligent Document Workflow

Document Processing API

API Endpoint

POST
/api/resolvesync

Authentication

All API requests require authentication using a Bearer token in the Authorization header:

Authorization: Bearer YOUR_API_KEY
HTTP Header

Request Schema
FieldTypeRequiredDescription
idstring
Required
Unique request identifier for tracking
input.filestring
Required
Base64 encoded document file (PDF, PNG, JPG)
input.corpusNamestring
Required
Name of the corpus to use for processing
input.saveOODToRepositorystring
Optional
Repository identifier to save out-of-distribution (unknown) documents
input.metadataobject
Optional
Custom metadata to attach to the request
input.supervisionobject
Optional
Supervision data for training or evaluation
input.useThresholdsboolean
Optional
Enable unknown document detection using similarity thresholds (default: false)
callbackstring
Optional
URL for async callback (webhook)

Response Schema

{
  "status": "OK",
  "requestId": "request-123",
  "timestamp": "2024-01-01T00:00:00.000Z",
  "duration": "2.45",
  "model": "gpt-4-vision",
  "metadata": {},
  "pages": [
    {
      "page": 1,
      "documentType": "Invoice",
      "documentTypeVariant": "Standard",
      "pageLayout": "invoice-standard-page1",
      "attributes": [
        {
          "item": "Invoice Number",
          "text": "INV-2024-001",
          "bbox_2d": [
            100,
            50,
            250,
            70
          ],
          "namedEntity": "invoice_number"
        }
      ],
      "image_height": 1100,
      "image_width": 850,
      "matchInfo": {
        "documentPageId": "layout-123",
        "layoutId": "layout-123",
        "maxSim": 0.95
      },
      "iclExamples": [
        {
          "documentPageId": "doc-456",
          "layoutId": "layout-123",
          "maxSim": 0.93,
          "documentType": "Invoice",
          "documentTypeVariant": "Standard",
          "pageLayout": "invoice-standard-page1"
        },
        {
          "documentPageId": "doc-789",
          "layoutId": "layout-123",
          "maxSim": 0.91,
          "documentType": "Invoice",
          "documentTypeVariant": "Standard",
          "pageLayout": "invoice-standard-page1"
        }
      ]
    },
    {
      "page": 2,
      "documentType": "unknown",
      "documentTypeVariant": null,
      "pageLayout": null,
      "attributes": [],
      "isUnknown": true,
      "unknownReason": "Below class similarity threshold (0.42 < 0.65)",
      "confidence": 0.42,
      "nearestMatch": {
        "documentType": "Receipt",
        "similarity": 0.42
      }
    }
  ]
}
JSON

Immediate Response:
{
  "status": "processed",
  "requestId": "request-123",
  "callbackUrl": "https://your-callback-url.com/webhook"
}
JSON
Webhook POST (sent to callback URL):

Same format as synchronous response above


Error Responses
Status CodeError TypeExample Response
401Unauthorized{"error": "Unauthorized: Invalid API key"}
400Bad Request{"error": {"requestId": "123", "message": "Missing required field: input.file"}}
500Server Error{"error": {"requestId": "123", "message": "Internal processing error"}}

Code Examples
curl -X POST https://api.docugym.com/api/resolvesync \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "request-123",
    "input": {
      "file": "BASE64_ENCODED_FILE_CONTENT",
      "corpusName": "your-corpus-name",
      "saveOODToRepository": "my-repo-key",
      "metadata": {
        "source": "api-test",
        "timestamp": "2024-01-01T00:00:00Z"
      }
    },
    "callback": "https://your-callback-url.com/webhook"
  }'
cURL

Unknown Document Detection
Similarity Thresholds

Enable unknown document detection by setting input.useThresholds: true in your request.

When enabled, the system uses two-stage rejection:

  • Stage 1: Rejects documents with centroid similarity < 0.5
  • Stage 2: Rejects documents below class-specific thresholds (typically 0.92-1.0)

Unknown documents will have isUnknown: true with an explanation and nearest match information.


In-Context Learning (ICL)
Intelligent Entity Extraction

When enabled for a corpus, the system automatically uses In-Context Learning (ICL) to improve entity extraction accuracy by providing the VLM with labeled examples from similar documents.

How it works:

  • The system identifies the top matching examples from your corpus based on similarity scores
  • Only examples with the same document type and variant as the highest match are included
  • Up to 3 labeled examples are provided to the VLM as context
  • The iclExamples field in the response shows which examples were used
  • Each ICL example includes document metadata and similarity scores for transparency

Note: The iclExamples field only appears in the response when ICL is enabled for the corpus and examples were successfully used.


Processing Pipeline
How it works:
  1. Authentication - API key is validated against your organization

  2. Document Classification - Each page is analyzed and classified against known document layouts in your corpus

  3. Unknown Detection - When useThresholds is enabled, documents below similarity thresholds are marked as unknown

  4. Layout Matching - Pages are matched to specific layouts with similarity scores

  5. In-Context Learning - If enabled, the system selects up to 3 similar labeled examples from the corpus to improve extraction accuracy

  6. Entity Extraction - Based on the identified layout and ICL examples (if enabled), relevant fields and entities are extracted

  7. Response Generation - Structured data is returned with bounding boxes and confidence scores

© 2025 Frank Sommers. All rights reserved.