Chat with a conversation history
const url = 'https://ai.work.optidata.cloud/api/ai/text/chat/contextual';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"messages":[{"role":"system","content":"Answer in one word."},{"role":"user","content":"Say OK."}]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://ai.work.optidata.cloud/api/ai/text/chat/contextual \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "messages": [ { "role": "system", "content": "Answer in one word." }, { "role": "user", "content": "Say OK." } ] }'Sends a whole conversation — instructions, earlier questions and
answers — and streams the assistant’s next answer as server-sent events.
The last entry of messages is the one being answered.
Roles follow the usual chat convention: system for instructions,
user for the person’s messages, assistant for earlier answers.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”object
The conversation so far, oldest first. The last entry is answered.
object
Who wrote the message.
The message text.
Examples
{ "messages": [ { "role": "system", "content": "Answer in one word." }, { "role": "user", "content": "Say OK." } ]}Responses
Section titled “ Responses ”The answer, streamed as server-sent events. Each message event’s
data is a JSON-encoded piece of text; a final content-end event
closes the stream.
Examples
id: 0event: messagedata: ""
id: 1event: messagedata: "OK"
id: -1event: content-enddata: {"time": "2026-10-19 11:27:46"}No authentication key was sent.
Authentication failures use an error key rather than message.
object
Examples
No bearer token sent
{ "error": "JWT passport exception: Missing bearer token in request"}The authentication key is expired or not recognised. Get a fresh one and retry.
Authentication failures use an error key rather than message.
object
Examples
{ "error": "JWT passport expired: Passport expired"}A message is missing its role or content, or messages was not sent.
object
The first validation message.
Validation messages keyed by field name.
object
Examples
{ "message": "The messages.0.content field is required.", "errors": { "messages.0.content": [ "The messages.0.content field is required." ] }}