Sessions API

Manage chat sessions to maintain conversation context across multiple requests.

GET/v1/sessions

Returns a list of all chat sessions for the authenticated user.

Query Parameters

limitoptional

Number of sessions to return. Default: 20, Max: 100

offsetoptional

Number of sessions to skip for pagination. Default: 0

Response

JSON
{
  "object": "list",
  "data": [
    {
      "id": "sess_abc123",
      "title": "Quantum Computing Discussion",
      "mode": "ensemble",
      "message_count": 8,
      "created_at": "2025-01-15T10:30:00Z",
      "updated_at": "2025-01-15T11:45:00Z"
    },
    {
      "id": "sess_def456",
      "title": "Python Best Practices",
      "mode": "smart_chat",
      "message_count": 4,
      "created_at": "2025-01-14T09:00:00Z",
      "updated_at": "2025-01-14T09:30:00Z"
    }
  ],
  "has_more": true,
  "total": 47
}
GET/v1/sessions/:id

Retrieves a specific session including all messages.

Path Parameters

idrequired

The unique identifier of the session.

Response

JSON
{
  "id": "sess_abc123",
  "title": "Quantum Computing Discussion",
  "mode": "ensemble",
  "created_at": "2025-01-15T10:30:00Z",
  "updated_at": "2025-01-15T11:45:00Z",
  "messages": [
    {
      "id": "msg_001",
      "role": "user",
      "content": "What is quantum computing?",
      "created_at": "2025-01-15T10:30:00Z"
    },
    {
      "id": "msg_002",
      "role": "assistant",
      "content": "Quantum computing is a type of computation...",
      "models_used": ["gpt-4o", "claude-3-opus"],
      "created_at": "2025-01-15T10:30:15Z"
    }
  ]
}
PATCH/v1/sessions/:id

Updates a session's metadata (e.g., title).

Request Body

JSON
{
  "title": "Updated Session Title"
}

Response

JSON
{
  "id": "sess_abc123",
  "title": "Updated Session Title",
  "mode": "ensemble",
  "message_count": 8,
  "created_at": "2025-01-15T10:30:00Z",
  "updated_at": "2025-01-15T12:00:00Z"
}
DELETE/v1/sessions/:id

Permanently deletes a session and all its messages.

Response

JSON
{
  "id": "sess_abc123",
  "object": "session.deleted",
  "deleted": true
}

Using Sessions in Chat

To continue a conversation, include the session_id in your chat request:

cURL
curl https://api.konnect.ai/v1/chat \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Can you elaborate on that?",
    "session_id": "sess_abc123"
  }'

The API will automatically include previous messages from the session as context.