Send Message for Stream
Send a message and get back a SSE (Server-Sent Events) stream for the AI response.
An example of how to handle SSE stream in Javascript.
let message = ''
const evtSource = new EventSource('https://stream.aimcaiface.com/abc...123')
evtSource.onmessage = (event) => {
const data = event.data
if (data === '[END]') {
// Request is closed by our servers once `[END]` is sent,
// you must close the request otherwise the browser will keep retrying the URL.
evtSource.close()
} else if (data !== '[START]') {
message += JSON.parse(data).chunk
}
}
Body
-
content string
Content can be upto 2000 characters.
-
conversation_id string
-
redirect boolean
By default, your request will be redirected to another url that will be a SSE stream. You can disable that and get the url in a json object instead.
Default value is
true
.
POST /messages/stream
curl \
-X POST https://getcody.ai/api/v1/messages/stream \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"content":"string","conversation_id":"string","redirect":true}'
Request example
{
"content": "string",
"conversation_id": "string",
"redirect": true
}
Response examples (200)
{
"data": {
"stream_url": "https://stream.aimcaiface.com/eyJpdiI6ImFyellpVWxScDBJdCtySGo0TzJtV3c9PSIsInZhbHVlIjoibW1VM1BDZkVZTGZ6T0ZrSG50dXhrQT09IiwibWFjIjoiZTA1NzYzMTgyMzUwOTU1MTUzMjYwZWY4NTI0MjcyODgxZjZkZDA1MTE3OWY2MjA5NmEzNTg3ZjdiZTM0NjAxNSIsInRhZyI6IiJ9"
}
}
Response examples (402)
{
"message": "You have reached the message limit for last 30 days, please wait till tomorrow or upgrade your plan."
}