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

# Add a fact

> Save one fact in your own memory or an app user's memory.

A key set to memory for each user of your app must send the user's id in
`x-atlaso-user`; without it the call gets 400 `memory_scope_per_user`. A key
whose **Memory for** is **Me** reaches your own memory and sends no
`x-atlaso-user`; with it, the call gets 403 `memory_scope_owner`.

Send an `Idempotency-Key` header to make a retry safe: a resend with the same key
and the same text within 24 hours saves nothing new. The 409 answers are listed
in [Memory API errors](https://docs.atlaso.ai/gateway/errors.md#memory-api-errors). See
[Memory API](https://docs.atlaso.ai/gateway/memory-api.md).


## OpenAPI

````yaml api-reference/openapi.json POST /memory/facts
openapi: 3.1.0
info:
  title: Atlaso Gateway API
  version: 1.0.0
  description: An OpenAI-compatible API that calls your own provider keys and adds memory.
servers:
  - url: https://api.atlaso.ai/v1
security:
  - AtlasoKey: []
paths:
  /memory/facts:
    post:
      tags:
        - Memory
      summary: Add a fact
      description: >-
        Saves one fact. With a key set to memory for each user of your app, it
        goes into the memory of the app user named by `x-atlaso-user`. With a
        key whose Memory for is Me, send no `x-atlaso-user`: it goes into your
        own memory, in the key's project or, for a key with no project, your
        personal facts. Send an `Idempotency-Key` to make a retry safe. See
        [Memory API](/gateway/memory-api).
      operationId: addMemoryFact
      parameters:
        - $ref: '#/components/parameters/AppUser'
        - name: Idempotency-Key
          in: header
          required: false
          description: >-
            Makes a retry safe. 1 to 255 printable ASCII characters, sent once.
            Resending the same body with the same key within 24 hours returns
            the first answer instead of saving again, with
            `x-atlaso-idempotent-replay: true`. The same key with a different
            body gets 409 `idempotency_key_reused`; a resend while the first
            request is still saving gets 409 `idempotency_in_progress`. A
            malformed or repeated header gets 400 `invalid_idempotency_key`. Do
            not send it as a body field. The Atlaso SDK sends one for you.
          schema:
            type: string
            minLength: 1
            maxLength: 255
          example: add-7f3c2a
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - text
              additionalProperties: false
              properties:
                text:
                  type: string
                  minLength: 1
                  maxLength: 4000
                  description: The fact. Not only spaces, no NUL characters.
                  example: Prefers oat-milk lattes.
                user:
                  type: string
                  description: >-
                    Never read as the id. Equal to `x-atlaso-user` it is
                    ignored; different, the call is refused with 400
                    `user_id_conflict`.
              example:
                text: Prefers oat-milk lattes.
      responses:
        '200':
          description: The saved fact.
          headers:
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
            x-request-id:
              $ref: '#/components/headers/RequestId'
            cache-control:
              $ref: '#/components/headers/NoStore'
            x-atlaso-idempotent-replay:
              description: >-
                `true` when this answer replays an earlier request with the same
                `Idempotency-Key`. Absent otherwise.
              schema:
                type: string
                enum:
                  - 'true'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Fact'
        '400':
          description: >-
            The request or the app user's id was refused. Codes:
            `memory_scope_per_user`, `missing_user_id`, `user_id_not_accepted`,
            `user_id_conflict`, `invalid_body`, `unknown_field`, `missing_text`,
            `invalid_text`, `invalid_idempotency_key`, `fact_rejected`.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    This key keeps memory for each user of your app. Use
                    atlaso.for_user(id).memory.
                  type: invalid_request_error
                  param: x-atlaso-user
                  code: memory_scope_per_user
                  doc_url: https://docs.atlaso.ai/gateway/errors#memory_scope_per_user
        '401':
          description: >-
            The Atlaso key is missing, invalid or revoked. Codes:
            `invalid_api_key`.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
            x-should-retry:
              description: >-
                `false`. Sent with `invalid_api_key`, when retrying soon cannot
                help. The OpenAI SDKs read it.
              schema:
                type: string
                enum:
                  - 'false'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    Your Atlaso API key is missing, invalid or revoked. Set
                    Authorization: Bearer to an active key from the API keys
                    page.
                  type: authentication_error
                  param: null
                  code: invalid_api_key
                  doc_url: https://docs.atlaso.ai/gateway/errors#invalid_api_key
        '403':
          description: >-
            The key or this request cannot use the Memory API. Codes:
            `memory_scope_owner` (a Me key sent `x-atlaso-user` or a body
            `user`), `memory_off` (a Me key whose memory is Off),
            `gateway_not_enabled`, `app_user_limit_reached`.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
            x-should-retry:
              description: >-
                `false`. Sent only with `gateway_not_enabled`, when retrying
                soon cannot help. The OpenAI SDKs read it.
              schema:
                type: string
                enum:
                  - 'false'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    This key uses your own memory. Use atlaso.memory, without a
                    user id.
                  type: permission_error
                  param: x-atlaso-user
                  code: memory_scope_owner
                  doc_url: https://docs.atlaso.ai/gateway/errors#memory_scope_owner
        '409':
          description: >-
            This `Idempotency-Key` cannot be used for this request now. Codes:
            `idempotency_in_progress` (the first request with this key is still
            saving: wait for `Retry-After`, then resend the same body with the
            same key), `idempotency_key_reused` (the key was used in the last 24
            hours for a different request: use a new key), `fact_replaced` (the
            fact saved with this key was later replaced or deleted:
            `replaced_by` is the current fact's id, or null when it was
            deleted). Nothing new was saved.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
            retry-after:
              $ref: '#/components/headers/RetryAfter'
            x-should-retry:
              description: >-
                `false`. Sent with `idempotency_key_reused`, when retrying with
                the same key cannot help. The OpenAI SDKs read it.
              schema:
                type: string
                enum:
                  - 'false'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    This request is still being saved. Retry with the same
                    Idempotency-Key.
                  type: invalid_request_error
                  param: null
                  code: idempotency_in_progress
                  doc_url: >-
                    https://docs.atlaso.ai/gateway/errors#idempotency_in_progress
        '413':
          description: 'The body is over 64 KiB. Codes: `request_too_large`.'
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: The body must be at most 65536 bytes.
                  type: invalid_request_error
                  param: null
                  code: request_too_large
                  doc_url: https://docs.atlaso.ai/gateway/errors#request_too_large
        '429':
          description: 'Too many requests on this key. Codes: `rate_limited`.'
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
            retry-after:
              $ref: '#/components/headers/RetryAfter'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Too many requests. Try again shortly.
                  type: rate_limit_error
                  param: null
                  code: rate_limited
                  doc_url: https://docs.atlaso.ai/gateway/errors#rate_limited
        '503':
          description: >-
            Memory is not reachable right now, or a deletion for this user has
            not finished. Safe to retry. Codes: `memory_unavailable`,
            `delete_pending`, `unavailable`, `not_configured`.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-atlaso-memory:
              $ref: '#/components/headers/MemoryReceipt'
            x-atlaso-paid-by:
              $ref: '#/components/headers/PaidBy'
            retry-after:
              $ref: '#/components/headers/RetryAfter'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    A deletion for this user has not finished yet. Retry the
                    same request in a few seconds; retrying is safe.
                  type: api_error
                  param: null
                  code: delete_pending
                  doc_url: https://docs.atlaso.ai/gateway/errors#delete_pending
components:
  parameters:
    AppUser:
      name: x-atlaso-user
      in: header
      required: false
      description: >-
        Your app user's id, set by your server. A key set to memory for each
        user of your app must send it on every call; without it the call gets
        400 `memory_scope_per_user`, and an empty value gets 400
        `missing_user_id`. A key whose Memory for is Me reaches your own memory
        and must not send it: with it, the call gets 403 `memory_scope_owner`
        and nothing is read or written. 1 to 256 printable characters, not only
        spaces, with no API key or token in it. Send it once. Used exactly as
        sent.
      schema:
        type: string
        minLength: 1
        maxLength: 256
      example: demo-user-42
  headers:
    MemoryReceipt:
      description: >-
        What memory did: `status=...; ids=...; ms=...; reason=...; added=...;
        action=...`. `status` is `used`, `none`, `skipped`, `off` or `bypass`.
        With `x-atlaso-memory: off` it reads `status=off` and
        `reason=request_off`; a key whose memory is off gives
        `reason=key_mode_off`. Routes that do not use memory say
        `status=bypass`.
      schema:
        type: string
      example: status=none; ids=; ms=38; reason=no_match; added=0; action=none
    PaidBy:
      description: 'Always `own_key`: the provider bills your own key.'
      schema:
        type: string
        enum:
          - own_key
      example: own_key
    RequestId:
      description: Atlaso's id for this request. Quote it to support.
      schema:
        type: string
      example: req_4f1c2e9a7b6d4c3e8a1f0b2d
    NoStore:
      description: Answers are never cached.
      schema:
        type: string
      example: no-store
    RetryAfter:
      description: Seconds to wait before retrying.
      schema:
        type: string
      example: '2'
  schemas:
    Fact:
      type: object
      required:
        - id
        - object
        - created
        - text
        - source
        - app_user
      properties:
        id:
          type: string
          format: uuid
        object:
          type: string
          enum:
            - memory.fact
        created:
          type: integer
          description: Unix seconds.
        text:
          type: string
          description: >-
            The stored fact. Stored text may differ from the input: recognised
            passwords, API keys and tokens are redacted, but unrecognised
            secrets and other sensitive details can remain.
        source:
          type: string
          enum:
            - api
            - learned
            - dashboard
        app_user:
          type: string
          description: A 12-character label for the app user, not the id you sent.
      example:
        id: 0b6f3c1e-2a4d-4e8f-9c1b-5d7e6f8a9b0c
        object: memory.fact
        created: 1763366400
        text: Prefers oat-milk lattes.
        source: api
        app_user: 3f9a1c7e5b2d
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
            - param
            - code
            - doc_url
          properties:
            message:
              type: string
              description: What happened and what to do.
            type:
              type: string
              description: Error type, as OpenAI uses it.
              example: invalid_request_error
            param:
              type:
                - string
                - 'null'
              description: The field or header at fault, if any.
            code:
              type: string
              description: A stable code. A provider's own code may appear too.
            doc_url:
              type: string
              format: uri
              description: Where this code is explained on the Errors page.
  securitySchemes:
    AtlasoKey:
      type: http
      scheme: bearer
      bearerFormat: sk-at-...
      description: >-
        Your Atlaso key in `Authorization: Bearer sk-at-...`. Send one
        Authorization header. A request that also sends `x-atlaso-key` is
        refused with 401.

````

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