All pages

API reference

Start a chat

POST /v1/chats

View as Markdown

Start a chat with one of your agents by sending its first message. Answers 201 with the first chat.turn: the agent's greeting in opening, and its reply. Send stream: true for the reply as server-sent events. Needs chats:write. An Idempotency-Key is optional: the same request again returns the same chat.

Parameters

Name In Type Required Description
Idempotency-Key header string No Your own id for this chat. Optional.

Body

Sent as JSON. A field this operation does not take is refused, so a typo fails loudly.

Field Type Required Description
agent_id string (uuid) Yes The agent to chat with.
agent_version integer or null No Answer with this published version of the agent rather than what is live now — its number from GET /v1/agents/{id}/versions. Its values and languages are that version's, and every turn of the conversation keeps it.
attachment_ids array of string (uuid) No Pictures to send with it, from POST /v1/attachments.
external_id string or null No
language string or null No One of the agent's language versions, like ar.
message string Yes What the person wrote.
metadata object No Your own data, returned on every read and event. The agent never sees it.
stream boolean No Send the reply as it is written, as server-sent events. Accept: text/event-stream does the same.
variables object No Values for the agent's {{placeholders}}. See its variables_schema.

Answer

201 with ChatTurn.

With stream: true, the same answer arrives as server-sent events instead — see Chat and streaming.

Errors

Every error is a problem document with a stable code.

Status When
401 The key is missing, mistyped, unknown, revoked or expired.
402 The organization's credit is used up.
403 The key lacks a permission, a live key was sent from a browser, or the organization is frozen and the request would change something.
404 This key reaches no such agent.
409 The agent is not published, its project is frozen, or the first message is still being answered.
422 A field, a variable or the language does not fit.
429 Too many requests for this key or its organization; see Retry-After.
500 Something went wrong on our side. Quote the request_id to support.

Examples

Start a chat
#!/bin/sh
# Start a chat
curl -sS --fail-with-body -X POST "https://api.aigently.ai/v1/chats" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY" \
  -H "Idempotency-Key: chat-20931" \
  --json '{
  "agent_id": "3c7d9e1f-5a2b-4c6d-8e0f-1a3b5c7d9e2f",
  "message": "Hello, I would like to book a table.",
  "variables": {
    "first_name": "Sara"
  }
}'

Try it

Sends this request to the API from your browser, with a test key. Nothing it does rings a phone.