Skip to main content
Execute a flow to process a document. This is the primary endpoint for document extraction.

Endpoint

POST https://app.doclo.ai/api/v1/flows/{flowId}/run

Authentication

Requires an API key with flows:execute scope.
Authorization: Bearer dc_live_your_api_key

Path Parameters

ParameterTypeDescription
flowIdstringRequired. The flow identifier

Request Body

{
  "version": "1.2.0",
  "wait": false,
  "timeout": 30000,
  "idempotencyKey": "unique-request-123",
  "webhookUrl": "https://your-server.com/webhook",
  "webhookSecret": "your_webhook_secret",
  "metadata": {
    "customerId": "cust_123",
    "source": "upload"
  },
  "input": {
    "document": {
      "base64": "data:application/pdf;base64,JVBERi0xLjQK...",
      "filename": "invoice.pdf",
      "mimeType": "application/pdf"
    },
    "variables": {
      "extractLineItems": true
    }
  }
}

Request Fields

FieldTypeRequiredDescription
versionstringNoFlow version to use (default: latest)
waitbooleanNoWait for completion (default: false)
timeoutnumberNoSync wait timeout in ms (default: 30000, max: 60000)
idempotencyKeystringNoUnique key for request deduplication
webhookUrlstringNoURL to receive completion webhook
webhookSecretstringNoSecret for webhook signature verification
metadataobjectNoCustom metadata (returned in results)
inputobjectYesFlow input data
input.documentobjectYesDocument to process
input.document.base64stringYesBase64-encoded document (with or without data URL prefix)
input.document.filenamestringNoOriginal filename
input.document.mimeTypestringNoMIME type (auto-detected if omitted)
input.variablesobjectNoFlow-specific variables

Response

Async Response (200 OK)

When wait: false (default), returns immediately with execution ID:
{
  "id": "exec_abc123def456",
  "flowId": "invoice-extractor",
  "version": "1.2.0",
  "status": "pending",
  "createdAt": "2024-02-20T15:30:00Z",
  "metadata": {
    "customerId": "cust_123",
    "source": "upload"
  }
}
Poll GET /runs/ to check status and retrieve results.

Sync Response (200 OK)

When wait: true, waits for completion (up to timeout):
{
  "id": "exec_abc123def456",
  "flowId": "invoice-extractor",
  "version": "1.2.0",
  "status": "completed",
  "createdAt": "2024-02-20T15:30:00Z",
  "completedAt": "2024-02-20T15:30:12Z",
  "output": {
    "invoiceNumber": "INV-2024-001",
    "date": "2024-02-15",
    "vendor": {
      "name": "Acme Corporation",
      "address": "123 Business St, City, ST 12345"
    },
    "lineItems": [
      {
        "description": "Professional Services",
        "quantity": 10,
        "unitPrice": 150.00,
        "total": 1500.00
      }
    ],
    "subtotal": 1500.00,
    "tax": 127.50,
    "total": 1627.50
  },
  "metrics": {
    "durationMs": 12340,
    "pageCount": 2,
    "creditsUsed": 4
  },
  "metadata": {
    "customerId": "cust_123",
    "source": "upload"
  }
}

Response Fields

FieldTypeDescription
idstringUnique execution identifier
flowIdstringFlow that was executed
versionstringFlow version used
statusstringpending, running, completed, failed, cancelled
createdAtstringISO 8601 start timestamp
completedAtstringISO 8601 completion timestamp (if finished)
outputobjectExtracted data (when completed)
errorobjectError details (when failed)
metricsobjectExecution metrics (when completed)
metrics.durationMsnumberProcessing time in milliseconds
metrics.pageCountnumberNumber of pages processed
metrics.creditsUsednumberCredits consumed
metadataobjectCustom metadata from request

Examples

Basic Async Execution

curl -X POST https://app.doclo.ai/api/v1/flows/invoice-extractor/run \
  -H "Authorization: Bearer dc_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "document": {
        "base64": "data:application/pdf;base64,JVBERi0xLjQK..."
      }
    }
  }'

Sync Execution

curl -X POST https://app.doclo.ai/api/v1/flows/invoice-extractor/run \
  -H "Authorization: Bearer dc_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "wait": true,
    "timeout": 30000,
    "input": {
      "document": {
        "base64": "data:application/pdf;base64,JVBERi0xLjQK..."
      }
    }
  }'

With Webhook

curl -X POST https://app.doclo.ai/api/v1/flows/invoice-extractor/run \
  -H "Authorization: Bearer dc_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "webhookUrl": "https://your-server.com/doclo-webhook",
    "webhookSecret": "whsec_your_secret",
    "input": {
      "document": {
        "base64": "data:application/pdf;base64,JVBERi0xLjQK..."
      }
    }
  }'

TypeScript

import * as fs from 'fs';

// Read and encode document
const pdfBuffer = fs.readFileSync('invoice.pdf');
const base64 = `data:application/pdf;base64,${pdfBuffer.toString('base64')}`;

// Execute flow
const response = await fetch(
  'https://app.doclo.ai/api/v1/flows/invoice-extractor/run',
  {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.DOCLO_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      wait: true,
      input: {
        document: {
          base64,
          filename: 'invoice.pdf',
          mimeType: 'application/pdf'
        }
      }
    })
  }
);

const result = await response.json();

if (result.status === 'completed') {
  console.log('Invoice Number:', result.output.invoiceNumber);
  console.log('Total:', result.output.total);
} else if (result.status === 'failed') {
  console.error('Extraction failed:', result.error);
}

With Idempotency

// Safe to retry - same idempotencyKey returns same execution
const response = await fetch(
  'https://app.doclo.ai/api/v1/flows/invoice-extractor/run',
  {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      idempotencyKey: `invoice-${documentHash}-${Date.now()}`,
      input: { document: { base64: documentData } }
    })
  }
);

Errors

StatusCodeDescription
400INVALID_INPUTInvalid JSON or missing required fields
401UNAUTHORIZEDMissing or invalid API key
402INSUFFICIENT_CREDITSNot enough credits
403FORBIDDENAPI key missing flows:execute scope
404FLOW_NOT_FOUNDFlow doesn’t exist
404VERSION_NOT_FOUNDRequested version doesn’t exist
422VALIDATION_ERRORInput doesn’t match schema
422INVALID_DOCUMENTDocument is corrupted or unsupported format
429RATE_LIMITEDRate limit exceeded
429CONCURRENT_LIMITToo many concurrent executions
504EXECUTION_TIMEOUTSync wait timeout exceeded

Sync vs Async

ModeUse WhenTimeoutResult
Async (wait: false)Large documents, background processingNonePoll or webhook
Sync (wait: true)Small documents, immediate responseMax 60sDirect response
For documents over 10 pages or complex flows, async execution with webhooks is recommended.

Next Steps