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

# Write memory

> Creates or replaces a memory document or an operational rule.

Set `kind` to `document` (the default) or `rule`. The Body section marks each field as document only or rule only.

Documents require the **write:memory** scope. Rules require the **write:operational-rules** scope and an API key with an owner.

A document write replaces the full file. To replace a document, read it first and send its organization-layer version as `expected_version`. Document text is reference information; it does not change accounting controls.

A saved rule applies to later classification and cash-application runs. It does not process transactions now; to classify selected transactions now, use [Classify transactions](/docs/api-reference/accounting/classification/classify-transactions). Rules apply only to your organization and do not inherit firm documents.

Returns the saved document path, or the saved rule and its `outcome`. The document response does not include the new version; read the document again to get it.

<RequestExample dropdown>
  ```bash cURL theme={null}
  curl --request PUT \
    --url 'https://api.entendre.finance/v1/memory/file?path=knowledge/vendors.md' \
    --header 'Content-Type: application/json' \
    --header 'X-API-Key: <api-key>' \
    --data '{
      "content": "Treat approved staking rewards as revenue.",
      "rationale": "Record the approved treatment of staking rewards.",
      "expected_version": null
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.entendre.finance/v1/memory/file?path=knowledge/vendors.md', {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': '<api-key>',
    },
    body: JSON.stringify({
      content: 'Treat approved staking rewards as revenue.',
      rationale: 'Record the approved treatment of staking rewards.',
      expected_version: null,
    }),
  });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  console.log(await response.json());
  ```

  ```python Python theme={null}
  import requests

  response = requests.put(
      "https://api.entendre.finance/v1/memory/file",
      params={
          "path": "knowledge/vendors.md"
      },
      headers={"X-API-Key": "<api-key>"},
      json={
          "content": "Treat approved staking rewards as revenue.",
          "rationale": "Record the approved treatment of staking rewards.",
          "expected_version": None
      },
      timeout=30,
  )
  response.raise_for_status()
  print(response.json())
  ```
</RequestExample>


## OpenAPI

````yaml openapi-public-preview.json PUT /v1/memory/file
openapi: 3.1.0
info:
  title: Entendre API
  version: 1.0.0
  description: Programmatic access to crypto-native accounting and treasury operations.
servers:
  - url: https://api.entendre.finance
    description: Production API.
security:
  - ApiKey: []
tags:
  - name: Organization
    description: Read your organization profile and find members for agent assignments.
  - name: Transactions
    description: Find transactions, inspect their details and create manual records.
  - name: Sources
    description: >-
      Manage wallets, exchange accounts, bank accounts and other transaction
      sources.
  - name: Assets
    description: Inspect asset acquisitions, remaining quantities and cost basis.
  - name: Journals
    description: >-
      Create and post journal entries, correct eligible entries and sync posted
      journals to a connected general ledger.
  - name: Documents
    description: >-
      Upload documents, check processing status and link supporting evidence to
      transactions.
  - name: Legal Entities
    description: Manage the legal entities used in your accounting records.
  - name: Ledger Accounts
    description: Manage your chart of accounts and find accounts for journal entries.
  - name: Tags
    description: Create and manage tags to classify your records.
  - name: Accruals
    description: >-
      Create and post accruals, inspect their status and reverse eligible
      entries.
  - name: Cash Application
    description: Match deposits to invoices and manage the resulting cash applications.
  - name: Classification
    description: >-
      Classify transactions in a batch, post eligible entries and inspect the
      results.
  - name: Revaluation
    description: Run asset revaluations for an accounting period and check their results.
  - name: Accounting Periods
    description: Check whether a period is ready to close, then close or reopen it.
  - name: Income Statement
    description: View revenue, expenses and net income for a reporting period.
  - name: Balance Sheet
    description: View assets, liabilities and equity as of a reporting date.
  - name: Trial Balance
    description: Review ledger account balances and debit and credit totals.
  - name: Closing Positions
    description: View asset positions at the end of a reporting period.
  - name: Treasury Balances
    description: Review treasury balances by asset and source.
  - name: Realized Gains & Losses
    description: Review realized gains and losses from asset dispositions.
  - name: Asset Tax Lots
    description: Inspect asset tax lots, remaining quantities and cost basis.
  - name: Schedule of Dispositions
    description: >-
      Review asset dispositions and their proceeds, cost basis and gains or
      losses.
  - name: Financial Insights
    description: Review financial insights for your selected reporting context.
  - name: Agents
    description: Create agents, schedule their work and inspect their runs.
  - name: Memory
    description: Read, search and maintain the memory files your agents use.
  - name: Connections
    description: Connect providers, manage authorization and disconnect.
  - name: GL Mapping
    description: >-
      Map ledger accounts and legal entities to your ERP. Import legal entities,
      tags and chart of accounts.
  - name: Request
    description: Request information, documents or connections from a client.
  - name: Client
    description: Manage your firm’s client relationships.
  - name: Team
    description: Invite team members and manage their access to your firm.
  - name: Settings
    description: Read and update your firm settings.
paths:
  /v1/memory/file:
    put:
      tags:
        - Memory
      summary: Write memory
      description: >-
        Writes a memory document or an operational rule. Set `kind` to
        `document` (the default) or `rule`. Each body field is marked as
        document only or rule only.


        Documents require the **write:memory** scope. Rules require the
        **write:operational-rules** scope and an API key with an owner.


        A document write replaces the full file. To replace a document, read it
        first and send its organization-layer version as `expected_version`.
        Document text is reference information; it does not change accounting
        controls.


        A saved rule applies to later classification and cash-application runs.
        It does not process transactions now; to classify selected transactions
        now, use Classify transactions. Rules apply only to your organization
        and do not inherit firm documents.


        Returns the saved document path, or the saved rule and its `outcome`.
        The document response does not include the new version; read the
        document again to get it.
      operationId: writeMemory
      parameters:
        - name: kind
          in: query
          required: false
          description: >-
            `document` (the default) for a memory document, or `rule` for an
            operational rule.
          schema:
            type: string
            enum:
              - document
              - rule
            default: document
        - name: path
          in: query
          required: false
          schema:
            type: string
            minLength: 1
          description: >-
            Document only, and required for documents. Relative path of a
            Markdown or YAML file, such as `knowledge/vendors.md`. Use
            `profile.md`, `clients.yaml`, or a file in a folder. You cannot
            write JSON or JSONL files, or files in `refs/`, `journal/`,
            `artifacts/`, `timeline/`, `workstreams/`, `knowledge/facts/`,
            `knowledge/preferences/` or `knowledge/decisions/`. A skill must be
            `skills/{slug}/SKILL.md`. Firm documents allow only `policy/`,
            `knowledge/`, `skills/`, `profile.md` and `clients.yaml`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                content:
                  type: string
                  maxLength: 200000
                  description: >-
                    Document only, and required for documents. The full file
                    body. A write replaces the file; it never merges.
                rationale:
                  type: string
                  minLength: 1
                  maxLength: 2000
                  description: >-
                    Document only, and required for documents. Why you make this
                    change. It is recorded with the document.
                expected_version:
                  type:
                    - string
                    - 'null'
                  description: >-
                    Document only, and required for documents. The `version` you
                    read for this path, or `null` to create a new file. A
                    mismatch returns HTTP 409.
                domain:
                  type: string
                  enum:
                    - classification
                    - cash_application
                  description: >-
                    Rule only. `classification` for transaction rules, or
                    `cash_application` for deposit matching rules.
                description_contains:
                  type: string
                  description: >-
                    Rule only. Classification rules: text that matches the memo
                    or payee of a bank transaction. Saved and returned in
                    lowercase. Matching ignores case.
                source_category:
                  type: string
                  description: >-
                    Rule only. For classification rules: source-platform
                    metadata category (Plaid personal-finance category, Ramp
                    accounting category). Preferred for a class of transactions.
                merchant_name:
                  type: string
                  description: >-
                    Rule only. For classification rules: merchant match for card
                    spend (Ramp/Raincard).
                blockchain_address:
                  type: string
                  description: >-
                    Rule only. Classification rules: address that matches the
                    from or to address. Saved and returned in lowercase.
                    Matching ignores case.
                asset_type:
                  type: string
                  description: >-
                    Rule only. For classification rules: asset match for crypto
                    transactions (USDC, ETH, …).
                direction:
                  type: string
                  enum:
                    - DEPOSIT
                    - WITHDRAWAL
                    - ANY
                  description: >-
                    Rule only. For classification rules: direction constraint.
                    Defaults to ANY.
                category_ledger_account_id:
                  type: string
                  description: >-
                    Rule only. Required for classification rules: the ledger
                    account matching transactions are classified to. Get it from
                    List ledger accounts.
                resolved_payee:
                  type: string
                  description: >-
                    Rule only. For classification rules: clean payee name for
                    display.
                default_tag_id:
                  type: string
                  description: >-
                    Rule only. For classification rules: tag applied to matching
                    transactions.
                title:
                  type: string
                  description: >-
                    Rule only. Required for cash-application rules: short
                    human-readable rule name.
                statement:
                  type: string
                  description: >-
                    Rule only. Required for cash-application rules:
                    natural-language statement of the rule.
                cash_application_action:
                  type: string
                  enum:
                    - route_to_account
                    - require_human_review
                  description: >-
                    Rule only. For cash-application rules: defaults to
                    `route_to_account`.
                matcher:
                  type: string
                  description: >-
                    Rule only. Required for cash-application rules: the exact
                    phrase matched against invoice line descriptions / product
                    names. Supply the SKU or product text verbatim.
                match_operator:
                  type: string
                  enum:
                    - exact
                    - contains
                  description: >-
                    Rule only. For cash-application rules: `contains` (default)
                    fires when the line text contains the matcher anywhere;
                    `exact` requires the normalized line label to equal it.
                ledger_account_id:
                  type: string
                  description: >-
                    Rule only. Required for cash-application rules with
                    `route_to_account`: target ledger account id. It is not
                    inferred from the rule text.
                ledger_account_name:
                  type: string
                  description: >-
                    Rule only. Required for cash-application rules with
                    `route_to_account`: name matching `ledger_account_id`, for
                    display and auditing.
              oneOf:
                - type: object
                  required:
                    - content
                    - rationale
                    - expected_version
                  properties:
                    content:
                      type: string
                      maxLength: 200000
                      description: >-
                        The full file body. A write replaces the file; it never
                        merges.
                    rationale:
                      type: string
                      minLength: 1
                      maxLength: 2000
                      description: >-
                        Why you make this change. It is recorded with the
                        document.
                    expected_version:
                      type:
                        - string
                        - 'null'
                      description: >-
                        The `version` you read for this path, or `null` to
                        create a new file. A mismatch returns HTTP 409.
                  additionalProperties: false
                - type: object
                  required:
                    - domain
                  properties:
                    domain:
                      type: string
                      enum:
                        - classification
                        - cash_application
                      description: >-
                        `classification` for transaction rules, or
                        `cash_application` for deposit matching rules.
                    description_contains:
                      type: string
                      description: >-
                        Classification rules: text that matches the memo or
                        payee of a bank transaction. Saved and returned in
                        lowercase. Matching ignores case.
                    source_category:
                      type: string
                      description: >-
                        For classification rules: source-platform metadata
                        category (Plaid personal-finance category, Ramp
                        accounting category). Preferred for a class of
                        transactions.
                    merchant_name:
                      type: string
                      description: >-
                        For classification rules: merchant match for card spend
                        (Ramp/Raincard).
                    blockchain_address:
                      type: string
                      description: >-
                        Classification rules: address that matches the from or
                        to address. Saved and returned in lowercase. Matching
                        ignores case.
                    asset_type:
                      type: string
                      description: >-
                        For classification rules: asset match for crypto
                        transactions (USDC, ETH, …).
                    direction:
                      type: string
                      enum:
                        - DEPOSIT
                        - WITHDRAWAL
                        - ANY
                      description: >-
                        For classification rules: direction constraint. Defaults
                        to ANY.
                    category_ledger_account_id:
                      type: string
                      description: >-
                        Required for classification rules: the ledger account
                        matching transactions are classified to. Get it from
                        List ledger accounts.
                    resolved_payee:
                      type: string
                      description: 'For classification rules: clean payee name for display.'
                    default_tag_id:
                      type: string
                      description: >-
                        For classification rules: tag applied to matching
                        transactions.
                    title:
                      type: string
                      description: >-
                        Required for cash-application rules: short
                        human-readable rule name.
                    statement:
                      type: string
                      description: >-
                        Required for cash-application rules: natural-language
                        statement of the rule.
                    cash_application_action:
                      type: string
                      enum:
                        - route_to_account
                        - require_human_review
                      description: >-
                        For cash-application rules: defaults to
                        `route_to_account`.
                    matcher:
                      type: string
                      description: >-
                        Required for cash-application rules: the exact phrase
                        matched against invoice line descriptions / product
                        names. Supply the SKU or product text verbatim.
                    match_operator:
                      type: string
                      enum:
                        - exact
                        - contains
                      description: >-
                        For cash-application rules: `contains` (default) fires
                        when the line text contains the matcher anywhere;
                        `exact` requires the normalized line label to equal it.
                    ledger_account_id:
                      type: string
                      description: >-
                        Required for cash-application rules with
                        `route_to_account`: target ledger account id. It is not
                        inferred from the rule text.
                    ledger_account_name:
                      type: string
                      description: >-
                        Required for cash-application rules with
                        `route_to_account`: name matching `ledger_account_id`,
                        for display and auditing.
                  additionalProperties: false
            example:
              content: Treat approved staking rewards as revenue.
              rationale: Record the approved treatment of staking rewards.
              expected_version: null
      responses:
        '200':
          description: The organization memory file was saved.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/MemoryWriteResult'
                  - type: object
                    required:
                      - data
                    properties:
                      data:
                        type: object
                        required:
                          - outcome
                          - rule_id
                          - domain
                          - version
                          - summary
                          - rule
                        properties:
                          outcome:
                            type: string
                            enum:
                              - created
                              - already_exists
                              - replaced
                            description: >-
                              `created` for a new rule, `already_exists` when
                              the same rule exists (nothing changes), or
                              `replaced` when a rule with the same match now has
                              the new target.
                          rule_id:
                            type: string
                            description: Rule ID.
                          domain:
                            type: string
                            enum:
                              - classification
                              - cash_application
                            description: Rule domain.
                          version:
                            type: string
                            description: Version stamp of the rules file after the write.
                          summary:
                            type: string
                            description: Human-readable outcome summary.
                          rule:
                            $ref: '#/components/schemas/OperationalRule'
                        description: The result.
              example:
                success: true
                path: knowledge/vendors.md
                layer: org
                rationale: Record the approved treatment of staking rewards.
        '400':
          description: Invalid path, query or request body.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MemoryErrorResponse'
              example:
                error:
                  code: VALIDATION_ERROR
                  message: Invalid path, query or request body.
                  request_id: req_example
        '401':
          description: The API key is missing, invalid or expired.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MemoryErrorResponse'
              example:
                error:
                  code: UNAUTHORIZED
                  message: Authentication is required.
                  request_id: req_example
        '403':
          description: The API key does not have the required scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MemoryErrorResponse'
              example:
                error:
                  code: FORBIDDEN
                  message: Insufficient access to organization
                  request_id: req_example
        '409':
          description: >-
            The supplied version does not match the organization file. Read it
            again before deciding to replace it.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MemoryErrorResponse'
              example:
                error:
                  code: CONFLICT
                  message: >-
                    The supplied version does not match the organization file.
                    Read it again before deciding to replace it.
                  request_id: req_example
        '429':
          description: >-
            Too many requests. If the response has a `Retry-After` header, wait
            that many seconds before you retry. Otherwise, read `error.message`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MemoryErrorResponse'
              example:
                error:
                  code: RATE_LIMITED
                  message: Rate limit exceeded. Retry after 30s.
                  request_id: req_example
        '502':
          description: Memory is temporarily unavailable. Retry later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MemoryErrorResponse'
              example:
                error:
                  code: PROVIDER_ERROR
                  message: The memory service is temporarily unavailable.
                  request_id: req_example
components:
  schemas:
    MemoryWriteResult:
      type: object
      required:
        - success
        - path
        - layer
        - rationale
      properties:
        success:
          type: boolean
          description: '`true` when the file was saved.'
        path:
          type: string
          description: Relative file path.
        layer:
          type: string
          enum:
            - org
          description: The layer written. This endpoint writes organization scope only.
        rationale:
          type: string
          description: The rationale recorded with the write.
    OperationalRule:
      type: object
      required:
        - rule_id
        - domain
        - title
        - statement
        - created_at
      properties:
        rule_id:
          type: string
          description: >-
            Rule ID (such as `rule_ab12cd34`). Pass it as `rule_id` to Delete
            memory with `kind=rule`.
        domain:
          type: string
          enum:
            - classification
            - cash_application
          description: >-
            Rule type: `classification` (transaction categorization) or
            `cash_application` (invoice/deposit matching).
        title:
          type: string
          description: Short human-readable rule name.
        statement:
          type: string
          description: Human-readable summary of what the rule matches and where it routes.
        created_at:
          type: string
          format: date-time
          description: Time the rule was created (ISO 8601).
        action:
          type: string
          enum:
            - route_to_account
            - require_human_review
          description: >-
            For cash-application rules: what the rule does when its matcher
            fires.
        matcher:
          type: string
          description: >-
            For cash-application rules: the verbatim matcher phrase compared
            against invoice line text.
        match_operator:
          type: string
          enum:
            - exact
            - contains
          description: >-
            For cash-application rules: how `matcher` is compared (`contains`
            fires on any occurrence; `exact` requires the normalized line label
            to equal it).
        normalized_matcher:
          type: string
          description: >-
            For cash-application rules: the matcher as Entendre compares it, in
            lowercase and without punctuation.
        ledger_account_id:
          type: string
          description: >-
            For cash-application rules with route_to_account: target ledger
            account.
        ledger_account_name:
          type: string
          description: Name of the target ledger account.
        ledger_account_archived:
          type: boolean
          description: >-
            Present and `true` only when the target ledger account is archived.
            The rule still routes to it, so change or delete the rule.
        description_contains:
          type: string
          description: >-
            Classification rules: text that matches the memo or payee. Returned
            in lowercase.
        source_category:
          type: string
          description: 'For classification rules: source-platform category matched.'
        merchant_name:
          type: string
          description: 'For classification rules: merchant name matched.'
        blockchain_address:
          type: string
          description: >-
            Classification rules: address that matches the from or to address.
            Returned in lowercase.
        asset_type:
          type: string
          description: 'For classification rules: asset symbol matched.'
        direction:
          type: string
          enum:
            - DEPOSIT
            - WITHDRAWAL
            - ANY
          description: 'For classification rules: transaction direction constraint.'
        category_ledger_account_id:
          type: string
          description: 'For classification rules: prefixed target ledger account id.'
        category_ledger_account_name:
          type: string
          description: 'For classification rules: target ledger account name.'
        category_ledger_account_archived:
          type: boolean
          description: >-
            For classification rules: present and true only when the category
            target ledger account is archived. Change or delete the rule.
        category_ledger_account_sequence:
          type:
            - integer
            - 'null'
          description: 'For classification rules: target ledger account sequence.'
        resolved_payee:
          type: string
          description: 'For classification rules: clean payee applied by the rule.'
        default_tag_id:
          type: string
          description: 'For classification rules: prefixed tag applied by the rule.'
    MemoryErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - request_id
          properties:
            code:
              type: string
              description: Machine-readable error code.
            message:
              type: string
              description: Technical description for developers.
            fields:
              type: object
              additionalProperties:
                type: string
              description: >-
                Present only on VALIDATION_ERROR. Maps failing field paths to
                reason strings.
            details:
              type: object
              additionalProperties: true
              description: >-
                Extra error details for agent operations. The keys can differ
                from the public field names; use them for diagnosis only.
            suggested_action:
              type: string
              description: A suggested next step.
            documentation_url:
              type: string
              format: uri
              description: Link to documentation about this error.
            request_id:
              type: string
              description: Unique request ID for support escalation.
          description: Error details.
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        Your organization API key. Some operations also need a key that is
        associated with a user; their pages say so.

````