> ## 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 Workflow

> Submit a file or text for processing using a workflow

The run is asynchronous — the response's `id` is the **`file_collection_id`**; poll `GET .../files/{file_collection_id}/results/` for the output.

## Input Methods

You can submit content for processing in two ways:

1. **File Upload** - Upload a binary file directly via multipart form data
2. **Text Input** - Send plain text for processing

<Note>
  Only one input method can be used per request. Provide either `file` or `text`, not both.
</Note>

<Info>
  The `id` returned in the response is the **`file_collection_id`** — not a `file_id`. Use it to poll for results via `GET /v2/workflows/{workflow_id}/files/{id}/results/` (the path segment is named `files`, but it expects the collection id). The endpoint returns 412 while processing and 200 when results are ready. See [Packets and files](/concepts/document-packets#packets-and-files).
</Info>

<RequestExample>
  ```bash curl (File Upload) theme={null}
  curl -X POST 'https://api.anyformat.ai/v2/workflows/550e8400-e29b-41d4-a716-446655440000/run/' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -F 'file=@/path/to/document.pdf'
  ```

  ```bash curl (Text Input) theme={null}
  curl -X POST 'https://api.anyformat.ai/v2/workflows/550e8400-e29b-41d4-a716-446655440000/run/' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -F 'text=Invoice #12345 from Acme Corp. Total: $1,250.00'
  ```

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

  workflow_id = "550e8400-e29b-41d4-a716-446655440000"
  url = f"https://api.anyformat.ai/v2/workflows/{workflow_id}/run/"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY"
  }

  with open('document.pdf', 'rb') as f:
      response = requests.post(
          url,
          headers=headers,
          files={'file': f}
      )

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const workflowId = '550e8400-e29b-41d4-a716-446655440000';
  const formData = new FormData();
  formData.append('file', fileInput.files[0]);

  const response = await fetch(`https://api.anyformat.ai/v2/workflows/${workflowId}/run/`, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    },
    body: formData
  });

  const data = await response.json();
  console.log(data);
  ```

  ```typescript TypeScript theme={null}
  interface WorkflowRunResponse {
    id: string;
    status: string;
    workflow_id: string;
  }

  const workflowId = '550e8400-e29b-41d4-a716-446655440000';
  const formData = new FormData();
  formData.append('file', fileInput.files[0]);

  const response = await fetch(
    `https://api.anyformat.ai/v2/workflows/${workflowId}/run/`,
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY'
      },
      body: formData
    }
  );

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

  const data: WorkflowRunResponse = await response.json();
  console.log(data.id);
  ```
</RequestExample>

<ResponseExample>
  ```json Response (202 Accepted) theme={null}
  {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "status": "pending",
    "workflow_id": "550e8400-e29b-41d4-a716-446655440000",
    "version_id": "FGaV4I2JAA"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v2/workflows/{workflow_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:
  /v2/workflows/{workflow_id}/run/:
    post:
      tags:
        - workflows
      summary: Run workflow
      description: >-
        Upload a file and immediately run the extraction workflow on it.


        This is the primary endpoint for document extraction. It creates a file
        collection,

        uploads the file, and starts extraction in one step. The response
        includes a collection

        `id` that you can use to poll for results via

        `GET /v2/workflows/{workflow_id}/files/{collection_id}/results/`.


        Provide the file as a binary upload in the `file` field.
      operationId: v2_run_workflow
      parameters:
        - name: workflow_id
          in: path
          required: true
          schema:
            type: string
            title: Workflow Id
        - name: X-Anyformat-Priority
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Anyformat-Priority
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_v2_run_workflow'
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowRunResponseV2'
          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, file, or collection 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:
    Body_v2_run_workflow:
      properties:
        file:
          anyOf:
            - type: string
              contentMediaType: application/octet-stream
            - type: 'null'
          title: File
      type: object
      title: Body_v2_run_workflow
    WorkflowRunResponseV2:
      properties:
        id:
          type: string
          title: Id
          description: >-
            The collection UUID for this run. Use this ID to poll for results
            via `GET /v2/workflows/{workflow_id}/files/{id}/results/`.
          examples:
            - 069dcc2c-e14c-7606-8000-2ee4fb17b4e1
        status:
          type: string
          enum:
            - not_started
            - queued
            - in_progress
            - processed
            - error
            - cancelled
          title: Status
          description: >-
            Initial status of the run: `queued` (the run was accepted and
            enqueued, not that extraction is complete). Use `GET
            /v2/workflows/{workflow_id}/files/{id}/results/` to poll the run
            through its `in_progress` / `processed` lifecycle.
          examples:
            - queued
        workflow_id:
          type: string
          title: Workflow Id
          description: The UUID of the workflow that was executed.
          examples:
            - 0686bb97-8c30-70f0-8000-97669e000eb8
        version_id:
          type: string
          title: Version Id
          description: >-
            The workflow version this run was bound to (the latest version at
            submission time). Lets callers verify which schema produced the
            results — useful right after an edit.
          examples:
            - FGaV4I2JAA
      type: object
      required:
        - id
        - status
        - workflow_id
        - version_id
      title: WorkflowRunResponseV2
      description: >-
        Response after triggering a workflow run. Contains the collection ID to
        use for polling extraction results.
    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
    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

````