> ## 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 carries a file UUID; poll `GET .../files/{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 a file UUID. Use it to poll for results via `GET /v2/workflows/{workflow_id}/files/{id}/results/`. The endpoint returns 412 while processing and 200 when results are ready.
</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": "accepted",
    "workflow_id": "550e8400-e29b-41d4-a716-446655440000"
  }
  ```
</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


    1. **Create a workflow** in the [AnyFormat
    dashboard](https://app.anyformat.ai) and define the fields you want to
    extract.

    2. **Run the workflow** via `POST /v2/workflows/{workflow_id}/run/` with a
    file attached.

    3. **Fetch results** via `GET
    /v2/workflows/{workflow_id}/files/{collection_id}/results/` once processing
    completes.


    ## 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/settings](https://app.anyformat.ai/settings).


    ## Versioning


    All endpoints use the `/v2/` path prefix. All responses include
    `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: webhooks
    description: >-
      Webhook subscriptions for asynchronous event notifications. Get notified
      when extractions complete or fail.
  - 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, or send raw
        text in the

        `text` field for text-only extraction.
      operationId: v2_run_workflow
      parameters:
        - name: workflow_id
          in: path
          required: true
          schema:
            type: string
            title: Workflow Id
      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'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    Body_v2_run_workflow:
      properties:
        file:
          anyOf:
            - type: string
              contentMediaType: application/octet-stream
            - type: 'null'
          title: File
        text:
          anyOf:
            - type: string
            - type: 'null'
          title: Text
      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
          title: Status
          description: >-
            Initial status of the run, typically `success` (meaning the run was
            accepted, not that extraction is complete).
          examples:
            - success
        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.
    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/settings. Send as `Authorization:
        Bearer <key>`.
      scheme: bearer

````