Ask API
Send your customers' questions from your backend and get your Zipchat AI agent's answer in the response.
Send a customer's question from your backend and get your Zipchat AI agent's answer in the response. Use it to put the agent in your own app, help center or chat UI.
The agent answers with the same instructions, knowledge, skills and tools it uses on your other channels. Each customer's questions and the agent's answers are saved as one conversation in Zipchat, where your team can read it and follow up by email.
Get an API key
In Zipchat, open Channels and set up API.
Name and create an API key. Copy it right away: it is shown only once.
Send your first question. The API channel goes Live with it.
To create more keys, revoke one, or disconnect the channel, open Manage on the API channel. Its Send a question tab shows the endpoint and a sample request.
Authentication
Send the API key as a Bearer token in the Authorization header:
Authorization: Bearer zca-your_api_keyAPI keys start with zca- and belong to one chat. The key tells Zipchat which chat you're asking, so the request doesn't name it.
An API key can only ask questions. It can't read your conversations or change your agent's instructions, skills or tools. It can ask on behalf of any customer, though, and a question for a verified customer is answered from that customer's orders. Give keys only to backends you trust with that data.
401
The key is missing, invalid or revoked.
403
The key was used on an endpoint other than Ask, or the chat's API channel is disconnected.
Ask a question
Sends a customer's question to your AI agent and waits for the answer, up to 20 seconds. The question continues that customer's current conversation. Send Content-Type: application/json, with a body of up to 32 KB.
message
string
yes
The customer's question, up to 4,000 characters.
customer
object
yes
Who is asking. Send the same values on every question from this customer. See Customers and conversations.
customer.id
string
yes
Your ID for this customer: their account ID when they are logged in, or a guest or session ID when they aren't. Up to 64 characters.
customer.email
string
no
The customer's email. Sending it alone does not verify it.
customer.email_verified
boolean
no
Defaults to false. Set true only when your backend authenticated this customer and got the email from their account. It lets the agent look up their orders and remember earlier conversations. Requires email. See Who verifies a customer.
customer.name
string
no
Display name for the customer's profile in Zipchat, up to 200 characters.
context
string or object
no
Background for this question, such as the page the customer is on or their cart, up to 8 KB. The agent reads it, but it can't override your instructions. Don't put secrets in it.
Unknown fields are rejected with parameter_unknown. Every request is a new question: sending the same request twice asks twice.
The response
A 200 response says how the question was handled. Every field is always present, and is null when it doesn't apply.
status
How the question was handled: answered, no_reply or blocked (below).
reason
For blocked: {code, message}.
conversation_id
The Zipchat conversation the question was saved in.
escalated
Whether the conversation was escalated to your team when the question was handled. See Escalations.
question.message_id
The saved question.
answer
Only when status is answered: message_id, text and sources.
answer.text
Plain text with line breaks and bare URLs. HTML and Markdown are already removed. Render it as text, never as HTML.
answer.sources
The pages and products the answer links to, in order, for rendering as cards. Each has url and nullable title, description and image_url. URLs carry attribution parameters, so purchases are credited to the conversation.
status
What to show
answered
answer.text and answer.sources.
no_reply
Nothing. The agent chose not to reply.
blocked
Your own fallback. A limit stopped the answer, and reason.code says which: quota_exceeded (your AI replies are used up), customer_reply_limit_reached (this customer reached the reply limit set for the chat) or ai_disabled.
When the AI fails or takes longer than 20 seconds, you get an error instead: 502 generation_failed or 504 timeout. The question is saved either way. New status and reason.code values may be added, so treat unknown ones like blocked.
Streaming
Add "stream": true to the request body to get the answer while it's written, the way Zipchat's chat bubble shows it. Everything else about the request stays the same: the endpoint, the API key and the other fields.
The response is then 200 with Content-Type: text/event-stream: server-sent events. Each event is an event: line with its name and a data: line with a JSON object whose type repeats that name. A blank line ends each event.
Events
question.saved
First, as soon as the question is saved.
conversation_id and question.message_id.
answer.delta
While the agent writes. Any number of times, or none.
delta: the text added since the previous one.
response.completed
Last, once the question is handled.
response: the same body as a response without streaming.
error
Last, instead of response.completed, if the answer fails or takes longer than 20 seconds.
error: {type, code, message, param}, as in Errors.
The deltas are a preview
Show the deltas as they arrive, then replace them with response.answer.text and its sources from response.completed, as Zipchat's chat bubble does. The two can differ:
The deltas are the agent's raw text and can contain Markdown. The final text is plain text, with made-up links removed.
Text the agent writes before it looks something up ("Let me check your order.") streams too, followed by a blank line, but it isn't part of the final answer.
A
no_replymay still have streamed some text. Followresponse.status, as for any response.
Errors in a stream
Errors found before the stream starts, such as an invalid key, invalid input, a disconnected API channel or a 429, are ordinary JSON error responses with their status code. Check the Content-Type before you read the stream.
Once question.saved is sent, the status is already 200, so a later failure arrives as an error event. Drop the preview and treat it like the matching error response: the question is saved, and the answer or a tool action may already have happened, so don't resend it automatically.
The 20-second limit and the rate limits are the same as without streaming. If you disconnect, the question is still answered and saved.
Relay the stream to your customers
Your API key stays on your server, so read the stream in your backend and pass the deltas and the final answer on to the customer's browser over your own connection.
Customers and conversations
Each customer's questions continue their current conversation. A conversation closes after about 24 hours without messages, and the next question starts a new one.
A conversation belongs to one identity: customer.id, customer.email and customer.email_verified together. When any of them changes, the next question starts a new conversation, so one person never sees another's history, even on a shared device.
Guest browsing
id = your session ID
Answers from your store's content. No order lookups.
Guest gives an email in chat
Add email
New conversation, linked to that contact. Still unverified.
Customer logs in
id = account ID, email, email_verified: true
New conversation. The agent can look up their orders and remember past chats.
Customer logs out
Back to the guest values
New conversation. Their history stays private.
Who verifies a customer
You do. Zipchat can't check email_verified: it trusts your backend's word that your own login authenticated this customer and that the email comes from their account.
Escalations
When a customer asks for a person, the agent forwards the request to your support team. It asks for the customer's email first, and tells them to expect a reply by email. The response's escalated turns true.
Your team answers by email, never through the API. You don't need to poll for replies or receive webhooks: the API only ever returns the agent's answers.
The agent keeps answering the customer's new questions after an escalation, so your chat UI works as before.
Show the agent's answer as usual. It already tells the customer that the team will email them.
If you know the customer's email, send it in
customer.emailso the agent doesn't have to ask for it.
Errors
A 4xx or 5xx response always carries an error. Branch on error.type and error.code, never on message. param names the request field at fault, with dots for nested fields.
Every response, success or error, has a request-id header. Include it when you contact support about a request.
HTTP
type
code
Meaning
400
invalid_request_error
malformed_json
The body isn't valid JSON.
401
authentication_error
invalid_token
The key is missing, invalid or revoked.
403
permission_error
api_channel_disconnected
The chat's API channel is disconnected.
413
invalid_request_error
body_too_large
The body is over 32 KB.
415
invalid_request_error
unsupported_content_type
The request isn't application/json.
422
invalid_request_error
parameter_missing, parameter_invalid, parameter_unknown
A body field is missing, invalid or not part of the API. param names it.
429
rate_limit_error
rate_limit_exceeded, concurrent_ask_limit
Too many requests, or the same customer's previous question is still running. See Rate limits.
500
api_error
internal_error
Something failed on Zipchat's side. The question may already be saved.
502
api_error
generation_failed
The AI couldn't generate an answer. The question is saved in the conversation.
504
api_error
timeout
The answer took longer than 20 seconds. The question is saved, and the answer or a tool action may already have happened.
Don't retry a 403. Retry a 429 after Retry-After: nothing was saved. After a 500, 502 or 504, or a response that isn't JSON, the question may already be saved, so don't resend it automatically. New codes may be added, so handle unknown ones by their type.
Rate limits
Each API key has its own limits. Every 429 response includes a Retry-After header in seconds.
Questions
300 per minute per key
rate_limit_exceeded
Questions running at once
1 per customer
concurrent_ask_limit
Each customer has one question at a time. A second question from the same customer.id, or with the same email, while the first is being answered gets 429 concurrent_ask_limit. Different customers are answered in parallel.
Both come with Retry-After: 2, and nothing is saved, so retry the same question with backoff and some jitter.
Timeouts and retries
An answer takes a few seconds, and Zipchat stops waiting for it after 20 seconds. Set your HTTP client timeout to about 30 seconds.
Every request is a new question. If you send the same request twice, the customer's question is asked twice: two questions in the conversation, two AI replies, and any tool action twice.
A timeout doesn't mean nothing happened. The question and its answer may already be saved, or a tool may already have sent an email or created a discount. So:
Don't resend automatically after a
504 timeout, a502, a500, anerrorevent in a stream, a dropped connection, or a response that isn't JSON. The question is saved and the answer may be too. Show the customer that something went wrong and let them ask again.Do retry a
429afterRetry-After. Nothing was saved, so it can't double up.
Last updated