Without sessions, you manage conversation history manually by sending all prior messages on every request. Sessions do this for you server-side, stored in Redis with a 7-day TTL.
Add session_id to any /chat request. Previous messages are automatically injected before your new messages.
curl -X POST https://ninjachat.ai/api/v1/chat \ -H "Authorization: Bearer nj_sk_YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5", "messages": [{"role": "user", "content": "My name is Alice. I work in fintech."}], "session_id": "user-alice-session-1" }'
Second request (history is automatically included):
curl -X POST https://ninjachat.ai/api/v1/chat \ -H "Authorization: Bearer nj_sk_YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5", "messages": [{"role": "user", "content": "What do you know about me?"}], "session_id": "user-alice-session-1" }'
The model will respond: “You told me your name is Alice and you work in fintech.”
GET https://ninjachat.ai/api/v1/sessions/user-alice-session-1Authorization: Bearer nj_sk_YOUR_API_KEY
{ "session_id": "user-alice-session-1", "messages": [ {"role": "user", "content": "My name is Alice. I work in fintech."}, {"role": "assistant", "content": "Nice to meet you, Alice! ..."}, {"role": "user", "content": "What do you know about me?"}, {"role": "assistant", "content": "You told me your name is Alice..."} ], "message_count": 4, "created_at": "2026-03-10T12:00:00.000Z", "updated_at": "2026-03-10T12:01:32.000Z"}