What it is
The Chat API takes a customer's message and returns the assistant's reply. It speaks the wire format of OpenAI's Chat Completions, so the official OpenAI SDKs and tools that accept a custom OpenAI address work with it, for example a voice platform's Custom LLM setting. Behind it runs the same turn as WhatsApp or the website chat: knowledge, tools, procedures, handover and guardrails all apply.
- Use it from your server. Never call it from a browser: the key would be exposed. The website widget is for browsers.
- The assistant keeps its own memory per conversation. You send only the newest message.
- Each reply the assistant writes uses credits like on any other channel. The messages you send are free.
Endpoints
| Request | What it does |
|---|---|
POST /v1/agents/{agent_id}/chat/completions | Chat with the assistant named in the path. A key from another assistant gets 401. |
POST /v1/chat/completions | The key alone picks the assistant. For clients that always add /v1/chat/completions to a base address. |
GET /v1/agents/{agent_id}/models, GET /v1/models | Lists one model whose id is the assistant's id, owned_by: "agent-platform". For clients that ask which models exist. |
POST /v1/visitor-context, POST /v1/agents/{agent_id}/visitor-context | Tell the assistant who a customer is before they write. See Who the customer is. |
The base is your dashboard's address; examples use https://app.heyservo.ai. The Endpoint box on DevelopersAPI keys shows the exact address, with the assistant's id filled in when you filter by an assistant.
Authentication
Send a chat key as a Bearer token: Authorization: Bearer sk-agent-…. Create one on DevelopersAPI keys with the purpose Chat (OpenAI-compatible API). Its Channel decides where the conversations are filed: API, Website, Phone or WhatsApp. See API keys.
Send a message
curl -X POST "https://app.heyservo.ai/v1/agents/AGENT_ID/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user": "customer-42",
"messages": [
{"role": "user", "content": "Do you have a table for two tonight?"}
]
}'The request body
- messagesList
- Required. An array of
{role, content}. Only the newestusermessage with content is used. Earlier messages and system prompts in the array are ignored: the assistant keeps its own history and follows its own instructions. Without a user message the request fails with400. - userText
- Strongly recommended. A stable id for the customer or conversation, such as your own customer id. The same
usercontinues the same conversation. It also becomes the conversation's contact id. Values starting withconv:are reserved. - streamSwitch
truestreams the reply as server-sent events.Defaultfalse- modelText
- Ignored for behaviour, and echoed back in the response. When you leave it out, the response carries the assistant's id.
- Other OpenAI fieldsShown
temperature,max_tokens,toolsand the rest are accepted and ignored. The assistant's own settings decide.
How a conversation is identified
HeyServo derives the conversation from the assistant and the user value. Send the same user and the assistant remembers what was said, and the messages join the same transcript in Conversations.
- Send only the newest message each time. Sending the whole history does no harm, but only the last user message counts.
- If the same message arrives again at the end of the same conversation within 120 seconds, it is treated as a retry and not stored twice.
- While one message is still being answered, a second for the same conversation waits its turn. If it waits too long, it gets
409. - When a team member has taken over the conversation, you get an ordinary reply carrying the assistant's handover acknowledgement, set on Hand over to a person.
The response
{
"id": "chatcmpl-6b1f0c2e9a4d4e7b8c3a1f20",
"object": "chat.completion",
"created": 1763900000,
"model": "heyservo",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Yes, we have a table for two at 8pm. Shall I hold it for you?"
},
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0 }
}usage is always zeros. Credits are charged per reply and are not reported in tokens here: see Credits and billing.
Streaming
With "stream": true the answer is text/event-stream. Each line is data: and a chat.completion.chunk:
- A first chunk with
delta: {"role": "assistant", "content": ""}. - Content chunks, about a sentence each, as the reply is written.
- A last chunk with
finish_reason: "stop". data: [DONE].
- Lines starting with
:(: keepalive) may arrive while the assistant uses a slow tool. Ignore them; most clients do. - If the assistant is set to say a short waiting line during tool calls, it arrives as ordinary content followed by a space.
- An error in the middle of a stream arrives as content starting
Sorry, something went wrong:.
curl -N -X POST "https://app.heyservo.ai/v1/agents/AGENT_ID/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"user": "customer-42", "stream": true,
"messages": [{"role": "user", "content": "Hi"}]}'Who the customer is
To let the assistant greet a customer by name or know their number, register them first with POST /v1/visitor-context (or /v1/agents/{agent_id}/visitor-context) using the same chat key. When a later chat request's user equals the caller_id, the assistant knows who it is talking to.
- caller_idText
- Required. The same value you will send as
user.callerIdis accepted too. - full_nameText
- The customer's name.
- phoneText
- International E.164 form, like
+971501234567. - emailText
- A valid email address.
- source, pageText
- Optional notes on where they came from.
At least one of full_name, phone or email is needed. The answer is {"ok": true, "agent_id": …, "visitor": {…}}.
curl -X POST "https://app.heyservo.ai/v1/agents/AGENT_ID/visitor-context" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"caller_id": "customer-42", "full_name": "Layla Hassan",
"phone": "+971501234567", "email": "layla@example.com"}'Errors and status codes
Errors come back as {"detail": "…"} with the message below.
| Status | Message | What to do |
|---|---|---|
200 | The reply. Also used for the cases in the next table. | |
400 | messages must include at least one user message | Send at least one user message with content. |
400 | user values starting with conv: are reserved | Pick another user value. |
400 | caller_id is required, phone must be E.164 (e.g. +9715…), email is invalid, at least one of full_name, phone, or email is required | Visitor context only: fix the body. |
401 | missing bearer token | Add the Authorization: Bearer header. |
401 | invalid or revoked API key | Check the key, and that it belongs to the assistant in the path. |
401 | API key is not a chat key | Use a key whose purpose is Chat. |
409 | Sorry, I'm still working on your previous message. Please give me a moment and try again. | A message for this conversation is still being answered. Wait, then send again. When streaming, this text arrives as content. |
502 | The error, or no reply produced | The assistant could not produce a reply. Try again. |
| Situation | What you get |
|---|---|
| A team member has taken over | A normal reply with the handover acknowledgement, by default "A human team member will pick this conversation up shortly." |
| The account is out of credits or suspended | A normal reply with the fallback line, not an HTTP error. It is not charged. |
| A repeat of the last message within 120 seconds | Treated as a retry: the message is not stored twice. |