> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyformat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Run Document Packet

> Run (or re-run) a document packet on the latest version of its workflow

*Rate limit tier: **submission** (60 req/min) — see [Rate limits](/api-reference-v3/introduction#rate-limits).*

Runs — or **re-runs** — a [document packet](/concepts/document-packets) on the latest version of its workflow. The path is flat: the packet already knows which workflow it belongs to, so no `workflow_id` appears in the URL.

**Every call creates a new run.** Re-running after editing the workflow is the intended flow — same document, another attempt — and earlier runs stay readable at [`GET /v3/runs/{run_id}/`](/api-reference-v3/runs/get) with their own results. Re-runs are metered like fresh runs (see [How credits work](/concepts/how-credits-work)).

The only exception is an `Idempotency-Key` replay: retrying with the same key returns the **original** run instead of triggering (and billing) a second extraction. See [Idempotency](/api-reference-v3/introduction#idempotency).

Unknown ids — including packets belonging to another organization — return `404`. An organization without extraction credit receives `402 PAYMENT_REQUIRED`.

<RequestExample>
  ```bash curl theme={null}
  curl -X POST 'https://api.anyformat.ai/v3/document-packets/069dcc2c-e14c-7606-8000-2ee4fb17b4e1/run/' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -H 'Idempotency-Key: 9e8d7c6b-5a4f-3e2d-1c0b-a9b8c7d6e5f4'
  ```

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

  document_packet_id = "069dcc2c-e14c-7606-8000-2ee4fb17b4e1"
  url = f"https://api.anyformat.ai/v3/document-packets/{document_packet_id}/run/"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Idempotency-Key": "9e8d7c6b-5a4f-3e2d-1c0b-a9b8c7d6e5f4",
  }

  triggered = requests.post(url, headers=headers).json()
  print(triggered["run_id"])
  ```

  ```typescript TypeScript theme={null}
  interface RunTriggered {
    run_id: string;
    document_packet_id: string;
    workflow_id: string;
    status: 'queued' | 'in_progress' | 'processed' | 'error' | 'cancelled';
  }

  const packetId = '069dcc2c-e14c-7606-8000-2ee4fb17b4e1';
  const response = await fetch(
    `https://api.anyformat.ai/v3/document-packets/${packetId}/run/`,
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Idempotency-Key': crypto.randomUUID(),
      },
    }
  );

  if (!response.ok) {
    throw new Error(`API error: ${response.status}`);
  }

  const triggered: RunTriggered = await response.json();
  console.log(triggered.run_id);
  ```
</RequestExample>

<ResponseExample>
  ```json Response (202 Accepted) theme={null}
  {
    "run_id": "069dcc2c-e14c-7606-8000-2ee4fb17b4fa",
    "document_packet_id": "069dcc2c-e14c-7606-8000-2ee4fb17b4e1",
    "workflow_id": "0686bb97-8c30-70f0-8000-97669e000eb8",
    "status": "queued"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v3/document-packets/{document_packet_id}/run/
openapi: 3.1.0
info:
  title: anyformat API
  description: >
    Document extraction and workflow automation API.


    AnyFormat lets you define extraction workflows that pull structured data
    from any document — PDFs, images, scanned files, or plain text. Upload a
    file, run it through a workflow, and get back structured fields with
    confidence scores and source evidence.


    ## Quick start


    See the [Quick start
    guide](https://docs.anyformat.ai/api-reference/introduction) for a
    walkthrough.


    ## Authentication


    All endpoints (except `/health/`) require a Bearer token in the
    `Authorization` header:


    ```

    Authorization: Bearer <your-api-key>

    ```


    Get your API key from
    [app.anyformat.ai/api-key](https://app.anyformat.ai/api-key).


    ## Versioning


    Endpoints are versioned by path prefix (`/v2/`, `/v3/`). Every response
    under

    a versioned prefix includes `X-API-Version`.
  version: 2.0.0
servers:
  - url: https://api.anyformat.ai
    description: API server
security: []
tags:
  - name: workflows
    description: >-
      Workflows define extraction templates — what fields to extract from
      documents. Create workflows, upload files, run extractions, and fetch
      results.
  - name: files
    description: >-
      File collections group uploaded documents and track their extraction
      progress. Upload files, check status, and retrieve extraction results.
  - name: suggestions
    description: >-
      AI-powered schema and workflow suggestion endpoints for the AnyFormat
      webapp. Authenticated with a Cognito JWT rather than an API key.
  - name: document-packets
    description: >-
      Document packets group uploaded documents for a workflow (v3). Address a
      packet directly to (re-)run its workflow.
  - name: runs
    description: >-
      Extraction runs — the v3 first-class result entity. Each run is a single
      execution of a workflow against a document packet; fetch its status and
      results flat by run id.
  - name: health
    description: Health check endpoints to verify API availability.
paths:
  /v3/document-packets/{document_packet_id}/run/:
    post:
      tags:
        - document-packets
      summary: Run document packet
      description: |-
        Run (or re-run) a document packet on the latest version of its
        workflow.

        Every call creates a NEW run — re-running after editing the workflow
        is the intended flow; earlier runs stay readable at
        `GET /v3/runs/{run_id}/`. The only exception is an `Idempotency-Key`
        replay, which returns the original run.

        Unknown ids — including packets belonging to another organization —
        return 404. An organization without extraction credit gets 402.
      operationId: v3_run_document_packet
      parameters:
        - name: document_packet_id
          in: path
          required: true
          schema:
            type: string
            title: Document Packet Id
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: >-
              Optional caller-supplied key (Stripe convention). Retrying the
              request with the same key returns the original run instead of
              triggering (and billing) a second extraction.
            title: Idempotency-Key
          description: >-
            Optional caller-supplied key (Stripe convention). Retrying the
            request with the same key returns the original run instead of
            triggering (and billing) a second extraction.
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunTriggeredV3'
          headers:
            X-RateLimit-Limit:
              description: Requests allowed per window (60s).
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: Requests remaining in the current window.
              schema:
                type: integer
            X-RateLimit-Reset:
              description: Seconds until the current window resets.
              schema:
                type: integer
        '401':
          description: Authentication failed — missing, invalid, or expired API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
              examples:
                AUTH_FAILED:
                  value:
                    error: Authentication failed.
                    detail: Authentication failed.
                    error_code: AUTH_FAILED
                    retryable: false
                    request_id: req_abc123
        '404':
          description: >-
            Resource not found — the workflow, document packet, or run ID does
            not exist or is not visible to this API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
              examples:
                NOT_FOUND:
                  value:
                    error: Resource not found.
                    detail: Resource not found.
                    error_code: NOT_FOUND
                    retryable: false
                    request_id: req_abc123
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: >-
            Rate limited — retry after the `Retry-After` header. Default
            windows: 60 requests/minute for extraction submission, 600
            requests/minute for general endpoints.
          headers:
            Retry-After:
              description: Seconds until the next request is allowed.
              schema:
                type: integer
            X-RateLimit-Limit:
              description: Requests allowed per window (60s).
              schema:
                type: integer
            X-RateLimit-Remaining:
              description: Requests remaining in the current window.
              schema:
                type: integer
            X-RateLimit-Reset:
              description: Seconds until the current window resets.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
              examples:
                RATE_LIMITED:
                  value:
                    error: Rate limit exceeded — retry after backoff.
                    detail: Rate limit exceeded — retry after backoff.
                    error_code: RATE_LIMITED
                    retryable: true
                    request_id: req_abc123
      security:
        - ApiKeyAuth: []
components:
  schemas:
    RunTriggeredV3:
      properties:
        run_id:
          type: string
          title: Run Id
          description: Unique identifier of the new run (hyphenated UUID).
          examples:
            - 069dcc2c-e14c-7606-8000-2ee4fb17b4f9
        document_packet_id:
          type: string
          title: Document Packet Id
          description: The document packet the run executes on (hyphenated UUID).
          examples:
            - 069dcc2c-e14c-7606-8000-2ee4fb17b4e1
        workflow_id:
          type: string
          title: Workflow Id
          description: The workflow being run (hyphenated UUID).
          examples:
            - 0686bb97-8c30-70f0-8000-97669e000eb8
        status:
          $ref: '#/components/schemas/RunStatus'
          description: Status at acceptance time — normally `queued`.
          examples:
            - queued
      type: object
      required:
        - run_id
        - document_packet_id
        - workflow_id
        - status
      title: RunTriggeredV3
      description: |-
        202 response for both run triggers (`upload/run/` and
        `document-packets/{id}/run/`).
    ErrorEnvelope:
      type: object
      title: ErrorEnvelope
      description: >-
        Uniform error response. `retryable=true` means the same request may
        succeed on retry (with backoff); `retryable=false` means the caller must
        change the request before retrying.
      required:
        - error
        - detail
        - error_code
        - retryable
        - request_id
      properties:
        error:
          type: string
          description: Short human-readable summary.
        detail:
          description: >-
            Machine-readable detail. String for most errors; list of field
            errors for validation failures.
          oneOf:
            - type: string
            - type: array
              items:
                type: object
        error_code:
          type: string
          description: Stable identifier for programmatic handling.
          examples:
            - VALIDATION_ERROR
            - AUTH_FAILED
            - NOT_FOUND
            - PRECONDITION_FAILED
            - RATE_LIMITED
            - INTERNAL_ERROR
            - GATEWAY_TIMEOUT
        retryable:
          type: boolean
          description: True when the caller should retry (with backoff for 429/412/5xx).
        request_id:
          type: string
          description: Correlates this response with server logs.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    RunStatus:
      type: string
      enum:
        - queued
        - in_progress
        - processed
        - error
        - cancelled
      title: RunStatus
      description: |-
        Execution lifecycle of a run. Non-terminal: ``queued``,
        ``in_progress``. Terminal: ``processed`` (success), ``error``,
        ``cancelled``.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    ApiKeyAuth:
      type: http
      description: >-
        API key issued from app.anyformat.ai/api-key. Send as `Authorization:
        Bearer <key>`.
      scheme: bearer

````