Retrieve conversation history for a session

History Endpoint

Retrieve the full conversation history for a session. Useful for restoring chat state when a user revisits a page.

Endpoint

text
GET /api/history?session_id={session_id}

Query Parameters

ParameterTypeRequiredDescription
text
session_id
stringYesThe session ID used in
text
/api/chat
requests

Response

200 OK

Returns an array of messages in chronological order. Only
text
user
and
text
assistant
roles are returned.
json
{
  "messages": [
    {
      "role": "user",
      "content": "Hello! I need help with my order.",
      "created_at": "2026-04-05T10:00:00.000000Z"
    },
    {
      "role": "assistant",
      "content": "I'd be happy to help! Could you share your order number?",
      "created_at": "2026-04-05T10:00:01.000000Z"
    }
  ]
}
If the session has no conversation yet (or has expired), an empty array is returned:
json
{
  "messages": []
}

Example

cURL

bash
curl https://ai.vindex.ai/api/history?session_id=user-abc-123 \
  -H "X-API-Key: amgai_your-channel-key-here"

JavaScript

javascript
async function loadHistory(sessionId, apiKey) {
  const response = await fetch(
    `https://ai.vindex.ai/api/history?session_id=${sessionId}`,
    {
      headers: { 'X-API-Key': apiKey }
    }
  );

  const { messages } = await response.json();
  return messages; // [{ role, content, created_at }, ...]
}

Python

python
import requests

response = requests.get(
    'https://ai.vindex.ai/api/history',
    params={'session_id': 'user-abc-123'},
    headers={'X-API-Key': 'amgai_your-channel-key-here'}
)

messages = response.json()['messages']
for msg in messages:
    print(f"{msg['role']}: {msg['content']}")
Note: History is tied to the session's conversation window. Sessions expire after 24 hours of inactivity, after which
text
messages
will return empty.