Skip to Content

Chat API

Send messages to an agent and receive AI-generated responses.

Send a Message

POST /api/public/agents/{agentId}/chat

Path Parameters

ParameterTypeRequiredDescription
agentIdstringYesThe unique identifier of the agent

Request Body

FieldTypeRequiredDescription
messagestringYesThe user’s message text
sessionIdstringYesA unique session identifier for conversation continuity
visitorIdstringNoPersistent visitor identifier (survives sessions)
visitorEmailstringNoVisitor’s email address (used for lead capture)
visitorNamestringNoVisitor’s display name
metadataobjectNoArbitrary key-value metadata to attach to the message

Headers

HeaderValueRequired
AuthorizationBearer agx_live_YOUR_KEYYes
Content-Typeapplication/jsonYes

Response

The response is a streaming text response by default. The Content-Type is text/plain with chunked transfer encoding. Each chunk contains a portion of the agent’s response as it is generated.

The response also includes these headers:

HeaderDescription
X-Conversation-IdThe conversation ID for this session
X-Message-IdThe unique ID of the assistant’s response message
X-UI-SpecJSON-encoded rich UI specification (when applicable)

Examples

cURL

curl -X POST https://app.agentix.cl/api/public/agents/abc123/chat \ -H "Authorization: Bearer agx_live_YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "message": "What products do you have under $50?", "sessionId": "visitor-session-001", "visitorEmail": "customer@example.com" }'

JavaScript (fetch)

const response = await fetch( 'https://app.agentix.cl/api/public/agents/abc123/chat', { method: 'POST', headers: { 'Authorization': 'Bearer agx_live_YOUR_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ message: 'What products do you have under $50?', sessionId: 'visitor-session-001', }), } ) // Read streaming response const reader = response.body.getReader() const decoder = new TextDecoder() while (true) { const { done, value } = await reader.read() if (done) break const chunk = decoder.decode(value) process.stdout.write(chunk) }

Python (requests)

import requests response = requests.post( 'https://app.agentix.cl/api/public/agents/abc123/chat', headers={ 'Authorization': 'Bearer agx_live_YOUR_KEY', 'Content-Type': 'application/json', }, json={ 'message': 'What products do you have under $50?', 'sessionId': 'visitor-session-001', }, stream=True, ) for chunk in response.iter_content(chunk_size=None, decode_unicode=True): print(chunk, end='')

Error Responses

StatusCodeWhen
400INVALID_AGENT_IDAgent ID is missing or empty
400INVALID_REQUEST_DATAMissing message or sessionId
400INVALID_JSONRequest body is not valid JSON
401MISSING_API_KEYNo API key provided
401INVALID_API_KEYAPI key is invalid
403AGENT_NOT_PUBLICAgent is not public
403AGENT_INACTIVEAgent status is not active
403ORG_MISMATCHAPI key org does not match agent org
403DOMAIN_NOT_ALLOWEDRequest origin not in allowed domains
404AGENT_NOT_FOUNDAgent does not exist
429RATE_LIMITEDRate limit exceeded (60 req/min)

Conversation Continuity

The sessionId is the key to maintaining conversation context. Messages with the same sessionId are grouped into a single conversation. The agent retains the full message history for context.

Best practices:

  • Use a consistent sessionId per user session (e.g., browser session ID)
  • Generate a new sessionId when the user explicitly starts a new conversation
  • The visitorId persists across sessions for returning user identification

Rich UI Responses

When an agent has ecommerce tools enabled and generates structured data (product cards, order details, etc.), the X-UI-Spec response header contains a JSON-encoded UI specification. Your client can parse this to render rich components.

{ "type": "product-grid", "data": [ { "title": "Blue Widget", "price": "$24.99", "image": "https://...", "url": "https://..." } ] }
Last updated on