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

# Create a collection

> Declare a collection of JSON documents addressed by key. This is the counterpart to facts: `POST /v1/memory` recalls by meaning, a collection recalls by key.

**Create it explicitly when you need `query`.** Writing to an unknown collection creates it implicitly, but with no indexes — and indexes cannot be added afterwards. If you will ever look items up by a field rather than by key, declare that field here, before the first write.

A collection is defined once for the project. Its ITEMS are per-scope, so the same collection holds a separate set of documents for the project, for each contact, and for each conversation.



## OpenAPI

````yaml /openapi.json post /v1/memory/collections
openapi: 3.0.3
info:
  title: Zavu Unified Messaging Layer API
  version: 0.2.0
  description: >
    Unified multi-channel messaging API for Zavu.


    Supported channels:

    - **SMS**: Simple text messages

    - **WhatsApp**: Rich messaging with media, buttons, lists, CTA URL buttons,
    location requests, and templates

    - **Telegram**: Bot messaging with text, media, and interactive elements

    - **Email**: Transactional emails via Amazon SES


    Design goals:

    - Simple `send()` entrypoint for developers

    - Project-level authentication via Bearer token

    - Support for all WhatsApp message types (text, image, video, audio,
    document, sticker, location, contact, buttons, list, cta_url,
    location_request, reaction, template)

    - If a non-text message type is sent, WhatsApp channel is used automatically

    - 24-hour WhatsApp conversation window enforcement

    - Universal `to` field accepts phone numbers (E.164), email addresses, or
    numeric chat IDs (Telegram/Instagram/Messenger)
servers:
  - url: https://api.zavu.dev
security:
  - bearerAuth: []
paths:
  /v1/memory/collections:
    post:
      tags:
        - Memory
      summary: Create a collection
      description: >-
        Declare a collection of JSON documents addressed by key. This is the
        counterpart to facts: `POST /v1/memory` recalls by meaning, a collection
        recalls by key.


        **Create it explicitly when you need `query`.** Writing to an unknown
        collection creates it implicitly, but with no indexes — and indexes
        cannot be added afterwards. If you will ever look items up by a field
        rather than by key, declare that field here, before the first write.


        A collection is defined once for the project. Its ITEMS are per-scope,
        so the same collection holds a separate set of documents for the
        project, for each contact, and for each conversation.
      operationId: createMemoryCollection
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MemoryCollectionCreateRequest'
            example:
              name: orders
              indexes:
                - field: status
      responses:
        '201':
          description: Collection created.
          content:
            application/json:
              schema:
                type: object
                required:
                  - collection
                properties:
                  collection:
                    $ref: '#/components/schemas/MemoryCollection'
        '400':
          description: Invalid name, index field, or TTL.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            A collection with that name already exists (`already_exists`), or
            one is still being deleted (`collection_deleting`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: The plan's collection cap is reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    MemoryCollectionCreateRequest:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: >-
            1-63 chars: lowercase letters, digits, `-` and `_`, starting with a
            letter or digit.
          example: orders
        indexes:
          type: array
          description: >-
            Up to 2 fields to index for `query`. **This is the only way to
            declare them** — a collection created implicitly by its first write
            has none, and querying an unindexed field returns `400
            field_not_indexed`. Indexes cannot be added later, so declare them
            here before the first write.
          maxItems: 2
          items:
            type: object
            required:
              - field
            properties:
              field:
                type: string
                description: >-
                  1-64 chars: letters, digits and `_`, starting with a letter.
                  Top-level field of the stored document.
                example: status
        defaultTtlSeconds:
          type: integer
          minimum: 60
          maximum: 63072000
    MemoryCollection:
      type: object
      description: A namespace of JSON documents addressed by key.
      required:
        - name
        - indexes
        - defaultTtlSeconds
        - status
        - createdAt
        - updatedAt
      properties:
        name:
          type: string
          example: orders
        indexes:
          type: array
          description: >-
            Fields that `POST /v1/memory/collections/{collection}/query` can
            filter on. Immutable after creation.
          items:
            type: object
            required:
              - field
            properties:
              field:
                type: string
        defaultTtlSeconds:
          type: integer
          nullable: true
          description: >-
            TTL applied to items written without their own `ttlSeconds`. Null
            means items are kept until deleted.
        status:
          type: string
          description: '`active`, or `deleting` while a delete drains in the background.'
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          example: invalid_request
        message:
          type: string
          example: Phone number is invalid
        details:
          type: object
          additionalProperties: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````