BookbagBookbag

Chat with an agent (v2)

POST /api/v2/agents/:agentId/chat — send a message and stream or receive the reply. Continue conversations, identify users, retry, submit tool results, and set feedback.

View as Markdown

POST /api/v2/agents/:agentId/chat

Send a message to an agent. By default the reply streams in the v2 streaming format; set stream: false for a single JSON response. Omit conversationId to start a new conversation, or pass it to continue one.

Auth

Requires Authorization: Bearer oc_.... The key's workspace must own the agent; an agent-scoped key may only target its agent.

Path & body

FieldInTypeRequiredNotes
agentIdpathintegerYesThe agent id.
messagebodystringYesNon-empty after trimming.
userIdbodystringNoYour end-user id. Must match ^[a-zA-Z0-9._-]{1,128}$. Groups conversations per person.
conversationIdbodyintegerNoContinue an existing conversation. Must belong to this agent.
streambodybooleanNoDefaults to true. Set false for a JSON response.

Streaming request

curl -N https://app.bookbag.ai/api/v2/agents/123/chat \
  -H "Authorization: Bearer $BOOKBAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "message": "Where is my order?", "userId": "user_8821" }'

See the streaming guide for a full parsing example.

Non-streaming request

curl https://app.bookbag.ai/api/v2/agents/123/chat \
  -H "Authorization: Bearer $BOOKBAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "message": "Where is my order?", "userId": "user_8821", "stream": false }'

Status codes

StatusCodeMeaning
200Streamed or JSON reply.
400VALIDATION_INVALID_BODYEmpty message, or userId that fails the pattern.
401AUTH_MISSING_API_KEY / AUTH_INVALID_API_KEYMissing or invalid key.
403AUTH_INSUFFICIENT_PERMISSIONSAgent-scoped key targeting a different agent.
404RESOURCE_NOT_FOUNDAgent not found/archived, or conversationId not in this agent.
429RATE_LIMIT_TOO_MANY_REQUESTSRate limit exceeded.
500INTERNAL_SERVER_ERRORUnexpected error (non-streaming path).

These operate on a conversation that belongs to the agent.

Retry — POST .../conversations/:conversationId/retry

Re-run the last user turn. Truncates the conversation at the user message that produced messageId and regenerates from there. Streams (or returns JSON) like chat.

FieldTypeRequiredNotes
messageIdstringYesThe assistant message to retry (e.g. msg_789). The msg_ prefix is optional.
streambooleanNoDefaults to true.
curl https://app.bookbag.ai/api/v2/agents/123/conversations/456/retry \
  -H "Authorization: Bearer $BOOKBAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "messageId": "msg_789", "stream": false }'

Tool result — POST .../conversations/:conversationId/tool-result

When the agent invokes a client-side tool/action, submit its result so the run can continue.

FieldTypeRequiredNotes
toolCallIdstringYesThe id from the tool-call part.
outputanyNoThe tool's result payload.
curl https://app.bookbag.ai/api/v2/agents/123/conversations/456/tool-result \
  -H "Authorization: Bearer $BOOKBAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "toolCallId": "call_abc", "output": { "status": "shipped" } }'

Feedback — PATCH .../messages/:messageId/feedback

Set thumbs up/down on an assistant message. feedback is "positive", "negative", or null to clear.

curl -X PATCH https://app.bookbag.ai/api/v2/agents/123/conversations/456/messages/msg_789/feedback \
  -H "Authorization: Bearer $BOOKBAG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "feedback": "positive" }'
StatusCodeMeaning
200Action succeeded.
400VALIDATION_INVALID_BODY / RESOURCE_MESSAGE_NOT_ASSISTANT / CHAT_RETRY_NO_USER_MESSAGEBad input for the specific action.
404RESOURCE_NOT_FOUND / RESOURCE_MESSAGE_NOT_FOUND / RESOURCE_TOOL_CALL_NOT_FOUND / CHAT_RETRY_MESSAGE_NOT_FOUNDThe agent, conversation, message, or tool call was not found.
429RATE_LIMIT_TOO_MANY_REQUESTSRate limit exceeded.

See Errors for the full envelope and codes.