Authentication
Each part of the API has its own credential. Secret API keys stay on your server and carry only the access you give them, publishable keys go in web pages, and an automation's webhook URL is its own secret.
The Careflow API has three kinds of credential, and you authenticate with each one differently. This page covers all three. All requests go to https://api.trycareflow.com.
| Part | Credential | Where it lives |
|---|---|---|
| Conversations, agents, knowledge, analytics, tools, variables, integrations | Secret API key, sk_live_... | Your server |
| Web widget | Publishable key, pk_live_..., then a session token | Your web pages |
| Automation triggers | The webhook URL itself | Your server |
API keys
An API key lets your server work with your workspace. A Manager creates it under SettingsChannelsAPI and chooses what it can do. The full key is shown once, when it's created, because Careflow keeps only a hash of it. See API keys.
Send the key in the Authorization header:
curl -X POST https://api.trycareflow.com/v1/conversations/messages \
-H "Authorization: Bearer sk_live_xxx" \
-H "Content-Type: application/json" \
-d '{"assistantId":"66f1c2a9e4b0f1a2b3c4d5e6","message":"Do you have a room for two on Friday?"}'
const res = await fetch("https://api.trycareflow.com/v1/conversations/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CAREFLOW_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
assistantId: "66f1c2a9e4b0f1a2b3c4d5e6",
message: "Do you have a room for two on Friday?",
}),
});
When the key is wrong, the response is 401 with message set to unauthorized and one of these in error:
missing Authorization: Bearer <api key>: there's noAuthorizationheader, or it doesn't start withBearer.malformed API key: the value doesn't start withsk_.invalid or revoked API key: no key matches. A revoked key and a key that never existed look the same.
On the endpoints that the dashboard shares with keys, such as /assistants and /knowledge/*, a value that doesn't start with sk_ is treated as a dashboard sign-in instead, so a missing or malformed key comes back as 401 with missing bearer token or query param or invalid or expired token.
A key only reaches its own workspace. An ID from another workspace is refused, usually with 404.
What a key can do
Each key carries scopes: one per area of the API, at a level of read or write. Write includes read, so a key with knowledge:write can also list and search knowledge. A GET request needs read, and every other method needs write.
| Area | Read lets a key | Write also lets it |
|---|---|---|
conversations | (write only) | Send customer messages to your agents |
agents | List agents and read their settings | Create, change, check, publish and delete agents |
knowledge | List sources and documents, search, and ask an agent's knowledge | Upload documents, add, change, sync and remove sources, attach them to agents |
analytics | Read overview, trends, sessions, transcripts and exports | (read only) |
tools | List tools, their runs, health and usage | Create, change, test and delete tools |
variables | List variables | Create, change, preview and delete variables |
integrations | See connected integrations, their activity and runs | Disconnect an integration |
Previewing a variable is a POST, so it needs variables:write even though it changes nothing. Asking an agent's knowledge a question is a POST too, and needs knowledge:write.
Keys created before scopes existed keep the access they always had: conversations:write and nothing else. A Manager can give an older key more on its page in the dashboard.
When a key lacks a scope
A request outside the key's scopes is refused with 403, before anything happens:
{
"code": "ERROR",
"message": "insufficient_scope",
"error": "this API key needs the knowledge:write scope"
}
The error names the scope that's missing. Ask a Manager to add it on the key's page, under What this key can do. The change applies to the key's next request, so there's nothing to redeploy.
What a key acts as
Within its scopes, a key acts with a Manager's permissions. It can do anything a Manager can do in those areas, including actions the dashboard keeps for Managers, such as disconnecting an integration. It never reaches areas outside its scopes, whatever a Manager could do there.
Changes a key makes are recorded in Audit logs like anyone else's. The actor is shown as API key: followed by the key's name, such as API key: PMS sync, with no email address. Name keys after the system that uses them so the log reads clearly.
Keep keys safe
Keep keys out of browsers and mobile apps. Anyone who has a key can do everything its scopes allow. Store it in your secret manager or an environment variable.
Give each system its own key with only the scopes it needs. A reporting job needs analytics:read and nothing else. A service that keeps your knowledge current needs knowledge:write. If one key leaks, you revoke just that key, and the damage is limited to what it could reach. Replace keys on a schedule with Rotate an API key.
Publishable keys for the web widget
The widget API is called from your visitors' browsers, so its key is public by design. Each web widget has a publishable key, shown in its install snippet under Agentsyour agentDeployWebInstall.
A publishable key on its own isn't enough. Careflow also checks the Origin header that the browser sends, and only answers pages on the widget's Allowed website origins. The match is exact on scheme, host and port, so https://www.harbourviewhotel.com and https://harbourviewhotel.com are two different entries. A request from any other site gets 403 with origin_rejected.
The key works in two ways:
GET /v1/web/config,GET /v1/web/helpandGET /v1/web/help/{id}take it as thekeyquery parameter.POST /v1/web/sessiontakes it in the body aspublishableKey, and returns a session token for one visitor.
const res = await fetch("https://api.trycareflow.com/v1/web/session", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ publishableKey: "pk_live_xxx", visitorId: savedVisitorId }),
});
const { data } = await res.json();
// data.token, data.visitorId, data.expiresIn (1800)
The session token authenticates everything the visitor does next. Send it as Authorization: Bearer <token> on messages and conversations, and as the token query parameter on the voice WebSocket, because browsers can't set headers there. A token lasts 30 minutes from when it was created, however much it's used. When a call returns 401 with session_expired, create a new session with the same visitorId and send the call again.
The visitorId is what links a visitor to their past conversations. Use the one Careflow returns, or your own long random value. Don't use something guessable like an email address or a customer number.
Webhook URLs for automation triggers
An automation's webhook URL needs no header and no key. The webhook ID in the address is the credential, so anyone with the full URL can start the automation. Careflow doesn't sign these requests or check anything else.
Treat the URL like an API key. Keep it in your server's configuration, not in browser code or a public repository. If it leaks, turn off When called from outside in the automation's trigger and save. Turning it back on gives a new URL. See Start an automation from your systems.
Where to go next
- Make your first request with an API key.
- API keys covers choosing and changing a key's access.
- Rotate an API key without downtime.
- Errors lists every failure these credentials can return.