Create chat session
Open a text chat with an agent and get its greeting. Then send messages with Send chat message, and call End chat session when you are done. A session with no message for 30 minutes ends on its own.
Call this from your server: your API key must never reach a browser or app. Add a chat agent to any website or app walks through the whole flow.
A live chat is for your customers:
- talks to the agent as you last published it;
- runs the agent's tools for real (
tool_resultsis refused). Its end call and transfer tools end the chat; a transfer reports the number intransferred_toand connects nobody, so route the customer yourself; - is listed under the
API-Chatchannel in Call Logs; - runs post-call analysis and the agent's post-call actions (webhooks, email, connected apps), as a call does.
A test chat (the default) is for checking an agent:
- talks to the agent as you last edited it, so you can fix the agent and test again before you publish;
- never runs the agent's tools. Each tool returns what you set in
tool_results, or{"status": "ok", "data": {}}when you set nothing. The end call and transfer tools still run, so you see the agent end or transfer the chat; - is listed under the
MCP-Testchannel, apart from your real chats; - runs post-call analysis to extract variables, and sends nothing to your webhooks, email or connected apps;
Each agent reply is billed as a chat message, paid from your balance
before the agent answers (see Chat API). A
balance too low for one more reply is refused with
insufficient_balance. A session ends after 100 agent replies.
A test chat's response also has a briefing: the agent's tools with
their exact names and parameters (key tool_results by these names),
and the dynamic variables its prompt expects, with the ones you did not
pass in custom_variables.
To test an agent well, play one caller goal per chat. Judge the agent
on the tools it called and their arguments (tool_calls) and on the
final record, not only on what it said.
Body
agent_idintegerrequiredID of the agent to chat with.
modeenumlive for your customers (real tools and post-call actions), test to check the agent (scripted tools, nothing delivered).
One of: livetest
Default test
custom_variablesobjectVariables that personalize the conversation, as on a call.
tool_resultsobjectTest chats only. What each of the agent's tools returns, keyed by
tool name. The agent sees the value as the tool's result. Script a
failure as {"status": "error", "error": "<short_code>"}. A tool you
leave out returns {"status": "ok", "data": {}}.
Was this page helpful?
