Skip to content
QwryAI
Documentation
Pages

Endpoints

Chat with an agent

Send a customer's message to an agent and get its answer, streamed or in one response

This is the Chat API's main endpoint. Send the customer's message and QwryAI answers with the agent's live instructions, knowledge and actions, just as it would in the Chat bubble. Leave out conversationId to start a new conversation; send it to continue one. The answer streams by default; send "stream": false to get it as one JSON object.

Conversations started here appear in the Inbox under the API channel, and each answer uses message credits.

POSThttps://api.qwryai.com/api/v2/agents/{agentId}/chat

Authentication

Send your API key as Authorization: Bearer <api-key>. The key needs Chat with agents. See Authentication.

Path parameters

NameTypeRequiredDescription
agentIdstringYesThe agent's id, from list_agents.

Body parameters

NameTypeRequiredDescription
messagestringYes, unless conversationId is sentThe customer's message. Leave it out only to let the agent continue after you submit a tool result.
conversationIdstringNoThe conversation to continue, from an earlier answer's metadata. Leave it out to start a new conversation.
streambooleanNoStream the answer as Server-Sent Events. Defaults to true.
userIdstringNoYour id for the customer, on a new conversation. Up to 128 characters from a-z A-Z 0-9 . _ -. Ignored when conversationId is sent. See User Conversations.

Any other field is refused with VALIDATION_INVALID_BODY. The body can be at most 1 MB.

Request example

Bash
curl -X POST 'https://api.qwryai.com/api/v2/agents/YOUR_AGENT_ID/chat' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "message": "Where is my order 1042?",
    "userId": "customer_1042",
    "stream": false
  }'

Response

With "stream": false, you get the whole answer once it's finished:

JSON
{
  "data": {
    "id": "5b0e7c1a-2f4d-4c55-9a51-6d8e3f2b9c10",
    "role": "assistant",
    "parts": [
      { "type": "text", "text": "Order 1042 shipped on Monday with UPS and should arrive by Friday." }
    ],
    "metadata": {
      "conversationId": "fd5ae9e1-9b30-4503-b346-ccd4d7ef16a3",
      "userMessageId": "0c4f6a2e-8d13-4b7a-b0e9-1a2c3d4e5f60",
      "userId": "customer_1042",
      "finishReason": "stop",
      "usage": { "credits": 1 }
    }
  }
}
FieldTypeDescription
data.idstringThe answer's id. Pass it as messageId to Retry a message.
data.rolestringAlways assistant.
data.partsarrayThe answer in order: text parts, a tool-call part for each action the agent called, and a tool-result part for each action QwryAI ran.
data.metadata.conversationIdstringThe conversation's id. Send it with the next message.
data.metadata.userMessageIdstringThe id of the customer message this answer replies to.
data.metadata.userIdstring | nullThe conversation's userId, or null.
data.metadata.finishReasonstringstop when the answer is complete, tool-calls when it waits for a client action result, error if it failed.
data.metadata.usage.creditsnumberMessage credits this answer used.

Errors

HTTP statusCodeWhen
400VALIDATION_INVALID_BODYNo message on a new conversation, an unknown field, a bad userId, or a body over 1 MB. details names each field.
400VALIDATION_INVALID_JSONThe body isn't valid JSON.
401AUTH_MISSING_API_KEYNo Authorization header.
401AUTH_INVALID_API_KEY / AUTH_EXPIRED_API_KEYThe key is malformed, unknown, deleted or expired.
402CHAT_CREDITS_EXHAUSTEDThe workspace doesn't have enough message credits for this answer.
403AUTH_INSUFFICIENT_PERMISSIONSThe key lacks Chat with agents, or its creator left the workspace.
403SUBSCRIPTION_API_RESTRICTED_PLANThe workspace's plan doesn't include API access.
403ACCESS_COUNTRY_BLOCKEDThe request comes from a country the agent blocks in Guardrails.
403CHAT_CONVERSATION_MISMATCHThe conversationId doesn't exist or belongs to another agent.
404AGENT_NOT_FOUNDNo agent with that id in your workspace.
409CHAT_CONVERSATION_NOT_ONGOINGThe conversation ended, a teammate took it over, its AI replies are paused, or another answer is still being written.
429RATE_LIMIT_TOO_MANY_REQUESTSToo many requests, or too many open streams. Wait for Retry-After seconds.
500INTERNAL_SERVER_ERRORSomething failed on our side. Quote the x-request-id header to support.

See Error Handling for every code.

Explore the documentation