Authentication
AIUS authentication has two layers: a short-lived session token (an HS256 JWT) you get by logging in, and a durable API token (aius_…) you mint from
a session and use as a bearer credential on every request.
All examples target production (
https://aius.co/api). For the dev gateway,
swap for https://dev.aius.co/api and add -H "Accept-Encoding: identity".1. Register
POST /v1/register creates a new email/password account. On success the gateway
adds a session_token to the response so a non-browser client can immediately
mint an API token.
200:
2. Log in
POST /v1/login verifies credentials. The response depends on whether the
account has 2FA enabled.
200 (no 2FA): same shape as register — { user, message, session_token }.
Response 200 (2FA enabled): no user or session is returned; instead a
short-lived challenge:
401 with {"detail": {"code": "INVALID_CREDENTIALS", "message": "Invalid email or password"}}.
3. Complete a 2FA login
Whenrequires_2fa is true, finish the login with POST /v1/2fa/login, passing
the challenge_token plus a current TOTP code (or a recovery code). This
endpoint is unauthenticated — the challenge token is the credential.
200: { user, message, session_token } — the gateway attaches a
session_token just like login. Invalid challenge → 401 INVALID_CHALLENGE;
invalid code → 401 INVALID_CODE.
4. Mint an API token
POST /v1/tokens exchanges a session for a durable aius_… token. The session
is supplied via the __Host-aius_session cookie. token_name is required;
client_id is optional (defaults to your account).
200:
token_name → 400 token_name is required. No / invalid session cookie → 401.
5. Use the bearer token
Send youraius_… token on every API request:
{"type": "auth", "token": "aius_…"} (see Run-loop WebSocket).
A missing or malformed Authorization header returns 401 missing bearer token
/ invalid authorization header; an unknown or revoked token returns
401 invalid token.
Enrolling and managing 2FA
These endpoints operate on the authenticated user (send your session cookie or a bearer token). They use TOTP (RFC 6238) — compatible with any authenticator app.| Endpoint | Method | Purpose |
|---|---|---|
/v1/2fa/status | GET | Whether 2FA is enabled → {"enabled": false} |
/v1/2fa/setup | POST | Begin enrolment → {"secret": "...", "otpauth_uri": "otpauth://..."} |
/v1/2fa/enable | POST | Confirm a code → {"enabled": true, "recovery_codes": [...]} |
/v1/2fa/disable | POST | Disable after verifying a code → {"enabled": false} |
Begin
POST /v1/2fa/setup returns a secret and an otpauth_uri. Add the secret
(or scan the URI as a QR code) into your authenticator app. 2FA is not yet active.POST /v1/2fa/disable with a current TOTP or a recovery code:
Password reset
| Endpoint | Method | Body | Purpose |
|---|---|---|---|
/v1/password/reset/request | POST | {"email": "..."} | Send a reset email (always 200, even if the email is unknown) |
/v1/password/reset/confirm | POST | {"token": "...", "new_password": "..."} | Set a new password from a reset token |