Chat with a chatbot

POST/v1/chat

Send a message to a chatbot with the legacy v1 API and get its answer, with the sources it used, in one JSON response.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

Sends one or more messages to a chatbot and returns its reply. Call it from your backend when you want the chatbot to answer inside your own app, without the chat widget.

Request

POST /v1/chat

Body fields:

Name Type Required Description
chatbotId string Yes The chatbot that should answer, starting with agt_.
messages array Yes The messages to send. Each item has a role (user or assistant) and a content string.
conversationId string No Continue an existing conversation, starting with conv_. Leave it out to start a new one.
userId string No Your identifier for the person chatting, starting with usr_. Conversations with the same userId are grouped together.
metadata object No Free-form key and value pairs stored with the conversation.

The last item in messages should be a user message. The chatbot answers it using its sources and procedures.

Note: For streamed replies, use Chat with an agent in API v2.

Example request

curl -X POST https://api.askocto.co/v1/chat \
  -H "Authorization: Bearer $OCTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chatbotId": "agt_8f3k2m",
    "messages": [{ "role": "user", "content": "Where is my order?" }],
    "userId": "usr_3b6t0z"
  }'
const response = await fetch("https://api.askocto.co/v1/chat", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.OCTO_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    chatbotId: "agt_8f3k2m",
    messages: [{ role: "user", content: "Where is my order?" }],
    userId: "usr_3b6t0z",
  }),
})

const { conversationId, message } = await response.json()
console.log(conversationId, message.content)

Store the returned conversationId and send it with the next call to keep the context.

Example response

A successful call returns 200 OK.

{
  "conversationId": "conv_5n2p8w",
  "message": {
    "id": "msg_7c1k9s",
    "role": "assistant",
    "content": "I can check that for you. What is your order number?",
    "sources": [
      { "id": "src_91xa7d", "title": "Shipping and delivery" }
    ]
  },
  "usage": { "credits": 1 }
}

Response fields

Name Type Description
conversationId string The conversation this exchange belongs to.
message.id string ID of the assistant message, starting with msg_.
message.role string Always assistant.
message.content string The reply text.
message.sources array The sources the answer drew on, each with an id and a title.
usage.credits number Credits used by this call.

Errors

Status Code When
400 invalid_request chatbotId or messages is missing, or a message has an unknown role.
401 unauthorized The API key is missing, malformed or revoked.
404 not_found The chatbot or the conversationId does not exist.
429 rate_limited Too many requests. Wait for the number of seconds in the Retry-After header.

Read the v1 overview for the conventions shared by all v1 endpoints.

Something unclear or missing? Tell us and we will fix the page.