AI chat integration
Put the merchant's AI chatbot in your own channel: a website chat widget, a mobile app, or a messaging bot. Your app sends what the person types and shows the chatbot's replies.
Before you start
- The merchant must have the AI Chatbot module and its chatbot switched on. Otherwise every call returns
403with a type such asai-chat-module-disabledorai-chat-chatbot-disabled. - Your app needs the scopes
ai_chat:write( start conversations, send messages ) andai_chat:read( list conversations, read history ). They are not granted by default: ask the merchant to add them to your app. - Every message uses the merchant's AI credits or AI keys. When they run out, calls return
403ai-chat-credits-exhausted.
What the chatbot can see
The chatbot answers as your app, on your app's own credential. It looks things up with the same read operations
your app can call, so the scopes, catalogues, storefronts and booking ownership granted to your app decide what it
can see. For example, without pricing:read it cannot quote prices, and it only sees the bookings your app may read.
With products:read it can find tours by words, city or country and answer about a tour's itinerary, inclusions and
exclusions, pickup, meeting point, cancellation policy, guide languages, FAQs and add-ons, for tours and activities.
With availability:read it can check dates and timeslots.
It never creates, changes or cancels anything: send the person to your booking flow for that.
There is no Agantia user behind a chat. To keep each of your users' conversations apart, send your own id for the
person as external_user_id and filter by it.
Endpoints
| Method | Path | Scope | What it does |
|---|---|---|---|
POST | /api/public/v1/ai/conversations | ai_chat:write | Start a conversation, optionally with a first message |
GET | /api/public/v1/ai/conversations | ai_chat:read | List your app's conversations ( filter[external_user_id], filter[status] ) |
GET | /api/public/v1/ai/conversations/{id} | ai_chat:read | Get a conversation |
GET | /api/public/v1/ai/conversations/{id}/messages | ai_chat:read | Conversation history, oldest first, paginated |
POST | /api/public/v1/ai/conversations/{id}/messages | ai_chat:write | Send a message and get the reply |
POST | /api/public/v1/ai/responses/{response_id}/replies | ai_chat:write | Reply to a specific chatbot reply |
POST calls need an Idempotency-Key. A retry with the same key returns the first reply instead
of asking the AI again, so a network retry is never charged twice.
Start a conversation
curl -X POST https://api.staging.agantia.com/api/public/v1/ai/conversations \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1d1c1e-2f7a-4b8e-9d55-1f0d6a3c9b21" \
-d '{ "external_user_id": "customer-8841", "message": "Which desert safaris are available tomorrow for 4 adults?" }'
The response is 201 with the conversation and its first two messages:
{
"data": {
"id": "conv_8Jd2kQ9mPz1Lw4tR",
"title": "Which desert safaris are available tomorrow for 4 adults?",
"status": "active",
"external_user_id": "customer-8841",
"messages": [
{ "id": "msg_…", "role": "user", "content": "Which desert safaris …", "options": [], "response_id": null },
{
"id": "msg_…",
"role": "assistant",
"content": "Two desert safaris have space tomorrow …",
"options": ["Evening Desert Safari", "Morning Desert Safari"],
"response_id": "resp_Xb2kQ9mPz1Lw4tRe",
"status": "completed"
}
]
}
}
Leave out message to create an empty conversation and send the first message later.
Send messages
curl -X POST https://api.staging.agantia.com/api/public/v1/ai/conversations/conv_8Jd2kQ9mPz1Lw4tR/messages \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 0b8b0f8e-6d0a-4a39-8d1c-2a6a8e4c7f10" \
-d '{ "message": "What does the evening one include?" }'
The response holds conversation, the stored message, and the chatbot's reply.
Replies and options
Each chatbot reply has a response_id. When a reply has options, show them as buttons. When the person picks one,
or answers that reply specifically, send it as a reply:
curl -X POST https://api.staging.agantia.com/api/public/v1/ai/responses/resp_Xb2kQ9mPz1Lw4tRe/replies \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 4c2f9a0d-1b7e-4f3a-a6d2-9e8b7c6d5a41" \
-d '{ "message": "Evening Desert Safari" }'
This is the same as sending a message with reply_to_response_id. The person can always type another answer instead.
History
GET /ai/conversations/{id}/messages?page=1&per_page=50 returns the messages oldest first, with the usual
pagination.
Failed replies
If no AI model can answer, the reply has status: "failed" and a content that is safe to show, such as asking the
person to try again shortly. The call itself still succeeds.
Isolation
A conversation belongs to the app and environment that created it. Another app's conversation, or one from the other
environment, returns 404.