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

# Create or update documents

> Up to 100 documents and 8 MB in one call (larger documents fit fewer: send the rest in another call), each as the single call does, with a result for each in request order: created, updated, unchanged, or failed with the error alone that document would have had. One that fails leaves the rest written. Each counts against your rate limit. A document is identified by your `external_id`, unique in its knowledge base (titles may repeat). Its words are stored and indexed in the background: the previous version keeps answering until the new one is ready. The same words, title and link again are `unchanged`: nothing is written or indexed again. A 503 that says the document was saved but its indexing could not be started: send it again, and indexing is asked for again. Writes go into a knowledge base this API made or one that takes uploads in the app (`writable`); a connector's is a 409. A digital worker's own key can't write.



## OpenAPI

````yaml /api/statisfy-api.openapi.json post /v1/knowledge_bases/{knowledge_base_id}/documents/batch/upsert
openapi: 3.1.0
info:
  description: >-
    The agent-first Statisfy API. Authenticate with an API key (`Authorization:
    Bearer stfy_live_…`), then call `GET /v1/meta/capabilities` to discover
    every operation and its schemas.
  title: Statisfy API
  version: 1.0.0
servers:
  - url: https://api.statisfy.com
    description: Production
security: []
paths:
  /v1/knowledge_bases/{knowledge_base_id}/documents/batch/upsert:
    post:
      tags:
        - knowledge_bases
      summary: Create or update documents
      description: >-
        Up to 100 documents and 8 MB in one call (larger documents fit fewer:
        send the rest in another call), each as the single call does, with a
        result for each in request order: created, updated, unchanged, or failed
        with the error alone that document would have had. One that fails leaves
        the rest written. Each counts against your rate limit. A document is
        identified by your `external_id`, unique in its knowledge base (titles
        may repeat). Its words are stored and indexed in the background: the
        previous version keeps answering until the new one is ready. The same
        words, title and link again are `unchanged`: nothing is written or
        indexed again. A 503 that says the document was saved but its indexing
        could not be started: send it again, and indexing is asked for again.
        Writes go into a knowledge base this API made or one that takes uploads
        in the app (`writable`); a connector's is a 409. A digital worker's own
        key can't write.
      operationId: knowledge_bases_batch_upsert_documents
      parameters:
        - description: The knowledge base's id, from GET /v1/knowledge_bases
          in: path
          name: knowledge_base_id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: false
              properties:
                items:
                  items:
                    $ref: '#/components/schemas/DocumentFields'
                  maxItems: 100
                  minItems: 1
                  title: Items
                  type: array
              required:
                - items
              type: object
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchUpsertResult'
          description: Successful Response
      security:
        - HTTPBearer: []
components:
  schemas:
    DocumentFields:
      additionalProperties: false
      properties:
        content:
          description: >-
            Its words, up to 256 KB (UTF-8): a larger document is refused, never
            cut short
          minLength: 1
          title: Content
          type: string
        external_id:
          description: Your id for the document, unique in its knowledge base
          maxLength: 200
          minLength: 1
          title: External Id
          type: string
        format:
          description: 'How content is written: markdown, html or text'
          enum:
            - markdown
            - html
            - text
          title: Format
          type: string
        title:
          description: 'Its title: a worker sees it beside each passage'
          maxLength: 500
          minLength: 1
          title: Title
          type: string
        url:
          anyOf:
            - maxLength: 2048
              type: string
            - type: 'null'
          default: null
          description: >-
            The link a worker gives a customer when it answers from this
            document (an http or https URL). Without one, the worker names the
            document without a link
          title: Url
      required:
        - external_id
        - title
        - content
        - format
      title: DocumentFields
      type: object
    BatchUpsertResult:
      properties:
        items:
          description: In request order
          items:
            $ref: '#/components/schemas/BatchUpsertItem'
          title: Items
          type: array
      required:
        - items
      title: BatchUpsertResult
      type: object
    BatchUpsertItem:
      properties:
        document_id:
          anyOf:
            - type: string
            - type: 'null'
          description: Set unless the document could not be saved
          title: Document Id
        error:
          anyOf:
            - $ref: '#/components/schemas/ItemError'
            - type: 'null'
          description: Set exactly when `status` is `failed`
        external_id:
          title: External Id
          type: string
        status:
          enum:
            - created
            - updated
            - unchanged
            - failed
          title: Status
          type: string
      required:
        - external_id
        - status
      title: BatchUpsertItem
      type: object
    ItemError:
      description: The error envelope a single request would have returned.
      properties:
        code:
          title: Code
          type: string
        details:
          items:
            additionalProperties: true
            type: object
          title: Details
          type: array
        message:
          title: Message
          type: string
      required:
        - code
        - message
      title: ItemError
      type: object
  securitySchemes:
    HTTPBearer:
      scheme: bearer
      type: http
      description: >-
        An API key, sent as `Authorization: Bearer stfy_live_…`. See
        [Authentication](/rest-api/authentication) for how to get one and which
        scopes it needs.

````

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