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

# Upload File

> Upload a file without triggering processing

<Note>
  This endpoint uploads a file. It does **not** trigger processing. To upload and process in one step, use [Run Workflow](/api-reference/workflows/run) instead.
</Note>

## Request Body

This endpoint uses `multipart/form-data`:

| Field   | Type | Required | Description        |
| ------- | ---- | -------- | ------------------ |
| `files` | file | Yes      | The file to upload |

<RequestExample>
  ```bash curl theme={null}
  curl -X POST 'https://api.anyformat.ai/v2/workflows/550e8400-e29b-41d4-a716-446655440000/files/' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -F 'files=@invoice.pdf'
  ```

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

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

  with open("invoice.pdf", "rb") as f:
      files = [("files", ("invoice.pdf", f, "application/pdf"))]

      response = requests.post(url, headers=headers, files=files)
      print(response.json())
  ```

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

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

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

  ```typescript TypeScript theme={null}
  interface FileItem {
    filename: string;
    status: string;
  }

  interface UploadFileResponse {
    id: string;
    name: string | null;
    files: FileItem[];
    workflow_id: string;
  }

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

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

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

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

<ResponseExample>
  ```json Response (201 Created) theme={null}
  {
    "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "name": null,
    "files": [
      {
        "filename": "invoice.pdf",
        "status": "uploaded"
      }
    ],
    "workflow_id": "550e8400-e29b-41d4-a716-446655440000"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v2/workflows/{workflow_id}/files/
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}/files/:
    post:
      tags:
        - files
      summary: Create file collection
      description: >-
        Upload one or more files to a workflow, creating one collection per
        file.


        Use this when you want to upload files without immediately running
        extraction.

        To upload and extract in one step, use `POST
        /v2/workflows/{workflow_id}/run/` instead.


        Supported file types: PDF, PNG, JPG, TIFF, TXT, DOCX, XLSX, CSV, and
        more.


        Multi-file collections aren't supported yet — each uploaded file becomes

        its own one-file collection. The response's ``id`` is the last

        collection's id; ``files`` enumerates every uploaded file in order.
      operationId: v2_create_workflow_file
      parameters:
        - name: workflow_id
          in: path
          required: true
          schema:
            type: string
            title: Workflow Id
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_v2_create_workflow_file'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCollectionResponse'
          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_create_workflow_file:
      properties:
        files:
          items:
            type: string
            contentMediaType: application/octet-stream
          type: array
          title: Files
      type: object
      required:
        - files
      title: Body_v2_create_workflow_file
    CreateCollectionResponse:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier of the newly created file collection.
          examples:
            - 069dcc2c-e14c-7606-8000-2ee4fb17b4e1
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: Human-readable name for the collection.
        files:
          items:
            $ref: '#/components/schemas/FileItem'
          type: array
          title: Files
          description: List of files included in the collection, with their upload status.
        workflow_id:
          type: string
          title: Workflow Id
          description: The UUID of the workflow this collection belongs to.
          examples:
            - 0686bb97-8c30-70f0-8000-97669e000eb8
        rejected:
          items:
            $ref: '#/components/schemas/RejectedFileItem'
          type: array
          title: Rejected
          description: >-
            Files the backend refused to accept — unsupported extension at
            slot-time or disguised bytes at register-time. Empty when every file
            uploaded cleanly.
      type: object
      required:
        - id
        - files
        - workflow_id
      title: CreateCollectionResponse
      description: >-
        Response from creating a file collection. Contains the collection ID and
        the status of each uploaded file.
    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
    FileItem:
      properties:
        filename:
          type: string
          title: Filename
          description: Name of the uploaded file.
          examples:
            - invoice.pdf
        status:
          type: string
          title: Status
          description: >-
            Initial status of the file at the moment the response is returned.
            Multipart upload (`POST .../files/`) returns `uploaded` or `failed`
            synchronously. URL ingestion (`POST .../files/from-url/`) returns
            `pending` while the server fetches the bytes asynchronously. The
            file listing's `status` field reflects extraction state, not upload
            state — trigger a workflow run on the returned collection to drive
            the file through the `queued` / `in_progress` / `processed`
            lifecycle.
          examples:
            - uploaded
      type: object
      required:
        - filename
        - status
      title: FileItem
      description: A single file within a collection, showing its name and upload status.
    RejectedFileItem:
      properties:
        filename:
          type: string
          title: Filename
          description: Name of the rejected file.
          examples:
            - trojan.pdf
        reason:
          type: string
          title: Reason
          description: Human-readable reason from the backend upload validator.
          examples:
            - >-
              File contents are not a supported file type (detected:
              application/x-msdownload).
      type: object
      required:
        - filename
        - reason
      title: RejectedFileItem
      description: |-
        A file the backend rejected either upfront (unsupported filename) or
        after inspecting its bytes (disguised content). No ``FileCollection``
        was created for these; the raw bytes (if any reached S3) age out via
        the ``upload-status=pending`` lifecycle rule within 24 h.
    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

````