API Reference

Everything you need to integrate document processing into your application. The REST API uses JSON for request/response bodies and standard HTTP status codes.

Base URLhttps://your-domain.com/api/v1

Authentication

Most endpoints require an API key. Generate one from Settings → API Keys in your organization dashboard.

Include your API key in the Authorization header:

curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://your-domain.com/api/v1/credits/balance

Templates

Browse available document templates.

GET/api/v1/templatesNone

List all active document templates. Optionally filter by category.

Parameters

NameTypeRequiredDescription
categorystringOptionalFilter by template category

Response

{
  "categories": ["Legal", "Finance", "Marketing"],
  "templates": [
    {
      "id": "clx...",
      "name": "Invoice Template",
      "description": "Professional invoice template",
      "category": "Finance",
      "pageCount": 2,
      "creditCost": 2,
      "thumbnailKey": "templates/thumb-123.png"
    }
  ]
}

Jobs

Submit and manage document processing jobs.

POST/api/v1/jobsAPI Key

Submit a new document processing job. Deducts credits automatically.

Request Body

FieldTypeRequiredDescription
templateIdstringRequiredThe template to use (CUID2 format)
editPromptstringRequiredInstructions for document editing (10-2000 chars)
targetPagesnumber[]OptionalSpecific pages to edit (defaults to all)

Response

{
  "job": {
    "id": "clx...",
    "status": "pending"
  }
}
GET/api/v1/jobsAPI Key

List jobs for the authenticated organization with cursor-based pagination.

Parameters

NameTypeRequiredDescription
cursorstringOptionalCursor for pagination (job ID)
limitnumberOptionalResults per page (default: 20, max: 100)

Response

{
  "jobs": [
    {
      "id": "clx...",
      "status": "completed",
      "createdAt": "2025-01-15T10:30:00Z",
      "templateName": "Invoice Template",
      "creditsCharged": 2,
      "errorMessage": null
    }
  ],
  "nextCursor": "clx..."
}
GET/api/v1/jobs/:jobIdAPI Key

Get detailed information about a specific job, including download URL if completed.

Parameters

NameTypeRequiredDescription
jobIdstringRequiredThe job ID

Response

{
  "job": {
    "id": "clx...",
    "status": "completed",
    "createdAt": "2025-01-15T10:30:00Z",
    "updatedAt": "2025-01-15T10:31:00Z",
    "templateName": "Invoice Template",
    "creditsCharged": 2,
    "downloadUrl": "https://...",
    "errorMessage": null
  }
}

Credits

Check balance and purchase credit packs.

GET/api/v1/credits/balanceAPI Key

Get the current credit balance for the authenticated organization.

Parameters

NameTypeRequiredDescription
includeTransactionsbooleanOptionalInclude recent transactions in response

Response

{
  "balance": 47,
  "transactions": [
    {
      "id": "clx...",
      "amount": 50,
      "description": "Purchased 50 credits",
      "createdAt": "2025-01-15T10:00:00Z"
    }
  ]
}
POST/api/v1/credits/purchaseAPI Key

Create a Stripe checkout session to purchase a credit pack.

Request Body

FieldTypeRequiredDescription
packIdstringRequiredCredit pack ID: "pack10", "pack50", or "pack100"

Response

{
  "checkoutUrl": "https://checkout.stripe.com/..."
}

Crypto Payments

Purchase credits using cryptocurrency.

POST/api/v1/crypto/checkoutAPI Key

Create a crypto payment checkout for credit purchase.

Request Body

FieldTypeRequiredDescription
packIdstringRequiredCredit pack ID
chainstringRequiredBlockchain (e.g., "ethereum", "polygon")
tokenstringRequiredToken symbol (e.g., "USDC", "USDT")

Response

{
  "paymentId": "clx...",
  "depositAddress": "0x...",
  "amount": "10.00",
  "token": "USDC",
  "chain": "polygon",
  "expiresAt": "2025-01-15T11:00:00Z"
}

Files

Access template thumbnails and job output files.

GET/api/v1/files/:bucket/:keySigned URL

Download a file. Template files are public. Output files require a signed URL (provided in job detail response).

Parameters

NameTypeRequiredDescription
bucketstringRequiredBucket name: "templates" or "outputs"
keystringRequiredFile key (URL-encoded)
downloadbooleanOptionalForce download instead of inline display

Response

Binary file content with appropriate Content-Type header

Webhooks

Configure webhook endpoints in Settings → Webhooks to receive real-time notifications when job status changes. All payloads are signed with HMAC-SHA256.

Events

EventDescription
job.processingFired when a job begins processing.
job.completedFired when a job finishes successfully. Includes output key.
job.failedFired when a job fails. Includes error message.

Payload Example

{
  "event": "job.completed",
  "timestamp": "2025-01-15T10:31:00Z",
  "data": {
    "id": "clx...",
    "organizationId": "clx...",
    "templateId": "clx...",
    "status": "completed",
    "outputKey": "outputs/clx...pdf",
    "creditsCharged": 2,
    "processingTimeSeconds": 12.5
  }
}

Signature Verification

Each webhook includes an X-Webhook-Signature header. Verify it using HMAC-SHA256 with your webhook secret:

import { createHmac } from "crypto";

function verifyWebhook(payload: string, signature: string, secret: string) {
  const expected = createHmac("sha256", secret)
    .update(payload)
    .digest("hex");
  return signature === expected;
}

Error Codes

All errors return a JSON body with an error field describing the issue.

CodeDescription
400Bad Request - Invalid parameters or request body
401Unauthorized - Missing or invalid API key
403Forbidden - Insufficient permissions
404Not Found - Resource does not exist
409Conflict - Duplicate request (idempotency)
422Unprocessable Entity - Validation failed
429Too Many Requests - Rate limit exceeded
500Internal Server Error