/api/integration/ai_service/ on https://back.leap.onclarity.com, and every request sends Authorization: Bearer $CLARITY_API_KEY (see Authentication).
How it works
1
Start from a web-chat ticket
The conversation starts in your chat widget or mobile SDK, which opens the ticket. Get its
ticket_id and the customer’s id (customer.id) from the ticket_created webhook for a ticket whose channel is web, android_sdk or ios_sdk, or list a known customer’s tickets with GET /api/integration/ai_service/customer/{customer_id}/tickets.2
Forward each customer message
POST /api/integration/ai_service/customer/send adds a message to the ticket as if the customer had typed it in the chat widget. The AI agent then processes it the same way it processes widget messages.3
Read the replies
Subscribe to the
message webhook, or read the ticket’s events with GET /api/integration/ai_service/ticket/{ticket_id}/details, and relay the agent’s replies to the customer on your channel.Opening a brand-new ticket from your own system, without the widget, needs an integration credential bound to an AI agent, which an organization API key is not. Contact Clarity support if your integration needs it.
Send a customer message
integer
required
The customer the ticket belongs to.
integer
required
The ticket to add the message to.
string
required
The message text. Required, but may be an empty string when you only send files.
integer[]
default:"[]"
Attachment ids from
POST /api/attachment/upload (see Attachments). At most 5 per message.string
When Clarity accepted the message (ISO 8601).
string
The message’s id. The same value appears as
internal_id on the event in the ticket details.object[]
The attached files, each with
id, original_url, thumbnail_url, mime_type, and original_filename.200 means Clarity accepted it, and the AI agent’s reply arrives later.
The ticket must have an active chat session, which tickets opened through the chat widget and the mobile SDKs have. Other tickets, such as WhatsApp or email ones, cannot receive customer messages this way.
Errors
Read the ticket
GET /api/integration/ai_service/ticket/{ticket_id}/details returns the customer, the ticket, its tags and team, and the latest events of the chat.
integer
default:"20"
How many events to return. When the ticket continues a closed chat, at least 60 are returned so the earlier tickets are included.
object
The customer:
id, first_name, last_name, avatar_url, organization_id, attributes (a list of {key, value}), tags, and custom_attributes.object
id, conversation_id, status, priority, category, is_archived, and custom_attributes.object[]
The ticket’s tags, each with
id, name, description, and color.object | null
The team the ticket is assigned to.
object[]
Timeline events. Each has
id, type (for example message, private_note, status_change), created_at, ticket_id, conversation_id, internal_id, and a payload whose shape depends on the type.object | null
When a voice agent handed this customer over to chat, the summary it wrote of the call.
custom_attributes on the ticket and the customer include only the attributes whose definition has ai_context turned on (Settings > Custom attributes). Use GET /api/custom-attributes/values to read every attribute.Read the customer
Ask a voice agent to call the customer
POST /api/integration/ai_service/ticket/{ticket_id}/voice_handoff asks a Clarity voice agent to phone the customer of a chat ticket. It works when the AI agent that answers the ticket has the request-a-call tool configured with a voice agent, and your organization has a voice project.
string
required
The number to call, 1 to 64 characters. It is normalized against your organization’s region.
object
What the voice agent should know before it speaks. Optional fields:
reason (up to 200 characters), summary (800), key_facts (up to 10 {label, value} pairs), commitments (up to 5 strings), open_question (300), opening_line (200), and language. Longer values are cut, not refused.200 with status: "refused" and a message you can relay to the customer:
Next steps
Webhooks
Receive the AI agent’s replies as they are written.
Messages
Reply as the business, add private notes, and upload attachments.