Skip to main content

Conversations API

Retrieve and browse your chatbot's messages 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 Messages

Get all messages for your chatbot with pagination. Optionally filter by session or user.

GET /Dev/{chatbotId}/messages

Path Parameters

ParameterTypeRequiredDescription
chatbotIdstringThe unique identifier for your chatbot

Query Parameters

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

Response

{
"data": [
{
"id": "6612a1b2c3d4e5f6a7b8c9d2",
"chatbotId": "your_chatbot_id",
"chatSessionId": "6612a1b2c3d4e5f6a7b8c9d1",
"chatUserId": "6612a1b2c3d4e5f6a7b8c9d0",
"senderType": "User",
"text": "What are the latest crypto trends?",
"tokenCount": 12,
"responseTime": null,
"createdAt": "2025-04-08T12:00:00Z"
},
{
"id": "6612a1b2c3d4e5f6a7b8c9d3",
"chatbotId": "your_chatbot_id",
"chatSessionId": "6612a1b2c3d4e5f6a7b8c9d1",
"chatUserId": "6612a1b2c3d4e5f6a7b8c9d0",
"senderType": "Bot",
"text": "Based on current market trends, here are the key developments...",
"tokenCount": 350,
"responseTime": 1.25,
"createdAt": "2025-04-08T12:00:02Z"
}
],
"error": null,
"totalItems": 500,
"pageSize": 20,
"currentPage": 1,
"totalPages": 25
}

Response Fields

FieldTypeDescription
idstringUnique identifier for the message
chatbotIdstringThe chatbot this message belongs to
chatSessionIdstringThe session this message belongs to
chatUserIdstringThe user who sent or received the message
senderTypestringWho sent the message: User or Bot
textstringThe message content (for text messages)
urlstringMedia URL (for media messages)
tokenCountintNumber of tokens consumed by this message
responseTimenumberAI response time in seconds (only for Bot messages)
createdAtdatetimeWhen the message was sent

Get Message

Get a single message by its ID.

GET /Dev/{chatbotId}/messages/{messageId}

Path Parameters

ParameterTypeRequiredDescription
chatbotIdstringThe unique identifier for your chatbot
messageIdstringThe unique identifier for the message

Response

{
"data": {
"id": "6612a1b2c3d4e5f6a7b8c9d2",
"chatbotId": "your_chatbot_id",
"chatSessionId": "6612a1b2c3d4e5f6a7b8c9d1",
"chatUserId": "6612a1b2c3d4e5f6a7b8c9d0",
"senderType": "User",
"text": "What are the latest crypto trends?",
"tokenCount": 12,
"createdAt": "2025-04-08T12:00:00Z"
},
"error": null
}

Error Response

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

Filtering Messages

By Session

Get all messages in a specific conversation session:

GET /Dev/{chatbotId}/messages?sessionId=6612a1b2c3d4e5f6a7b8c9d1

By User

Get all messages from a specific user across all sessions:

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

Combined Filters

Filter by both session and user:

GET /Dev/{chatbotId}/messages?sessionId=SESSION_ID&userId=USER_ID&page=1&pageSize=50

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";
const sessionId = "your_session_id";

// Get messages for a specific session
const timestamp = Math.floor(Date.now() / 1000);
const path = `/api/Dev/${chatbotId}/messages?sessionId=${sessionId}&page=1&pageSize=50`;
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("Messages:", 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'
session_id = 'your_session_id'

# Get messages for a specific session
timestamp = str(int(time.time()))
path = f'/api/Dev/{chatbot_id}/messages?sessionId={session_id}&page=1&pageSize=50'
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()

for msg in result['data']:
sender = 'You' if msg['senderType'] == 'User' else 'Bot'
print(f'{sender}: {msg.get("text", "")}')

cURL

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

TIMESTAMP=$(date +%s)
REQ_PATH="/api/Dev/$CHATBOT_ID/messages?sessionId=$SESSION_ID&page=1&pageSize=50"
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"

Common Workflow

A typical flow to retrieve a full conversation:

  1. List users to find the user you're interested in
  2. List sessions filtered by userId to find their conversations
  3. List messages filtered by sessionId to read the full conversation
GET /Dev/{chatbotId}/users
→ pick a userId

GET /Dev/{chatbotId}/sessions?userId={userId}
→ pick a sessionId

GET /Dev/{chatbotId}/messages?sessionId={sessionId}
→ full conversation

Error Codes

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