Authentication
Authenticate Askocto API requests with a bearer API key, tell test and live keys apart, rotate keys safely and keep them out of browser code.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
Every request to the Askocto API carries an API key in the Authorization header. Keys belong to a workspace, are created in the dashboard and are meant for your server, never for a browser.
Create a key
- Open Workspace Settings > API keys.
- Create a key and give it a name that says where it is used, for example
orders-backend. - Copy the key right away. It is shown once, and you cannot read it again later.
Keys start with oc_live_ for production or oc_test_ for testing. A key acts on the whole workspace, so it can reach every agent in it. Treat it like a password.
Send the key
Pass the key as a bearer token:
curl "https://api.askocto.co/v2/agents?limit=1" \
-H "Authorization: Bearer $OCTO_API_KEY"
const response = await fetch("https://api.askocto.co/v2/agents?limit=1", {
headers: { Authorization: `Bearer ${process.env.OCTO_API_KEY}` },
})
if (response.status === 401) {
throw new Error("The API key was rejected")
}
Keep the key in an environment variable named OCTO_API_KEY. The octo command line tool reads the same variable. The same header works for API v1.
Test and live keys
Use an oc_test_ key while you build and in automated tests. Use an oc_live_ key in production. Keep them in separate environment files so a test script never runs with a production key, and the other way around.
Rotate a key
Rotate keys on a schedule, and right away if one may have leaked.
- Create a new key in Settings > API keys.
- Deploy the new key to your servers and confirm that requests succeed.
- Delete the old key. Requests that still use it fail with
401 unauthorized.
Because you can have several keys at once, rotation needs no downtime.
Keep keys out of browser code
Anything sent to a browser or a mobile app can be read by the person using it. Do not put an API key in front-end JavaScript, in a mobile app bundle or in a public repository.
- Call the API from your server and expose only the result to your front end.
- To put the agent on a website, use the embed script with the agent ID. The agent ID is not a secret. To tie chats to your logged-in users, add identity verification.
- If a key was exposed, delete it in Settings > API keys and create a new one.
Authentication errors
A missing, malformed or deleted key returns 401:
{
"error": {
"code": "unauthorized",
"message": "The API key is missing or invalid.",
"requestId": "req_4h9c2k"
}
}
A valid key that is not allowed to do something returns 403 forbidden. All codes are listed in Error handling. For a wider view of the API, see the API v2 overview and the API integration guide.