Skip to content
QwryAI
Documentation
Pages

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.

POSThttps://api.qwryai.com/api/v1/chat

Authentication

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.

NameTypeRequiredDescription
chatbotIdstringYesThe agent's id, from list_agents.
messagesarrayYesThe 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.
conversationIdstringNoA 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.
contactIdstringNoYour own id for the person chatting, recorded on a new conversation. Ignored with conversationId.
modelstringNoA 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.
temperaturenumberNoFrom 0 to 1. Overrides the agent's temperature for this answer.
streambooleanNotrue streams the answer as plain text. Defaults to false.

Request example

Bash
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?" }
    ]
  }'

Response

With stream left false, the answer comes back whole:

JSON
{
  "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:

JSON
{ "message": "Invalid API Key" }
HTTP statusmessageWhen
400Invalid requestThe 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.
400Invalid JSONThe body isn't valid JSON.
401No API Key providedNo Authorization header was sent.
401Invalid API KeyThe header isn't Bearer <key>, or the key is unknown, deleted or expired.
403API access requires a paid planThe workspace's plan doesn't include API access.
403API key does not have the required permissionsThe key doesn't hold Chat with agents, or its creator left the workspace.
403Message limit reachedThe workspace doesn't have enough credits for this answer.
403Requests from your country are blocked for this agentThe request comes from a country the agent blocks in Guardrails.
403Conversation does not belong to this agentThe conversationId doesn't exist or belongs to another agent.
403Conversation is not ongoingThe conversation ended, a teammate took it over, or another answer in it is still being written.
404Agent not foundNo agent with that chatbotId in your workspace.
429Too many requests, please try again laterToo many answers are streaming at once. Retry shortly.
500Something went wrong, please try againThe answer failed on our side.

Explore the documentation