> ## 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 to a workflow without triggering processing

Useful when you want to stage files now and process them in a separate batch later.

Each upload creates its own **single-file collection** and returns its `file_collection_id`. To process it, call [Run Uploaded File](/api-reference/workflows/run-staged) with that id. (For upload-and-process in one call, use [Run Workflow](/api-reference/workflows/run) instead.)

<Note>
  `file_collection_id` is the handle you run and poll — see [Packets and files](/concepts/document-packets#packets-and-files). `file_id` identifies the single file within it (used for reading that file's content/results).
</Note>

<RequestExample>
  ```bash curl theme={null}
  curl -X POST 'https://api.anyformat.ai/v2/workflows/550e8400-e29b-41d4-a716-446655440000/upload/' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -F 'file=@/path/to/document.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}/upload/"
  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}/upload/`, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    },
    body: formData
  });

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

  ```typescript TypeScript theme={null}
  interface UploadResponse {
    status: string;
    filename: string | null;
    file_collection_id: string | null;
    file_id: string | 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}/upload/`,
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY'
      },
      body: formData
    }
  );

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

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

<ResponseExample>
  ```json Response (201 Created) theme={null}
  {
    "status": "uploaded",
    "filename": "document.pdf",
    "file_collection_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "file_id": "f0e1d2c3-b4a5-6789-0abc-def123456789"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v2/workflows/{workflow_id}/upload/
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}/upload/:
    post:
      tags:
        - workflows
      summary: Upload file
      description: >-
        Upload a file to a workflow without running extraction.


        Use this when you want to stage files for later processing. For
        upload-and-extract

        in one step, use `POST /v2/workflows/{workflow_id}/run/` instead.
      operationId: v2_upload_file
      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_upload_file'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UploadFileResponse'
          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_upload_file:
      properties:
        file:
          anyOf:
            - type: string
              contentMediaType: application/octet-stream
            - type: 'null'
          title: File
      type: object
      title: Body_v2_upload_file
    UploadFileResponse:
      properties:
        status:
          type: string
          title: Status
          description: 'Upload result: `uploaded` on success.'
          examples:
            - uploaded
        filename:
          anyOf:
            - type: string
            - type: 'null'
          title: Filename
          description: >-
            Name the file was stored under. Auto-renamed with a ` (n)` counter
            when it collides with an existing file in the workflow;
            `original_filename` then holds the name you uploaded.
          examples:
            - invoice.pdf
        original_filename:
          anyOf:
            - type: string
            - type: 'null'
          title: Original Filename
          description: >-
            The name you uploaded, present only when the file was auto-renamed
            to avoid a duplicate name in the workflow. `null` when `filename` is
            the name you uploaded.
          examples:
            - invoice.pdf
        file_collection_id:
          anyOf:
            - type: string
            - type: 'null'
          title: File Collection Id
          description: >-
            The collection UUID the file was uploaded into. Use it to poll
            results via `GET
            /v2/workflows/{workflow_id}/files/{file_collection_id}/results/`.
          examples:
            - 069dcc2c-e14c-7606-8000-2ee4fb17b4e1
        file_id:
          anyOf:
            - type: string
            - type: 'null'
          title: File Id
          description: >-
            The UUID of the uploaded file. Pass it to `POST
            /v2/workflows/{workflow_id}/files/{file_id}/run/` to start
            extraction.
          examples:
            - 069dcc2c-e14c-7606-8000-2ee4fb17b4e2
      type: object
      required:
        - status
      title: UploadFileResponse
      description: >-
        Confirmation that a file was uploaded successfully without triggering
        extraction.
    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

````