# Append session messages

URL: https://docs.clinia.com/sdks/reference/sessions/append-messages

Appends user/assistant messages to a session, in order, creating the session if this is its first write, and queues memory formation over them. The returned `ingestion` is the receipt to poll. Tool-call turns are recorded separately by the MCP layer and are not accepted here.

New ids are limited to `[A-Za-z0-9][A-Za-z0-9.~:-]{0,127}`, but you can keep referring to previous ids as they were defined.

Deprecated: use `POST …/ingestions/sessions`, which accepts the same messages under the session's id.

## Usage [#usage]

```javascript tab="JavaScript" tab-group="sdk-language"
import { ContextEngineClient } from "@clinia/context-engine-js";

// Initialize the client
const client = new ContextEngineClient({
  baseUrl: process.env.CLINIA_WORKSPACE,
  auth: {
    clientId: process.env.CLINIA_CLIENT_ID,
    clientSecret: process.env.CLINIA_CLIENT_SECRET,
  },
});

// Call the API, with the request body the API reference documents
const { data, error } = await client.sessions.appendMessages("<patient-id>", "<session-id>", body);

// Print the response
console.log(data ?? error);
```

```python tab="Python" tab-group="sdk-language"
import os
from clinia_context_engine import ClientCredentials, ContextEngineClient

# Initialize the client
client = ContextEngineClient(
    base_url=os.environ["CLINIA_WORKSPACE"],
    auth=ClientCredentials(
        client_id=os.environ["CLINIA_CLIENT_ID"],
        client_secret=os.environ["CLINIA_CLIENT_SECRET"],
    ),
)

# Call the API, with the request body the API reference documents
result = client.sessions.append_messages("<patient-id>", "<session-id>", body)

# Print the response
print(result)
```

The environment variables are set in Install and authenticate, for [JavaScript](https://docs.clinia.com/sdks/javascript#install-and-authenticate) or [Python](https://docs.clinia.com/sdks/python#install-and-authenticate).

## API reference [#api-reference]

[`POST /v1/patients/{patientId}/sessions/{sessionId}/messages`](https://docs.clinia.com/api/rest/post-patients-patientId-sessions-sessionId-messages) documents the parameters, the request body and the responses.
