Get chat messages

GET/agent/chat/messages

Retrieves a list of chat messages for a given chat session

RequiresBearerauthentication

Query parameters

chat_session_idstringrequired

Chat session ID

num_messagesintegeroptionaldefault 10

Number of messages to return

rolestringoptional

Filter by one or more message roles. Multiple roles can be specified as a comma-separated string. If not specified, messages with all roles are returned.

Available roles:

  • user - Messages from the user
  • assistant - Text responses from the AI assistant
  • model - Function/tool call requests from the model
  • function - Function/tool call results
userassistantmodelfunction
orderstringoptionaldefault desc

Order of messages

ascdesc
Returns  

Chat messages retrieved successfully

Response fields

messagesobject[]optional
idstringoptional

Chat message ID

session_idstringoptional

Chat session ID

rolestringoptional

Message role indicating the source/type of the message:

  • user - Messages from the user
  • assistant - Text responses from the AI assistant
  • model - Function/tool call requests to the model
  • function - Function/tool call results
userassistantmodelfunction
contentstringoptional

Message content

createdstringoptional

Message created time

updatedstringoptional

Message updated time

function_namestringoptional

Function name

function_argsobjectoptional

Function arguments

function_resultobjectoptional

Function result

message_orderintegeroptional

Message order

totalintegeroptional
session_idstringoptional
GETRequest
# Get authentication token
PHENOML_TOKEN=$(curl -X POST "https://experiment.app.pheno.ml/v2/auth/token" \
  -u "$PHENOML_CLIENT_ID:$PHENOML_CLIENT_SECRET" \
  | jq -r '.access_token')

curl -X GET "https://experiment.app.pheno.ml/agent/chat/messages?role=user" \
  -H "Authorization: Bearer $PHENOML_TOKEN"
200 OKExample Response
{
  "session_id": "session_123",
  "total": 2,
  "messages": [
    {
      "id": "message_001",
      "session_id": "session_123",
      "role": "user",
      "content": "What is the patient's current condition?",
      "created": "2025-03-01T14:00:00Z",
      "updated": "2025-03-01T14:00:00Z",
      "message_order": 1
    },
    {
      "id": "message_002",
      "session_id": "session_123",
      "role": "assistant",
      "content": "Based on the patient records, they have been diagnosed with Type 2 Diabetes Mellitus (ICD-10: E11.65).",
      "created": "2025-03-01T14:00:02Z",
      "updated": "2025-03-01T14:00:02Z",
      "message_order": 2
    }
  ]
}