Chat API
Chat API allows you to integrate an AI consultant into your application. Standard request-response mode and SSE streaming for real-time display are supported.
POST/api/v1/chat
Send Message
Sends a message to AI chat and receives a complete response. For real-time display, use the SSE endpoint.
Request Parameters
- Name
message- Type
- string
- Description
- User message text (max 4000 characters)
- Name
chat_id- Type
- integer
- Description
- Existing chat ID to continue the conversation
- Name
stream- Type
- boolean
- Description
- Must be `false` for this endpoint
Response
- Name
chat_id- Type
- integer
- Description
- Chat ID (use to continue conversation)
- Name
message_id- Type
- integer
- Description
- Created message ID
- Name
response- Type
- string
- Description
- AI text response
- Name
product_ids- Type
- array
- Description
- Array of recommended product IDs
Request
curl -X POST "https://api.parsewise.ru/v1/chat" \
-H "Authorization: Bearer pw_your_token" \
-H "Content-Type: application/json" \
-d '{
"message": "What running shoes do you recommend?",
"stream": false
}'
Response
{
"chat_id": 456,
"message_id": 789,
"response": "For running, I recommend these models...",
"product_ids": [12, 45, 78]
}
POST/api/v1/chat/stream
SSE Streaming
Sends a message and receives a response in real-time via Server-Sent Events. Perfect for creating a ChatGPT-like UX.
Request Parameters
- Name
message- Type
- string
- Description
- User message text
- Name
chat_id- Type
- integer
- Description
- Existing chat ID to continue conversation
Event Types
- Name
products- Type
- object
- Description
- Sent first, contains `product_ids`
- Name
text- Type
- object
- Description
- Response text parts in `content` field
- Name
done- Type
- object
- Description
- Completion, contains `message_id` and `chat_id`
- Name
error- Type
- object
- Description
- Error, contains `message`
Request
import requests
import json
response = requests.post(
"https://api.parsewise.ru/v1/chat/stream",
headers={"Authorization": "Bearer pw_your_token"},
json={"message": "Tell me about products"},
stream=True
)
for line in response.iter_lines():
if line:
line = line.decode('utf-8')
if line.startswith('data: '):
data = json.loads(line[6:])
if data['type'] == 'products':
print(f"Products: {data['data']['product_ids']}")
elif data['type'] == 'text':
print(data['data']['content'], end='', flush=True)
elif data['type'] == 'done':
print(f"\nChat ID: {data['data']['chat_id']}")
SSE Events
data: {"type": "products", "data": {"product_ids": [12, 45]}}
data: {"type": "text", "data": {"content": "We have "}}
data: {"type": "text", "data": {"content": "great options..."}}
data: {"type": "done", "data": {"message_id": 789, "chat_id": 456}}
GET/api/v1/chat/{chat_id}/messages
Message History
Returns all messages in the specified chat.
URL Parameters
- Name
chat_id- Type
- integer
- Description
- Chat ID
Response
Array of messages:- Name
id- Type
- integer
- Description
- Message ID
- Name
content- Type
- string
- Description
- Message text
- Name
is_from_user- Type
- boolean
- Description
- `true` if from user, `false` if from AI
- Name
created_at- Type
- string
- Description
- Creation time in ISO 8601
Request
curl "https://api.parsewise.ru/v1/chat/456/messages" \
-H "Authorization: Bearer pw_your_token"
Response
[
{
"id": 1,
"content": "What running shoes do you have?",
"is_from_user": true,
"created_at": "2024-01-15T10:30:00Z"
},
{
"id": 2,
"content": "I recommend checking out...",
"is_from_user": false,
"created_at": "2024-01-15T10:30:05Z"
}
]