Endpoints
Chat with a chatbot
Send a message history to an agent and get its answer, whole or streamed as plain text
The v1 chat endpoint sends the latest customer message in messages to an agent and returns its answer. Without a conversationId, every call stands alone: the agent reads the earlier turns from messages, and the exchange isn't kept in your Inbox. With a conversationId, the message continues that saved conversation instead.
https://api.qwryai.com/api/v1/chatAuthentication
Send your API key as Authorization: Bearer YOUR_API_KEY. The key needs Chat with agents. See Authentication.
Body parameters
The body is JSON, up to 1 MB. Fields not listed here are refused.
| Name | Type | Required | Description |
|---|---|---|---|
chatbotId | string | Yes | The agent's id, from list_agents. |
messages | array | Yes | The conversation so far, oldest first, each { "role", "content" } with role set to user or assistant. The last item must have role: "user"; it's the message the agent answers. |
conversationId | string | No | A saved conversation to continue, such as the conversationId the Chat API returned. Only the last message in messages is added to it. The conversation must still be answered by the AI. |
contactId | string | No | Your own id for the person chatting, recorded on a new conversation. Ignored with conversationId. |
model | string | No | A model to answer with instead of the agent's own. It must be one the agent can use; list_available_models lists them. Credits follow the model used. |
temperature | number | No | From 0 to 1. Overrides the agent's temperature for this answer. |
stream | boolean | No | true streams the answer as plain text. Defaults to false. |
Request example
curl -X POST 'https://api.qwryai.com/api/v1/chat' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"chatbotId": "YOUR_AGENT_ID",
"messages": [
{ "role": "user", "content": "Do you ship to Canada?" },
{ "role": "assistant", "content": "Yes, we ship to Canada." },
{ "role": "user", "content": "How long does it take?" }
]
}'const response = await fetch("https://api.qwryai.com/api/v1/chat", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
chatbotId: "YOUR_AGENT_ID",
messages: [{ role: "user", content: "How long does shipping to Canada take?" }],
stream: true,
}),
});
// stream: true sends the answer as plain text chunks
const reader = response.body.getReader();
const decoder = new TextDecoder();
let answer = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
answer += decoder.decode(value, { stream: true });
}
console.log(answer);import requests
response = requests.post(
"https://api.qwryai.com/api/v1/chat",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"chatbotId": "YOUR_AGENT_ID",
"messages": [{"role": "user", "content": "How long does shipping to Canada take?"}],
},
)
print(response.json()["text"])Response
With stream left false, the answer comes back whole:
{
"text": "Orders to Canada arrive in 5 to 8 business days."
}With "stream": true, the response is text/plain and the answer arrives as raw text chunks as it's written. There are no event names or ids; the stream ends when the answer is complete. If the answer fails after streaming started, the stream simply ends.
Errors
Errors come back as JSON with a readable message and no code:
{ "message": "Invalid API Key" }| HTTP status | message | When |
|---|---|---|
| 400 | Invalid request | The body failed validation: chatbotId or messages is missing, the last message isn't from the user, temperature is outside 0 to 1, an unknown field was sent, model isn't available, or the body is over 1 MB. |
| 400 | Invalid JSON | The body isn't valid JSON. |
| 401 | No API Key provided | No Authorization header was sent. |
| 401 | Invalid API Key | The header isn't Bearer <key>, or the key is unknown, deleted or expired. |
| 403 | API access requires a paid plan | The workspace's plan doesn't include API access. |
| 403 | API key does not have the required permissions | The key doesn't hold Chat with agents, or its creator left the workspace. |
| 403 | Message limit reached | The workspace doesn't have enough credits for this answer. |
| 403 | Requests from your country are blocked for this agent | The request comes from a country the agent blocks in Guardrails. |
| 403 | Conversation does not belong to this agent | The conversationId doesn't exist or belongs to another agent. |
| 403 | Conversation is not ongoing | The conversation ended, a teammate took it over, or another answer in it is still being written. |
| 404 | Agent not found | No agent with that chatbotId in your workspace. |
| 429 | Too many requests, please try again later | Too many answers are streaming at once. Retry shortly. |
| 500 | Something went wrong, please try again | The answer failed on our side. |