Insights

Chatbot API: how it works and what you can build with it

What a chatbot API does, the request and response you can expect, how streaming and user identity work, and the builds that make sense when you use an API instead of a widget.

By the Askocto team · · 5 min read

A chatbot API is a way for your own software to send a customer message to an AI agent and receive the reply as data. Instead of using a ready-made chat window, you call an endpoint from your app, your backend or a script and decide how to show the answer. This article explains the pieces and when an API is the right choice.

In short: Use a widget when you want chat on a website with little code. Use an API when you need the agent inside your own app, in a custom interface or inside another workflow.

What a chatbot API does

At its core, one call does one thing: it sends a message and gets a reply. Around that sit a few supporting capabilities that you will want as soon as you build something real:

  • Conversations. A conversation ID ties messages together so the agent remembers earlier turns.
  • Streaming. The reply arrives in pieces as it is written, so your interface can show text immediately.
  • Identity. A user ID connects the conversation to a customer in your system.
  • Management. Endpoints to list conversations, read messages, update status and export data.
  • Content and configuration. Endpoints to add sources, edit procedures or change agent settings from code.
  • Events. Webhooks that call you when something happens, such as a conversation being handed over.

The shape of a request

Here is an example against an Askocto agent, using the v2 chat endpoint. The key is created under Workspace Settings > API keys and sent as a bearer token.

curl https://api.askocto.co/v2/agents/agt_123/chat \
  -H "Authorization: Bearer $OCTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      { "role": "user", "content": "Where is my order?" }
    ],
    "userId": "usr_456",
    "stream": false
  }'

A typical response includes the conversation ID to reuse, the reply text and the sources used, plus a usage record:

{
  "conversationId": "conv_789",
  "message": {
    "id": "msg_001",
    "role": "assistant",
    "content": "Your order shipped on Tuesday. Here is the tracking link.",
    "sources": [{ "id": "src_12", "title": "Shipping times" }]
  },
  "usage": { "credits": 1 }
}

Send conversationId in your next call and the agent continues the same thread. The full parameter list is in the chat endpoint reference.

Streaming replies

Waiting for a whole answer feels slow. With streaming switched on, the server sends the answer as a series of events. Your interface appends each piece as it arrives and stops when it receives a final marker. Plan for two cases in your code:

  1. Partial text. Append it to the message in progress.
  2. An error mid-stream. Show a short apology and offer a retry or a handover.

For batch jobs, such as drafting replies to a backlog, the non-streaming call is simpler.

Identifying the customer

An API call can carry the identity of the signed-in person. That lets the agent address them by name, find their orders and keep a history across sessions. Treat identity as a security matter:

  • Pass a stable user ID from your own system.
  • Sign it on your server, never in the browser.
  • Do not expose your API key in client-side code. Keep it on a server and call the agent through your own backend.

When to use an API instead of a widget

Situation Better fit
A support bubble on a marketing site Widget
Chat inside a mobile app with custom styling API or SDK
An internal tool where staff ask the agent questions API
A voice or kiosk interface API
Pushing conversation data into a warehouse API plus webhooks
A custom portal with account data on screen API

If you mostly want the first row, read how to add an AI chatbot to your website. It is faster.

What people build with a chatbot API

  • In-app help that knows the page, the plan and the last error the user saw.
  • Internal assistants for sales or IT staff, answering from the same sources the customer-facing agent uses.
  • Order or account screens with a chat panel next to the data.
  • Automations that send a customer message through the agent and file the result as a ticket.
  • Reporting pipelines that pull conversations and ratings into your own tools.

For the broader view of how chat connects to other systems, how to use a chatbot API looks at common integration patterns, and chatbot analytics shows what to do with the data you pull out.

Handle errors and limits

Plan for failure from the first version.

  • Authentication errors. A missing or revoked key returns a clear error. Rotate keys on a schedule and keep them in a secret store.
  • Rate limiting. When you send too many requests, the API tells you to wait. Respect the retry header and queue requests.
  • Not found. An agent or conversation ID that does not exist returns an error you should log, not hide.
  • Timeouts. Set a timeout on your side and show a fallback message.

Log the request ID that comes back with errors. It makes a support request to the vendor much faster.

Getting started

  1. Create an agent and add sources so there is something to answer from.
  2. Generate an API key in your workspace settings and store it as an environment variable.
  3. Send a first message from the command line, as above.
  4. Build the smallest interface that sends and displays one answer.
  5. Add streaming, identity and error handling, in that order.

Askocto also offers webhooks for events such as conversation.handoff and ticket.created, signed so you can verify them. You can read the API integration guide for the full walkthrough, or create a free account and try the first call.

Frequently asked questions

What is a chatbot API?

It is an interface that lets your software send messages to a chatbot and receive its replies as structured data, so you can use the bot in your own app or workflow.

Do I need a chatbot API if I have a widget?

Not usually. A widget covers a website bubble. You need the API for custom interfaces, internal tools or data pipelines.

Is it safe to call a chatbot API from the browser?

Do not put a secret API key in browser code. Call the API from your server, or use a client method designed for the browser that does not expose your key.

Can I stream chatbot replies?

Most chatbot APIs support streaming. It sends the text in pieces so your interface can show the reply as it is written.

Train an agent on your own help center

Askocto answers the repeat questions across chat, email and voice and hands the hard ones to your team.

Keep reading

All articles
Insightsai agents zendesk integration
Sep 19, 20255 min read

AI agents and Zendesk: how to evaluate an integration

A buyer's guide to pairing an AI agent with Zendesk: criteria to compare, questions for a demo, a two-week trial plan using your own tickets and a rollout checklist.

Read article
Insightszendesk sunshine integration
Aug 13, 20255 min read

Zendesk Sunshine integration: how to evaluate an AI agent

A buyer's guide for connecting an AI support agent to Zendesk through Sunshine: what to compare, what to ask in a demo, and how to test with your own tickets.

Read article