Chat with an agent
Send a visitor's question to an agent and get the answer, either complete (non-streaming) or word by word (streaming). The agent uses its knowledge, its tools and the conversation so far.
Plan: every plan. Credits: 60 per answer.
Host: https://luma.itechintl.com (the LUMA agent runtime).
Authentication: Authorization: Bearer AGENT_CLIENT_TOKEN from the handshake.
Non-streaming
POST https://luma.itechintl.com/v1/ai-agent/chat
curl --request POST 'https://luma.itechintl.com/v1/ai-agent/chat' \
--header 'Authorization: Bearer AGENT_CLIENT_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"pid": "PROJECT_ID",
"chatbot_id": "AGENT_ID",
"query": "Do you deliver on Fridays?",
"user_context": { "platform": "web", "session_id": "SESSION_ID" },
"user_metadata": { "email": "customer1@example.com", "user_profile_name": "Customer 1" }
}'
| Field | Type | Required | Description |
|---|---|---|---|
pid | string | yes | Project ID (same value as in the handshake) |
chatbot_id | string | yes | Agent ID |
query | string | yes | The visitor's message |
user_context.session_id | string | no | Leave out on the first message; LUMA creates a session and returns its ID. Send it back on every next message to keep the conversation. |
user_context.platform | string | no | Channel label, for example web or app |
user_metadata.email | string | no | Visitor email, if known |
user_metadata.user_profile_name | string | no | Visitor name, if known |
Response 200
{
"message": "Success",
"data": {
"answer": "Yes, we deliver every day from 9:00 to 21:00, Fridays included.",
"session_id": "SESSION_ID"
}
}
Streaming
POST https://luma.itechintl.com/v1/ai-agent/chat/stream
Same headers and fields as the non-streaming call, plus messages: the conversation in the AI SDK message
format, ending with the visitor's new message. Send the new message in both query and the last item of
messages. The answer comes back as Server-Sent Events (Content-Type: text/event-stream): one data: line per
event, each a JSON object with a type.
curl --no-buffer --request POST 'https://luma.itechintl.com/v1/ai-agent/chat/stream' \
--header 'Authorization: Bearer AGENT_CLIENT_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"pid": "PROJECT_ID",
"chatbot_id": "AGENT_ID",
"query": "Do you deliver on Fridays?",
"user_context": { "platform": "web", "session_id": "SESSION_ID" },
"messages": [
{ "id": "msg_1", "role": "user", "parts": [ { "type": "text", "text": "Do you deliver on Fridays?" } ] }
]
}'
| Field | Description |
|---|---|
messages | Required for streaming. Each item: id (your unique ID), role (user or assistant), parts ([{ "type": "text", "text": "..." }]). Include earlier turns to give the agent the conversation; the last item is the new visitor message. |
Without messages, the stream ends at once with no answer text.
Example stream:
data: {"type":"start","messageId":"MSG_1"}
data: {"type":"start-step"}
data: {"type":"text-start","id":"MSG_1"}
data: {"type":"text-delta","id":"MSG_1","delta":"Yes, we deliver "}
data: {"type":"text-delta","id":"MSG_1","delta":"every day from 9:00 to 21:00."}
data: {"type":"text-end","id":"MSG_1"}
data: {"type":"finish-step"}
data: {"type":"data-suggestion","data":["What are the delivery fees?","Can I pick a time slot?"]}
data: {"type":"finish"}
data: {"type":"data-session","data":"SESSION_ID"}
data: {"type":"data-finish-reason","data":{}}
data: [DONE]
Event type | Meaning |
|---|---|
start | The answer starts |
start-step, finish-step | Internal steps (for example a tool call); ignore or show progress |
text-start, text-delta, text-end | The answer text; join every delta in order |
data-suggestion | Suggested follow-up questions (when enabled on the agent) |
data-session | The session ID; keep it for the next message |
data-finish-reason | Why the answer ended |
data-provider-error | The AI provider failed; show a retry message |
finish | The answer is complete |
The order of the data-* events can vary; read them by type, not by position.
The stream follows the open AI SDK UI message stream format, so the ai npm package (useChat) can read it
directly. Ignore event types you do not know; new ones may be added.
Reading the stream in JavaScript
// history: earlier turns in the same message format (empty array on the first message)
const res = await fetch("https://luma.itechintl.com/v1/ai-agent/chat/stream", {
method: "POST",
headers: { Authorization: `Bearer ${clientToken}`, "Content-Type": "application/json" },
body: JSON.stringify({
pid: PROJECT_ID, chatbot_id: AGENT_ID, query, user_context: { session_id: sessionId },
messages: [...history, { id: crypto.randomUUID(), role: "user", parts: [{ type: "text", text: query }] }],
}),
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
for (;;) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split("\n");
buffer = lines.pop();
for (const line of lines) {
if (!line.startsWith("data: ")) continue;
const payload = line.slice(6);
if (payload === "[DONE]") break;
const event = JSON.parse(payload);
if (event.type === "text-delta") appendToChat(event.delta);
if (event.type === "data-session") sessionId = event.data;
}
}
Out of credits
When the account has no credits left, the call still answers 200, with a fixed answer that says the AI credits
are exhausted. No AI answer is generated and no credits are used.
Errors
| Status | error.code | When | What to do |
|---|---|---|---|
| 400 | BAD_REQUEST | query, pid or chatbot_id missing | Fix the body |
| 401 | UNAUTHORIZED | Token missing or expired | Run the handshake again, retry once |
| 429 | RATE_LIMITED | Too many requests | Retry with back-off |
| 5xx | SERVER_ERROR | Temporary problem | Retry with back-off |
Error body: { "message": "...", "error": { "code": "...", "detail": "..." } }.