API quickstart
Create one session, submit a user prompt, and follow Co's response. You need Bash, curl, jq, and an App API access token with environments:read, sessions:write, and sessions:read. A personal or service user token works, provided its user can access the environment and session. See authentication.
Get a token and choose an environment
In Settings → Access tokens, select New access token, choose permissions, and select Create. Copy the token into your terminal when prompted. Don’t paste it into a command or commit it to a repository.
export API_BASE='https://api.thecompany.company/v1'
read -r -s -p 'Access token: ' TCC_ACCESS_TOKEN; printf '\n'
export TCC_ACCESS_TOKENList the environments the token can read. Each entry in data includes an id and name. If the list is empty, choose an organization with a readable environment before continuing.
curl --fail-with-body --silent --show-error \
-H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
"$API_BASE/environments" | jq '.data[] | {id, name}'
read -r -p 'Environment ID: ' ENVIRONMENT_IDCreate a session
POST /v1/sessions returns the session record. Save its id for the next request.
SESSION_ID=$(jq -n --arg env "$ENVIRONMENT_ID" \
'{environmentId: $env, name: "API quickstart"}' |
curl --fail-with-body --silent --show-error \
-H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
--data-binary @- "$API_BASE/sessions" | jq -er '.id')Submit text
Use POST /v1/sessions/{id}/events with a TextSubmitted event. This is user input under the authenticated token's identity, not a message from another session. A personal token held by a human can also make that caller the session's directing user; a service user token does not acquire human authority.
The request body is a batch envelope: events contains tagged events, and each TextSubmitted contains messages with content strings. Omit threadId to address the root thread (0), or use a side-chat thread ID. Text is delivered as user text with fold behavior, rather than as a positional queue entry.
SUBMISSION_KEY="quickstart-$SESSION_ID-1"
jq -n --arg key "$SUBMISSION_KEY" \
'{idempotencyKey: $key, receipt: true,
events: [{_tag: "TextSubmitted",
messages: [{content: "Reply with a one-line greeting."}]}]}' |
curl --fail-with-body --silent --show-error \
-H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
--data-binary @- "$API_BASE/sessions/$SESSION_ID/events" |
jq '{status}'With receipt: true, success is 200 with status: "accepted" or "duplicate"; without it, success is 204 No Content. Neither means the agent has finished.
Read and stream the events
curl --fail-with-body --silent --show-error \
-H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
"$API_BASE/sessions/$SESSION_ID/events?limit=100" |
jq '{data, firstId, lastId, hasMore}'For a continuously updating view, open an SSE stream:
curl --fail-with-body --silent --show-error -N \
-H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
-H 'Accept: text/event-stream' \
"$API_BASE/sessions/$SESSION_ID/events/stream"Good to know
GET /v1/sessions/{id}/eventsreturns durable events indata, in ascending ID order by default. UselastIdas the exclusiveaftercursor for the next page whilehasMoreis true.- An event batch contains 1–100 events. A
TextSubmittedcontains 1–100 messages, each with 1–50,000 characters of content. - Reuse the same
idempotencyKey(1–512 characters) only when retrying the same batch. Deduplication is scoped to the session, organization, and caller user and retained for 48 hours. It is at-least-once delivery, not transactional exactly-once: a crash before the receipt is persisted can replay a batch, and retrying a partially executed batch can replay its accepted prefix. - An event's optional
operationIdis correlation metadata, not a deduplication key or a promise of an echoed text message ID. Use the batch receipt for retry decisions; a duplicate produces no new event echo. - For communication from another session, use the distinct session-to-session messaging flow.