Skip to main content

Sessions API

Retrieve and browse your chatbot's sessions programmatically through the Developer API.


Base URL

https://api.peki.ai/api

Authentication

All endpoints require HMAC-SHA256 authentication. See the Messages API guide for full details on signature generation.

Required Headers

HeaderRequiredDescription
Content-TypeMust be application/json
X-API-KeyYour API key (starts with pk_)
X-SignatureHMAC-SHA256 signature
X-TimestampUnix timestamp in seconds

List Sessions

Get all chat sessions for your chatbot with pagination. Optionally filter by user.

GET /Dev/{chatbotId}/sessions

Path Parameters

ParameterTypeRequiredDescription
chatbotIdstringThe unique identifier for your chatbot

Query Parameters

ParameterTypeRequiredDefaultDescription
userIdstring-Filter sessions by user ID
pageint1Page number (1-based)
pageSizeint20Number of items per page

Response

{
"data": [
{
"id": "6612a1b2c3d4e5f6a7b8c9d1",
"chatbotId": "your_chatbot_id",
"chatUserId": "6612a1b2c3d4e5f6a7b8c9d0",
"threadId": "thread_abc123",
"status": "Active",
"subject": "Product inquiry",
"summary": "User asked about pricing plans and feature comparison.",
"behaviour": "Calm",
"result": "Resolved",
"score": 8.5,
"category": "Sales",
"sentiment": "Positive",
"language": "en",
"tags": ["pricing", "features", "comparison"],
"chatUserName": "John Doe",
"source": "Dev",
"tokenCount": 1250,
"createdAt": "2025-04-08T12:00:00Z",
"updatedAt": "2025-04-08T12:05:00Z"
}
],
"error": null,
"totalItems": 120,
"pageSize": 20,
"currentPage": 1,
"totalPages": 6
}

Response Fields

FieldTypeDescription
idstringUnique identifier for the session
chatbotIdstringThe chatbot this session belongs to
chatUserIdstringThe user who initiated the session
threadIdstringThread identifier for the AI conversation
statusstringSession status: Active, Closed
subjectstringAuto-detected topic of the conversation
summarystringAuto-generated summary of the session
behaviourstringDetected user behavior (e.g., Calm, Urgent, Confused)
resultstringOutcome of the session (e.g., Resolved, Pending)
scorenumberAI-assigned quality score for the session
categorystringAuto-detected category (e.g., Sales, Support, General)
sentimentstringDetected sentiment (Positive, Neutral, Negative)
languagestringDetected language code (e.g., en, tr)
tagsstring[]Auto-generated tags for the conversation
chatUserNamestringDisplay name of the user
sourcestringPlatform where the session originated
tokenCountintTotal tokens consumed in the session
createdAtdatetimeWhen the session was created
updatedAtdatetimeWhen the session was last updated

Get Session

Get a single session by its ID.

GET /Dev/{chatbotId}/sessions/{sessionId}

Path Parameters

ParameterTypeRequiredDescription
chatbotIdstringThe unique identifier for your chatbot
sessionIdstringThe unique identifier for the session

Response

{
"data": {
"id": "6612a1b2c3d4e5f6a7b8c9d1",
"chatbotId": "your_chatbot_id",
"chatUserId": "6612a1b2c3d4e5f6a7b8c9d0",
"threadId": "thread_abc123",
"status": "Closed",
"subject": "Product inquiry",
"summary": "User asked about pricing plans and feature comparison.",
"sentiment": "Positive",
"score": 8.5,
"language": "en",
"tokenCount": 1250,
"createdAt": "2025-04-08T12:00:00Z",
"updatedAt": "2025-04-08T12:05:00Z"
},
"error": null
}

Error Response

{
"data": null,
"error": "Session not found."
}

Filtering by User

To get all sessions for a specific user, pass the userId query parameter:

GET /Dev/{chatbotId}/sessions?userId=6612a1b2c3d4e5f6a7b8c9d0

This is useful for building user-specific conversation history views.


Pagination

All list endpoints return paginated results with the following metadata:

FieldTypeDescription
totalItemsintTotal number of records
pageSizeintNumber of items per page
currentPageintCurrent page number
totalPagesintTotal number of pages

Use the page and pageSize query parameters to navigate through results. Results are ordered by creation date (newest first).


Code Examples

JavaScript

const crypto = require("crypto");

const apiKey = "pk_your_api_key";
const apiSecret = "sk_your_api_secret";
const chatbotId = "your_chatbot_id";

// List all sessions
const timestamp = Math.floor(Date.now() / 1000);
const path = `/api/Dev/${chatbotId}/sessions?page=1&pageSize=20`;
const payload = `GET\n${path}\n\n${timestamp}`;
const signature = crypto
.createHmac("sha256", apiSecret)
.update(payload)
.digest("base64");

const response = await fetch(`https://api.peki.ai${path}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-Key": apiKey,
"X-Signature": signature,
"X-Timestamp": timestamp.toString(),
},
});

const result = await response.json();
console.log("Sessions:", result.data);
console.log("Total:", result.totalItems);

Python

import hmac, hashlib, base64, time, requests

api_key = 'pk_your_api_key'
api_secret = 'sk_your_api_secret'
chatbot_id = 'your_chatbot_id'

# List sessions for a specific user
user_id = 'USER_ID_HERE'
timestamp = str(int(time.time()))
path = f'/api/Dev/{chatbot_id}/sessions?userId={user_id}&page=1&pageSize=20'
payload = f'GET\n{path}\n\n{timestamp}'

signature = base64.b64encode(
hmac.new(api_secret.encode(), payload.encode(), hashlib.sha256).digest()
).decode()

headers = {
'Content-Type': 'application/json',
'X-API-Key': api_key,
'X-Signature': signature,
'X-Timestamp': timestamp
}

response = requests.get(f'https://api.peki.ai{path}', headers=headers)
result = response.json()
print('Sessions:', result['data'])

cURL

API_KEY="pk_your_api_key"
API_SECRET="sk_your_api_secret"
CHATBOT_ID="your_chatbot_id"

TIMESTAMP=$(date +%s)
REQ_PATH="/api/Dev/$CHATBOT_ID/sessions?page=1&pageSize=20"
PAYLOAD="GET\n$REQ_PATH\n\n$TIMESTAMP"
SIGNATURE=$(echo -ne "$PAYLOAD" | openssl dgst -sha256 -hmac "$API_SECRET" -binary | base64)

curl -s "https://api.peki.ai$REQ_PATH" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-H "X-Signature: $SIGNATURE" \
-H "X-Timestamp: $TIMESTAMP"

Error Codes

Status CodeDescription
401Invalid API key or signature
403API key doesn't have access to the specified chatbot
404Session not found
500Internal server error