Send Message for Stream

POST /messages/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
  }
}
application/json

Body

  • content string

    Content can be upto 2000 characters.

  • 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.

Responses

  • 200 application/json

    When redirect is set to false

    Hide response attribute Show response attribute object
  • When redirect is set to true.

    Hide headers attribute Show headers attribute
  • 402 application/json

    When 30 days message limit of your subscription plan is reached.

    Hide response attribute Show response attribute object
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."
}