Chat API
Put your agent in your own chat window, on any website or app, with the Chat Sessions API. Test it first with scripted tools, from your code or from an AI tool over MCP.
The Chat API lets your agent answer text messages anywhere you can show text: your own chat window on a website, a mobile app, a support portal, or a backend that relays messages from another system. You build the chat window; OmniDimension runs the agent.
Each conversation is a chat session. Your server opens a session, sends each customer message, shows the agent's reply, and ends the session when the conversation is over. The agent uses everything you set up for it: its prompt, knowledge base, tools and post-call actions.
Pick the right option
| You want | Use |
|---|---|
| A chat bubble on your website with no code | Web chat widget |
| The agent in your own chat window or app | The Chat API in live mode (this page) |
| To check an agent before customers see it, with tools you control | The Chat API in test mode (Test your agent) |
| An AI tool such as Claude or Cursor to test and fix the agent for you | The same API over MCP |
| Voice in your own app | Web call sessions |
How it works
Before you start
- An agent you have published. A live chat answers with the published version, the same one your phone calls use. See Agent versioning and publishing.
- Your API key, kept on your server. See Authentication.
- Balance in your account. Each agent reply is charged; see Cost.
All requests go to https://omnidim.io/api/v1 with the header
Authorization: Bearer YOUR_API_KEY.
Build a live chat
Open a session when the customer starts chatting
Call Create chat session
with your agent's id and "mode": "live". The reply is the agent's greeting:
show it as the first message in your chat window. Keep the session_id for
this customer's conversation.
curl -X POST https://omnidim.io/api/v1/chat/sessions/create \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": 158910,
"mode": "live",
"custom_variables": { "name": "Ada", "plan": "Gold" }
}'{
"session_id": 4521,
"reply": "Hi Ada, this is Sam from Demo Dental. How can I help?",
"tool_calls": [],
"should_end": false
}custom_variables fills the agent's
dynamic variables, as on a call:
pass what you already know about the customer so the agent does not have to ask.
Send each customer message
Call Send chat message with the customer's text. The response holds the agent's reply, which you show in the chat window.
curl -X POST https://omnidim.io/api/v1/chat/sessions/4521/message \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "message": "Can I book a cleaning for tomorrow at 10?" }'{
"session_id": 4521,
"reply": "Done, you are booked for a cleaning tomorrow at 10 am.",
"tool_calls": [
{
"function_name": "book_appointment",
"args": "{\"date\": \"2026-12-01\", \"time\": \"10:00\"}",
"result": "{\"status\": \"ok\", \"data\": {\"booking_id\": \"B-1042\"}}",
"success": true
}
],
"should_end": false
}- One message at a time. Wait for the reply before you send the next message in the same session. A reply usually takes a second or two, longer when the agent calls a tool; show a typing indicator meanwhile.
tool_callslists the tools the agent ran on this turn, with their arguments and results. Your chat window can ignore it, or use it, for example to show a booking card.statusturnsendedwhen the agent closes the chat itself (see below). Show the reply, then close your chat window. You do not need to call End chat session.
When the agent ends or transfers the chat
The agent closes a chat the way it ends a call, following its own call settings:
- End call: when the conversation is done, the agent says goodbye and runs
end_call. - Transfer: when the customer must go to a person, the agent runs
transfer_calland tells the customer the number they are being transferred to. Nothing is dialed: the response gives you the number intransferred_to, so you can show it, open a phone link, or hand the chat to your team.
That turn's response says the chat is over and carries the whole conversation, so you can act on it right away:
{
"session_id": 4521,
"reply": "Sure, I am transferring you to +15551234567 now.",
"tool_calls": [{ "function_name": "transfer_call", "args": "{\"transfer_option_index\": 0}", "success": true }],
"should_end": true,
"status": "ended",
"ended_by": "transfer",
"transferred_to": "+15551234567",
"transcript": [
{ "role": "agent", "text": "Hi, this is Sam from Demo Dental. How can I help?" },
{ "role": "customer", "text": "I need to talk to a person." },
{ "role": "agent", "text": "Sure, I am transferring you to +15551234567 now." }
]
}ended_by is agent (end call), transfer, client (you called End chat
session) or idle (30 minutes with no message).
End the session
Call End chat session when the customer closes the chat or your own timeout passes. This saves the chat, runs post-call analysis and the agent's post-call actions, and returns the transcript. When the agent ended the chat itself, it is already saved; calling End chat session then only reports how it ended.
curl -X POST https://omnidim.io/api/v1/chat/sessions/4521/end \
-H "Authorization: Bearer YOUR_API_KEY"If you never call it, for example because the customer closed the tab, the
session ends on its own after 30 minutes with no message. After a session
ends, a new message returns 409 session_ended: open a new session.
Get the results
Once the chat ends, the agent's post-call actions run as they do after a call:
your webhook, email report, CRM,
Google Sheets or workflow receives the transcript, summary and extracted
variables. The chat is also in Call Logs on the API-Chat channel.
To read the record from your code instead, call
Get chat session until
analysis_status is done (usually a few seconds after the end). call_log
holds the record in the same shape as Get call log.
A complete server
This server gives your chat window three routes of its own and keeps the API key out of the browser. It is a starting point: add your own login, rate limits and storage.
import express from 'express';
const API = 'https://omnidim.io/api/v1';
const KEY = process.env.OMNIDIM_API_KEY; // never sent to the browser
const AGENT_ID = 158910;
async function omni(path, body) {
const res = await fetch(`${API}${path}`, {
method: 'POST',
headers: { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify(body ?? {}),
});
const data = await res.json();
if (!res.ok) throw Object.assign(new Error(data.error_description), { status: res.status, code: data.error });
return data;
}
const app = express();
app.use(express.json());
// The chat window opens: start a session and return the greeting.
app.post('/chat/start', async (req, res) => {
const turn = await omni('/chat/sessions/create', {
agent_id: AGENT_ID,
mode: 'live',
custom_variables: { name: req.body.name },
});
res.json(turn); // { session_id, reply, tool_calls, should_end }
});
// The customer sends a message.
app.post('/chat/:id/message', async (req, res) => {
try {
const turn = await omni(`/chat/sessions/${req.params.id}/message`, { message: req.body.message });
res.json(turn); // turn.status === 'ended': the agent closed the chat (see transferred_to)
} catch (e) {
res.status(e.status ?? 500).json({ error: e.code });
}
});
// The customer closes the chat.
app.post('/chat/:id/end', async (req, res) => {
await omni(`/chat/sessions/${req.params.id}/end`);
res.json({ ok: true });
});
app.listen(3000);Your chat window then calls only your server:
const { session_id, reply } = await post('/chat/start', { name: 'Ada' });
showAgentMessage(reply);
async function onCustomerMessage(text) {
showCustomerMessage(text);
const turn = await post(`/chat/${session_id}/message`, { message: text });
showAgentMessage(turn.reply);
if (turn.status === 'ended') closeChat(turn.transferred_to); // e.g. show "Call us at ..."
}
window.addEventListener('pagehide', () => navigator.sendBeacon(`/chat/${session_id}/end`));
async function post(url, body) {
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body ?? {}),
});
return res.json();
}Test your agent before you go live
A test session runs the same agent with three differences, so you can check
it without touching real systems:
- It talks to your latest edits, before you publish them.
- The agent's tools never run. Each tool returns what you set in
tool_results, so you can play out a tool that succeeds, fails or times out. A tool you leave out returns{"status": "ok", "data": {}}. The end call and transfer tools still run, so you see when the agent would hang up or transfer, and to which number. - Post-call analysis extracts the variables, but nothing is delivered: no
webhook, email or CRM update. The chat is listed on the
MCP-Testchannel.
curl -X POST https://omnidim.io/api/v1/chat/sessions/create \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": 158910,
"mode": "test",
"tool_results": {
"book_appointment": { "status": "error", "error": "calendar_unavailable" }
}
}'The response to a test session's creation also has a briefing, so you script
the right tools and fill the right variables:
"briefing": {
"agent_version": "draft",
"tools": [
{ "name": "book_appointment", "description": "Book a visit…", "parameters": { "type": "object", "properties": { "date": { "type": "string" } } }, "runs_in_test": false },
{ "name": "end_call", "description": "End this chat. Use it when: …", "parameters": {}, "runs_in_test": true }
],
"dynamic_variables": ["name", "plan"],
"missing_variables": ["plan"]
}Key tool_results by the tool names listed there. Pass every name in
missing_variables in custom_variables, or the agent talks with blanks.
Then send messages as in a live chat. To change what a tool returns for one
message only, add tool_results to that message:
curl -X POST https://omnidim.io/api/v1/chat/sessions/4522/message \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"message": "Try 11 instead, please.",
"tool_results": { "book_appointment": { "status": "ok", "data": { "booking_id": "B-1" } } }
}'End the session, then read the record with
Get chat session: check the
transcript, the tools the agent called with their arguments (tool_calls on
each turn), and whether extracted_variables hold what you expect.
In a test chat, each entry in tool_calls has a source: scripted (your
tool_results), default (you scripted nothing, so it got an empty success)
or real (the end call and transfer tools). If the agent states details after a
default result, such as an order status it was never given, it is making them
up.
A chat test checks what the agent says and does. It cannot show how it sounds on a call: speech recognition mistakes, interruptions, silence, latency and pronunciation only show on a real call. Voice prompts may also write numbers as words, which reads oddly in chat and is right on a call.
Good test chats play one customer goal each: a normal booking, a tool that fails, a customer who goes off topic, a question the agent must refuse. Judge the agent on what it did (the tools it called and the final record), not only on how it sounded.
Test from an AI tool over MCP
The four chat session endpoints are also tools in the
OmniDimension MCP server: createChatSession, sendChatMessage,
endChatSession and getChatSession. Connect Claude, ChatGPT, Cursor or
another MCP client, then ask it to test your agent in plain words:
Test my agent "Demo Dental Receptionist" in test mode. Play four customers:
a normal cleaning booking, one where book_appointment fails with
calendar_unavailable, one who asks for a diagnosis, and one who goes off topic.
Read each chat's record and tell me where the agent went wrong.The omnidim-test-agent playbook (in
OmniDimension skills, and served by the MCP
server) tells the AI tool how to do this well. It writes the scenarios from the
agent's own tools, plays the customer, scripts the tool results and reads back
each record. When the agent ends or transfers a chat,
the reply says so (status: ended, ended_by, transferred_to) with the
whole transcript, so the AI tool knows the conversation is over and can judge
whether the agent ended at the right moment. It changes the agent only after you
approve each fix, saves a version first, and never publishes: you publish when
you are satisfied. It can then suggest prompt changes, apply
them with updateAgent once you agree, and run the same chats again. Save a
version first (Agent versioning)
so you can go back.
Cost
Each agent reply is charged as a chat message, $0.006 by default, the greeting included. Customer messages are free. A chat of ten agent replies costs $0.06. Each reply is paid from your balance just before the agent answers, and refunded if the agent fails to answer, so your balance always shows what your chats have used. It is listed on your usage statement under Chat messages. Live and test chats cost the same.
If your balance cannot pay for one more reply, Create chat session and Send
chat message return 402 insufficient_balance. Show the customer a fallback,
such as a contact form, and top up.
Errors
| Status | error | What to do |
|---|---|---|
| 400 | unsupported_mode | Use live or test. |
| 400 | invalid_request | Check the body: an integer agent_id, a non-empty message, and tool_results only in a test chat. |
| 401 | Check the API key. | |
| 402 | insufficient_balance | Top up your balance. |
| 404 | agent_not_found / session_not_found | The agent or session is not in your account. |
| 409 | session_ended | Open a new session. ended_by says why it ended. |
| 502 | agent_unavailable | The agent did not answer in time. Send the same message again. |
Good to know
- Text only. For voice in your own app, use web call sessions.
- Every reply waits for the agent. The response comes when the reply is ready; allow up to 60 seconds before your server gives up.
- One session per conversation. Open a new one for each customer or
each new conversation; a session cannot be reopened. A session ends after
100 agent replies (
ended_by: turn_limit). - Real tools in live chats. A live chat books, updates and sends exactly as a call would. Use a test chat while you are building.
- A transfer connects nobody. It ends the chat and gives you the number; routing the customer is up to your chat window.
API reference
Was this page helpful?
