Skip to content

Your first AI conversation ​

Create a conversation, send one message, and follow the assistant's reply as it arrives. You will keep the IDs returned by the API rather than substituting example values.

Before you begin ​

Complete prerequisites. You need curl, jq, an interactive access token, and the applicable AI access and usage allowance. Generating a reply can consume AI usage. If you want to begin with work management instead, use the task tutorial.

Set your access token in your terminal. The examples already use the API address, so it is the only value you need to set:

bash
export TOKEN="YOUR_ACCESS_TOKEN"

A developer token is not interchangeable with the interactive token used here. See developer access for supported automation routes.

Step 1: Create an AI session ​

A session holds the conversation. Give it a title you can recognize later.

SESSION_RESPONSE="$(curl --fail-with-body -sS -X POST "https://api.chainabit.com/api/v1/ai/sessions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title":"My first API conversation"}')"
printf '%s\n' "$SESSION_RESPONSE" | jq .
export SESSION_ID="$(printf '%s\n' "$SESSION_RESPONSE" | jq -er '.data.id')"

Expect 201 Created and the session object in data. These are selected fields, with an illustrative UUID:

json
{
  "data": {
    "id": "00000000-0000-4000-8000-000000000001",
    "title": "My first API conversation",
    "status": "active"
  }
}

The command exports the returned UUID as SESSION_ID. Use it in the next request.

Step 2: Send a message ​

MESSAGE_RESPONSE="$(curl --fail-with-body -sS -X POST "https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID/messages" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content":"Suggest three steps for reviewing a product launch checklist."}')"
printf '%s\n' "$MESSAGE_RESPONSE" | jq .
export MESSAGE_ID="$(printf '%s\n' "$MESSAGE_RESPONSE" | jq -er '.data.assistantMessage.id')"

Expect 201 Created. The result includes a user message, an assistant message, and the run that will produce the answer. The assistant message can still be pending when this request returns. An accepted request is not yet a completed answer.

Capture data.assistantMessage.id for streaming. The user message ID identifies your input and is not the response stream to follow.

Step 3: Stream the response ​

curl --fail-with-body -sS -N \
  "https://api.chainabit.com/api/v1/ai/sessions/$SESSION_ID/messages/$MESSAGE_ID/stream" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: text/event-stream"

The -N option disables curl's output buffering. A successful connection returns 200 OK with a text/event-stream response. The first event is a connection preamble. Later events include numbered envelopes. A shortened example is:

text
event: stream.connected
data: {"runId":"00000000-0000-4000-8000-000000000003"}

id: 1
event: message.delta
data: {"eventId":1,"type":"message.delta","runId":"00000000-0000-4000-8000-000000000003","timestamp":"2026-10-21T10:00:00.000Z","payload":{"delta":"Start by reviewing"},"v":1}

Text deltas are pieces of an answer. Follow the terminal event before showing the run as completed; a stream can also report failure or cancellation. The streaming reference defines the event types, completion events, and reconnection behavior.

Native browser EventSource cannot set this Authorization header. Use a streaming HTTP client with header support; do not put your token in the URL.

If something goes wrong ​

SymptomNext step
401Obtain a fresh interactive access token through authentication.
403Check the error code, AI entitlement, workspace permissions, and subscription coverage.
429Follow rate-limit guidance before retrying.
The stream has no assistant textCheck the terminal events and use the assistant message ID captured in step 2.
The connection dropsReconnect with the last event ID as described in stream reconnection.

Do not continue with an empty ID after a failed request. Inspect the error response first.

What's next ​

Built with purpose. chainabit.com