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

# Upload document

> Upload borrower evidence or documents supporting a lending product or risk policy. Upload creates a new record; it cannot overwrite an existing document.

Upload borrower evidence or documents supporting a lending product or risk policy. Upload creates a new record; it cannot overwrite an existing document. All IDs and cursors must belong to the authorized workspace and environment. Required scope: evidence:write.

Examples use synthetic IDs. Replace them with values returned by your environment.


## OpenAPI

````yaml openapi/amlok.json POST /v1/documents
openapi: 3.1.0
info:
  title: AMLOK API
  version: 1.0.0
  description: >-
    AMLOK API: borrower connections, Insights origination, immutable risk
    packages and Signal monitoring. Use your institution-issued API origin.
servers: []
security:
  - BearerAuth: []
paths:
  /v1/documents:
    post:
      tags:
        - Evidence
      summary: Upload document
      description: >-
        Upload borrower evidence or documents supporting a lending product or
        risk policy. Upload creates a new record; it cannot overwrite an
        existing document. All IDs and cursors must belong to the authorized
        workspace and environment. Required scope: evidence:write.
      operationId: uploadDocument
      parameters:
        - name: Idempotency-Key
          in: header
          required: true
          schema:
            type: string
            minLength: 1
          description: >-
            Stable for one intended command and its retries, scoped to key
            workspace/environment and operation. Mismatched body returns 409.
            Full response replay 24 hours; durable receipt remains.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/UploadDocument'
            example:
              file: <binary file bytes>
              context: borrower
              borrower_id: bor_synthetic
              document_type: financial_statement
      responses:
        '202':
          description: Accepted asynchronously; inspect status, not just HTTP success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Document'
                  meta:
                    $ref: '#/components/schemas/Meta'
                required:
                  - data
                  - meta
                additionalProperties: false
              example:
                data:
                  id: doc_synthetic
                  context: borrower
                  borrower_id: bor_synthetic
                  file_name: financial-statement.pdf
                  mime_type: application/pdf
                  sha256: >-
                    0000000000000000000000000000000000000000000000000000000000000000
                  size_bytes: 12500
                  status: processing
                  restriction_reason: null
                  created_at: '2026-11-06T12:00:00Z'
                  document_type: financial_statement
                  origination_id: null
                  requirement_id: null
                  origin: institution_upload
                  record_version: 1
                  failure: null
                meta:
                  request_id: req_synthetic
                  schema_version: 1.0.0
                  environment: sandbox
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '400':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: validation_error
                  message: Validation error.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '401':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: unauthenticated
                  message: Unauthenticated.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '402':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: insufficient_credits
                  message: Insufficient credits.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '403':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: forbidden
                  message: Forbidden.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '404':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: not_found
                  message: Not found.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '409':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: idempotency_conflict
                  message: Idempotency conflict.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '410':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: cursor_expired
                  message: Cursor expired.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '413':
          description: >-
            Request exceeds the effective profile size limit or media type is
            unsupported. No command is accepted.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: payload_too_large
                  message: payload too large
                  retryable: false
                  request_id: req_synthetic
                  field: null
        '415':
          description: >-
            Request exceeds the effective profile size limit or media type is
            unsupported. No command is accepted.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: unsupported_media_type
                  message: unsupported media type
                  retryable: false
                  request_id: req_synthetic
                  field: null
        '422':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: validation_error
                  message: Validation error.
                  retryable: false
                  request_id: req_synthetic
                  field: null
          headers:
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '429':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: rate_limited
                  message: Rate limited.
                  retryable: true
                  request_id: req_synthetic
                  field: null
          headers:
            Retry-After:
              description: Minimum delay in seconds before retry.
              schema:
                type: integer
                minimum: 0
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
        '503':
          description: >-
            Inspect structured error; retry only when retryable. 429 and 503 can
            include Retry-After.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    $ref: '#/components/schemas/Error'
                required:
                  - error
                additionalProperties: false
              example:
                error:
                  code: temporarily_unavailable
                  message: Temporarily unavailable.
                  retryable: true
                  request_id: req_synthetic
                  field: null
          headers:
            Retry-After:
              description: Minimum delay in seconds before retry.
              schema:
                type: integer
                minimum: 0
            X-Request-ID:
              schema:
                type: string
                minLength: 1
              description: Same request ID as meta.request_id or error.request_id.
      security:
        - BearerAuth: []
      x-codeSamples:
        - lang: Shell
          label: cURL
          source: |-
            curl --request POST --fail-with-body --max-time 30 \
              "${AMLOK_API_BASE_URL}/v1/documents" \
              --header "Authorization: Bearer ${AMLOK_API_KEY}" \
              --header 'Accept: application/json' \
              --header 'Idempotency-Key: uploadDocument-synthetic-0042' \
              --form file=@/path/to/financial-statement.pdf \
              --form context=borrower \
              --form borrower_id=bor_synthetic \
              --form document_type=financial_statement
        - lang: Python
          source: >
            import os

            import requests


            headers = {'Accept': 'application/json', 'Idempotency-Key':
            'uploadDocument-synthetic-0042'}

            headers["Authorization"] = "Bearer " + os.environ["AMLOK_API_KEY"]

            with open("/path/to/financial-statement.pdf", "rb") as upload:
                response = requests.request('POST', os.environ["AMLOK_API_BASE_URL"] + '/v1/documents', headers=headers, data={'context': 'borrower', 'borrower_id': 'bor_synthetic', 'document_type': 'financial_statement'}, files={"file": upload}, timeout=30, allow_redirects=False)
            response.raise_for_status()

            print(response.json())
        - lang: JavaScript
          source: >
            import { readFile } from "node:fs/promises";

            const headers = {"Accept": "application/json", "Idempotency-Key":
            "uploadDocument-synthetic-0042"};

            headers.Authorization = `Bearer ${process.env.AMLOK_API_KEY}`;

            const form = new FormData();

            form.append("file", new Blob([await
            readFile("/path/to/financial-statement.pdf")]),
            "financial-statement.pdf");

            form.append("context", "borrower");

            form.append("borrower_id", "bor_synthetic");

            form.append("document_type", "financial_statement");

            const response = await fetch(process.env.AMLOK_API_BASE_URL +
            "/v1/documents", {
              method: "POST", headers, redirect: "error", signal: AbortSignal.timeout(30000),
              body: form
            });

            if (!response.ok) throw new Error(`HTTP ${response.status}: ${await
            response.text()}`);

            console.log(await response.json());
components:
  schemas:
    UploadDocument:
      type: object
      properties:
        file:
          type: string
          format: binary
          description: >-
            File for UploadDocument. Constraints, requiredness and allowed
            values are defined by this schema.
          contentMediaType: application/octet-stream
        context:
          type: string
          enum:
            - borrower
            - lending_product
            - risk_policy
          description: >-
            Context for UploadDocument. Constraints, requiredness and allowed
            values are defined by this schema.
        borrower_id:
          type: string
          minLength: 1
          description: >-
            Opaque identifier, authorized within the API key workspace and
            environment.
        document_type:
          type: string
          minLength: 1
          description: >-
            Document type for UploadDocument. Constraints, requiredness and
            allowed values are defined by this schema.
        origination_id:
          type: string
          minLength: 1
          description: >-
            Opaque identifier, authorized within the API key workspace and
            environment.
        requirement_id:
          type: string
          minLength: 1
          description: >-
            Opaque identifier, authorized within the API key workspace and
            environment.
      required:
        - file
        - context
        - document_type
      additionalProperties: false
      allOf:
        - if:
            properties:
              context:
                const: borrower
          then:
            required:
              - borrower_id
          else:
            not:
              anyOf:
                - required:
                    - borrower_id
                - required:
                    - origination_id
                - required:
                    - requirement_id
        - if:
            required:
              - requirement_id
          then:
            required:
              - origination_id
      description: >-
        Upload once, then reference document ID in the origination. A later
        upload may include origination_id and an open requirement_id: borrower
        and requirement ownership are checked and association occurs atomically.
        Late attachment is accepted only while collecting/requires_action,
        otherwise 409. Never overwrite a file or change a completed assessment.
    Document:
      type: object
      properties:
        id:
          type: string
          minLength: 1
          description: >-
            Opaque identifier, authorized within the API key workspace and
            environment.
        context:
          type: string
          enum:
            - borrower
            - lending_product
            - risk_policy
          description: >-
            Context for Document. Constraints, requiredness and allowed values
            are defined by this schema.
        borrower_id:
          anyOf:
            - type: string
              minLength: 1
              description: >-
                Opaque identifier, authorized within the API key workspace and
                environment.
            - type: 'null'
          description: >-
            Borrower that owns this resource; must match the key workspace and
            environment.
        file_name:
          type: string
          minLength: 1
          description: >-
            File name for Document. Constraints, requiredness and allowed values
            are defined by this schema.
        mime_type:
          type: string
          minLength: 1
          description: >-
            Mime type for Document. Constraints, requiredness and allowed values
            are defined by this schema.
        sha256:
          type: string
          minLength: 1
          pattern: ^[a-f0-9]{64}$
          description: >-
            Sha256 for Document. Constraints, requiredness and allowed values
            are defined by this schema.
        size_bytes:
          type: integer
          minimum: 0
          description: >-
            Size bytes for Document. Constraints, requiredness and allowed
            values are defined by this schema.
        status:
          type: string
          enum:
            - processing
            - available
            - rejected
            - restricted
          description: >-
            Current lifecycle state. See the product lifecycle and recovery
            guides.
        restriction_reason:
          anyOf:
            - type: string
              minLength: 1
            - type: 'null'
          description: >-
            Restriction reason for Document. Constraints, requiredness and
            allowed values are defined by this schema.
        created_at:
          type: string
          minLength: 1
          format: date-time
          description: UTC time the record was created.
        document_type:
          type: string
          minLength: 1
          description: >-
            Document type for Document. Constraints, requiredness and allowed
            values are defined by this schema.
        origination_id:
          anyOf:
            - type: string
              minLength: 1
              description: Opaque ID within the authorized workspace and environment.
            - type: 'null'
          description: >-
            Origination id for Document. Constraints, requiredness and allowed
            values are defined by this schema.
        requirement_id:
          anyOf:
            - type: string
              minLength: 1
              description: Opaque ID within the authorized workspace and environment.
            - type: 'null'
          description: >-
            Requirement id for Document. Constraints, requiredness and allowed
            values are defined by this schema.
        origin:
          type: string
          enum:
            - institution_upload
            - borrower_upload
            - integration
            - amlok_generated
          description: >-
            Origin for Document. Constraints, requiredness and allowed values
            are defined by this schema.
        record_version:
          type: integer
          minimum: 1
          description: >-
            Monotonically increasing version of this resource. Compare with
            event.resource_version; snapshot reads preserve their historical
            version.
        failure:
          anyOf:
            - $ref: '#/components/schemas/Error'
            - type: 'null'
          description: >-
            Failure for Document. Constraints, requiredness and allowed values
            are defined by this schema.
      required:
        - id
        - context
        - borrower_id
        - file_name
        - mime_type
        - sha256
        - size_bytes
        - status
        - restriction_reason
        - created_at
        - document_type
        - origination_id
        - requirement_id
        - origin
        - record_version
        - failure
      additionalProperties: false
      allOf:
        - if:
            properties:
              status:
                const: rejected
          then:
            properties:
              failure:
                $ref: '#/components/schemas/Error'
          else:
            properties:
              failure:
                type: 'null'
    Meta:
      type: object
      properties:
        request_id:
          type: string
          minLength: 1
          description: >-
            Opaque identifier, authorized within the API key workspace and
            environment.
        schema_version:
          type: string
          minLength: 1
          description: >-
            Schema version for Meta. Constraints, requiredness and allowed
            values are defined by this schema.
        environment:
          type: string
          enum:
            - sandbox
            - live
          description: >-
            Environment for Meta. Constraints, requiredness and allowed values
            are defined by this schema.
      required:
        - request_id
        - schema_version
        - environment
      additionalProperties: false
    Error:
      type: object
      properties:
        code:
          type: string
          enum:
            - validation_error
            - unauthenticated
            - forbidden
            - not_found
            - invalid_state
            - idempotency_conflict
            - insufficient_credits
            - precondition_failed
            - cursor_expired
            - rate_limited
            - temporarily_unavailable
            - deal_snapshot_conflict
            - payload_too_large
            - unsupported_media_type
            - document_rejected
            - processing_failed
            - session_expired
            - consent_purpose_missing
            - sandbox_only
            - scenario_not_available
            - idempotency_result_expired
          description: >-
            Code for Error. Constraints, requiredness and allowed values are
            defined by this schema.
        message:
          type: string
          minLength: 1
          description: >-
            Message for Error. Constraints, requiredness and allowed values are
            defined by this schema.
        retryable:
          type: boolean
          description: >-
            Retryable for Error. Constraints, requiredness and allowed values
            are defined by this schema.
        request_id:
          type: string
          minLength: 1
          description: >-
            Opaque identifier, authorized within the API key workspace and
            environment.
        field:
          anyOf:
            - type: string
              minLength: 1
            - type: 'null'
          description: >-
            Field for Error. Constraints, requiredness and allowed values are
            defined by this schema.
      required:
        - code
        - message
        - retryable
        - request_id
        - field
      additionalProperties: false
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: >-
        Server-to-server API key bound to exactly one workspace, institution
        tenant and environment. No caller-supplied workspace override is
        accepted. Do not use in public browser code.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.