Authentication
There are two ways to authenticate. Both call the same APIs directly; no server of your own is needed in between. Pick one per request; never send both.
| Personal API key | Sign in with a Personaas account | |
|---|---|---|
| Best for | A script, a coding agent, your own tool, or an app where each person enters their own key | An app that many people use: each person signs in as themselves |
| Header | x-personaas-key: <key> | Authorization: Bearer <access token> |
| Lifetime | Until it expires or is revoked | Short; renewed with a refresh token |
| Setup | The user creates a key in Settings and enters it once | The user types their username and password |
Both act as one user: that user's personas, that user's conversations.
The examples on this site use the x-personaas-key header. With sign-in,
replace it with Authorization: Bearer <access token>; everything else is the
same.
For an app that many people use, sign-in is the recommended way. Whichever you choose, never build a key or token into the app itself.
Personal API key
The header
Every request carries one header:
x-personaas-key: <key>
The key looks like p-AbC123dEf456gHi789@org_acme. The part after @ names
the organisation. Send the key exactly as it was given to you, @org_… included.
If the @org_… part is missing, the request is rejected with 401.
curl "$PERSONAAS_BASE_URL/api/v1/personas/" \
-H "x-personaas-key: $PERSONAAS_API_KEY"
Which key to use
Use a personal API key. A user creates it for themselves. It:
- acts as that user, with the same personas and conversations;
- is shown once at creation, can have an expiry date, and can be revoked at any time.
How to get one
- Sign in to Personaas in the browser, on the address the app will call (see API reference, Base URL).
- Open Settings and, under API keys, choose Personal API keys.
- Choose Create API key, give it a name that says where it will be used, and pick when it expires.
- Copy the key straight away, whole, including the
@org_…part. It is shown only this once. If it is lost, revoke it and create a new one.
A coding agent cannot do these steps. Ask the user for the key, and never ask them to paste it into the code.
Using a key in an app
Each person enters their own key in the app:
- Show a screen that asks for the key, with a short note on where to get it (the steps above).
- Check it with one call, for example
GET /api/v1/personas/. A401means the key is wrong, expired or revoked: say so and ask again. - Keep it in the platform's secure storage for secrets.
- Give the user a way to remove the key from the app and to enter a new one.
Never ship a key inside the app itself. A key built into an app can be read by everyone who has the app, and all of them would act as that one user.
Sign in with a Personaas account
Sign in
curl -X POST "$PERSONAAS_BASE_URL/api/v1/auth/jwt/login" \
-H "Content-Type: application/json" \
-d '{ "username_or_email": "jdoe@example.com", "password": "…" }'
{
"token_type": "bearer",
"access_token": "…",
"access_token_expires_in": 86400,
"refresh_token": "…",
"refresh_token_expires_in": 2592000,
"user": { "id": "…", "username": "jdoe", "email": "jdoe@example.com" }
}
The …_expires_in values are in seconds. Read them from the response; do not
hard-code them.
| Status | Meaning |
|---|---|
401 | Wrong username or password |
403 | The account is not activated yet |
Call the API
curl "$PERSONAAS_BASE_URL/api/v1/personas/" \
-H "Authorization: Bearer $ACCESS_TOKEN"
Renew the access token
When a call returns 401, or shortly before the access token expires:
curl -X POST "$PERSONAAS_BASE_URL/api/v1/auth/jwt/refresh" \
-H "Content-Type: application/json" \
-d '{ "refresh_token": "…" }'
# → { "token_type": "bearer", "access_token": "…", "expires_in": 86400 }
Then repeat the failed call once with the new access token. If the refresh call
itself returns 401, the session is over: send the user back to sign-in.
Sign out
curl -X POST "$PERSONAAS_BASE_URL/api/v1/auth/jwt/logout" \
-H "Authorization: Bearer $ACCESS_TOKEN"
This ends the session; both tokens stop working.
Rules for sign-in
- Send the password straight to Personaas over HTTPS. Never store or log it.
- Keep both tokens in the platform's secure storage for secrets, not in plain files or logs. Remove them on sign-out.
- Send them only to Personaas, only over HTTPS. Never log them.
- One set of tokens per signed-in person. Never share them between users.
Both ways
Where a token or key may live
| Place | Allowed |
|---|---|
| A signed-in user's tokens, in secure storage on that user's own device or session | Yes |
| A user's own personal API key, entered by them, in secure storage on their own device or session | Yes |
| A personal API key, in the environment or secret store of a script | Yes |
| Any key or token built into the app itself | No |
Git repository, including .env committed by mistake | No |
Anyone who has a token can act as its user. A signed-in user's tokens belong to that person and stay with that person, and so does a key the user entered themselves. A key built into the app itself can be read by everyone who has the app, and all of them would act as one user.
Errors
| Status | Meaning | What to do |
|---|---|---|
401 | Token missing, malformed, expired or revoked | Personal API key: ask for a new one. Signed-in user: renew once, then sign in again. |
403 | Not allowed | The item does not belong to this user. Do not retry. |
Error bodies are JSON: {"detail": "…"}.