BetterClaw
Agent API

Agent API

Talk to your agents from your own apps, scripts, and backends with a workspace API key.

Agent API

The Agent API lets your own software do what you do in Chats: find your agents, start a chat, send a message, and read or stream the reply. Use it to put an agent behind your product, wire one into an internal tool, or script work you'd otherwise type by hand.

Every request goes to:

https://api.betterclaw.io

Requests and responses are JSON, except message uploads with files, which use multipart/form-data. There is no version prefix in the path.

How API keys work

You generate keys on the Agents page: choose Agents under Workspace settings in the sidebar, then open the API keys tab (or go straight to /agents?tab=api-keys in the app). Every key is:

  • Bound to one workspace. It can only see and act in the workspace it was generated in.
  • Optionally pinned to one agent. A pinned key can only start chats with, and open chats of, that agent. Leave it set to Any agent to use every agent in the workspace.
  • Acting as the person who generated it. A key is a personal access token for the workspace admin who created it, not a separate service account. Chats it starts are theirs, and are visible to the rest of the workspace like any other chat. If that person leaves the workspace, the key stops working.
  • Limited to the permissions you chose.

Only workspace owners and admins can generate or revoke keys. Members can see which keys exist and when they were last used, but never the secret itself.

The full key is shown once, when you generate it. BetterClaw stores only a hash of it, so it can't be shown again. If you lose a key, revoke it and generate a new one.

Permissions

Each key carries one or more permissions (called scopes in the API).

ScopeShown in the app asAllows
chats:readRead chatsList chats, read a chat and its messages, download deliverables, and stream live updates
chats:writeSend messagesCreate, rename, archive and delete chats, send messages, and stop a reply
agents:readList agentsList the workspace's agents and the agent templates
workspaces:readRead workspaceRead the workspace's name, status, and plan

New keys start with Read chats and Send messages. There is no permission to create, change, or remove agents: adding an agent provisions a machine and changes your bill, so that stays in the app.

Two kinds of credential

API keySession token
Looks likebc_sk_…bcs_…
LastsUntil you revoke it10 minutes by default, 15 at most
Where it can liveYour server onlyAnywhere, including a browser or mobile app
How you get oneGenerate it in the appExchange an API key at POST /auth/sdk-token

An API key is a long-lived secret. Keep it on your server: the API rejects a key sent from a browser or in a URL. For browser and mobile apps, your server exchanges the key for a short-lived session token and hands that out instead. See Authentication.

JavaScript SDK

Building in JavaScript or TypeScript? The BetterClaw JavaScript SDK wraps this API — chats, messages, live replies, and session-token refresh — with hooks for React and Vue.

npm install @better-claw/sdk

On a server, create a client with your API key using createServerClient from @better-claw/sdk/server. In a browser, use BetterClawClient with SessionTokenAuth, and mint tokens on your server with mintSessionToken. The SDK's README has complete examples.

What you can call

MethodPathScope
GET/workspacesworkspaces:read
GET/workspaces/{workspaceId}workspaces:read
GET/workspaces/{workspaceId}/agentsagents:read
GET/workspaces/{workspaceId}/agents/{agentId}agents:read
GET/workspaces/{workspaceId}/agents/templatesagents:read
POST/chatschats:write
GET/chats?workspaceId={workspaceId}chats:read
GET/chats/{chatId}chats:read
PATCH/chats/{chatId}chats:write
DELETE/chats/{chatId}chats:write
POST/chats/{chatId}/messageschats:write
POST/chats/{chatId}/messages/{messageId}/stopchats:write
GET/chats/{chatId}/messages/{messageId}/deliverables/{index}chats:read
WS/ws/chats?workspaceId={workspaceId}chats:read
POST/auth/sdk-tokenAny API key

Everything else in the API, including managing keys themselves, needs a signed-in user and answers an API key with 403.

In this section

Quickstart

Generate a key, send a message, and read the reply in five minutes.

Authentication

API keys, session tokens for browsers, pinning, and revocation.

Endpoint reference

Every request and response, with examples.

Streaming replies

Watch replies arrive live over a WebSocket.

Errors

Status codes, error bodies, and what to do about each.

JavaScript SDK

The official client for Node.js and browsers, with React and Vue hooks.