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

# Ingest a session's messages into a profile

> Store a session. Facts are extracted from whatever you send — the body is taken as any JSON value and stored whole, so a framework's own transcript shape works unchanged. `messages` of `role`/`content` is the conventional shape, not a requirement. An empty object or a null body is refused. Carry a `session_id` to name the session: re-ingesting the same one replaces what it held. Omit it and a session is opened and returned. Extraction runs asynchronously — poll the returned operation.



## OpenAPI

````yaml /openapi/source/external/agent-memory/agent-memory.json post /ai/memory/namespaces/{namespace}/profiles/{profile_id}/ingest
openapi: 3.1.0
info:
  version: 1.0.0
  title: Telnyx API
  x-latency-category: interactive
  x-endpoint-cost: light
  description: >-
    Long-term memory for AI agents. A profile per user, caller, or agent: write
    memories in with `ingest` or `remember`, and recall them with `recall`.
    Facts are extracted, and contradictions resolve to the newest.
servers:
  - url: https://api.telnyx.com/v2
    description: Telnyx API v2
security:
  - bearerAuth: []
tags:
  - name: Memory
    description: Write memories into a profile and recall them.
  - name: Profiles
    description: What a namespace and a profile hold.
  - name: Sources
    description: What a profile stored, and what its memories came from.
  - name: Operations
    description: Whether a write has finished.
  - name: Settings
    description: How a namespace's summaries are written.
paths:
  /ai/memory/namespaces/{namespace}/profiles/{profile_id}/ingest:
    post:
      tags:
        - Memory
      summary: Ingest a session's messages into a profile
      description: >-
        Store a session. Facts are extracted from whatever you send — the body
        is taken as any JSON value and stored whole, so a framework's own
        transcript shape works unchanged. `messages` of `role`/`content` is the
        conventional shape, not a requirement. An empty object or a null body is
        refused. Carry a `session_id` to name the session: re-ingesting the same
        one replaces what it held. Omit it and a session is opened and returned.
        Extraction runs asynchronously — poll the returned operation.
      operationId: IngestSession
      parameters:
        - name: profile_id
          in: path
          required: true
          schema:
            type: string
            title: Profile Id
        - name: namespace
          in: path
          required: true
          schema:
            type: string
            title: Namespace
        - name: session_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 128
              - type: 'null'
            description: >-
              Names the session. Re-ingesting the same session replaces what it
              held and keeps its `source_id`. Omit it to have one derived from
              the content and returned. No whitespace, control characters, or
              any of / \ # ? %.
            title: Session Id
          description: >-
            Names the session. Re-ingesting the same session replaces what it
            held and keeps its `source_id`. Omit it to have one derived from the
            content and returned. No whitespace, control characters, or any of /
            \ # ? %.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IngestPayload'
            examples:
              session:
                summary: A session you name
                value:
                  messages:
                    - role: user
                      content: Invoices go to 220 W Chicago Ave now.
                    - role: assistant
                      content: Got it.
              new_session:
                summary: A new session, opened for you
                value:
                  messages:
                    - role: user
                      content: I prefer email.
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IngestResponse'
              example:
                data:
                  operation_id: op_01HZY4M7Q9
                  profile_id: caller:+13128675309
                  session_id: conv_8901
                  source_id: b1e6c0a2-4f3d-4a2e-9c7b-8e1f2a3b4c5d
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10009'
                    title: Authentication failed
                    detail: Could not find any usable credentials in the request.
                    source:
                      pointer: /
                    meta:
                      url: https://developers.telnyx.com/docs/overview/errors/10009
        '404':
          description: The namespace does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: namespace_not_found
                    detail: no such namespace
        '422':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: empty_payload
                    detail: payload must carry something to remember
        '502':
          description: Upstream error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: upstream_error
                    detail: the memory dataplane is unavailable
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Telnyx from 'telnyx';


            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });


            const response = await
            client.ai.memory.namespaces.profiles.ingest('namespace',
            'profile_id');


            console.log(response.data);
        - lang: Python
          source: |
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            response = client.ai.memory.namespaces.profiles.ingest(
                namespace="namespace",
                profile_id="profile_id",
            )
            print(response.data)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.AI.Memory.Namespaces.Profiles.Ingest(\n\t\tcontext.TODO(),\n\t\t\"namespace\",\n\t\t\"profile_id\",\n\t\ttelnyx.AIMemoryNamespaceProfileIngestParams{\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Data)\n}\n"
        - lang: Java
          source: >-
            package com.telnyx.sdk.example;


            import com.telnyx.sdk.client.TelnyxClient;

            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            import
            com.telnyx.sdk.models.ai.memory.namespaces.profiles.ProfileIngestParams;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    ProfileIngestParams params = ProfileIngestParams.builder()
                        .build();
                    var response = client.ai().memory().namespaces().profiles().ingest("namespace", "profile_id", params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            response = telnyx.ai.memory.namespaces.profiles.ingest("namespace",
            "profile_id")


            puts(response)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $response = $client->ai->memory->namespaces->profiles->ingest(
                'namespace',
                'profile_id',
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx ai:memory:namespaces:profiles ingest \
              --api-key 'My API Key' \
              --namespace namespace \
              --profile-id profile_id
components:
  schemas:
    IngestPayload:
      title: Payload
      description: >-
        The session's messages, in whatever shape your framework produces. Any
        JSON value but null is accepted and stored whole, as long as it holds
        something to remember: a body with no content anywhere in it -- `{}`,
        `[]`, `""`, `{"messages": []}` -- is a 422.
      anyOf:
        - type: object
          additionalProperties: true
        - type:
            - array
            - string
            - number
            - boolean
    IngestResponse:
      properties:
        data:
          $ref: '#/components/schemas/AcceptedIngest'
      type: object
      required:
        - data
      title: IngestResponse
    TelnyxErrors:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/TelnyxError'
    AcceptedIngest:
      properties:
        operation_id:
          type: string
          title: Operation Id
        profile_id:
          type: string
          title: Profile Id
        session_id:
          type: string
          title: Session Id
        source_id:
          type: string
          title: Source Id
          description: >-
            Identifies one source within its profile: an ingested session, or
            one remembered fact. Returned by `ingest` and `remember` when the
            write is accepted. Re-ingesting a session keeps its source id.
      type: object
      required:
        - operation_id
        - profile_id
        - session_id
        - source_id
      title: AcceptedIngest
    TelnyxError:
      type: object
      properties:
        code:
          type: string
        title:
          type: string
        detail:
          type: string
        source:
          type: object
          properties:
            pointer:
              type: string
        meta:
          type: object
          properties:
            url:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Telnyx API key

````