Skip to main content

Authentication

Brainstormer uses JWT (JSON Web Token) bearer authentication for all API requests. Tokens are obtained via the login or register endpoints and must be included in every subsequent request.

How It Works

  1. Authenticate via POST /api/auth/login or POST /api/auth/register to obtain an access token and refresh token.
  2. Include the access token in the Authorization header of every API request.
  3. When the access token expires (24 hours), use the refresh token to obtain a new pair via POST /api/auth/refresh.
All API requests go through the API Gateway on port 4000, which decodes the JWT and forwards user context to backend services.

Optional verified identity on public endpoints

Public distribution endpoints (e.g. GET /api/public/agents/:slug) can optionally accept a bearer token. When present, the gateway verifies the JWT signature and forwards verified user-id and organization-id headers to the bot service so that group-restricted agents can evaluate membership. When the token is absent, public endpoints behave exactly as before and serve only agents that do not require membership or group access.
All API requests require a valid JWT token in the Authorization: Bearer <token> header. The API Gateway decodes the JWT and forwards auth context (user-id, organization-id, user-email, x-platform-role, x-org-role) as headers to downstream services.

Token Format

The JWT payload contains:
string
Unique user identifier (UUID).
string
User’s email address.
string
Platform-level role: user or superadmin.
array
List of organizations the user belongs to.
number
Token issued-at timestamp (Unix seconds).
number
Token expiration timestamp (Unix seconds).

Token Lifetimes

Header Format

Include the access token as a Bearer token in the Authorization header:
The API Gateway also accepts the token from an access_token cookie as a fallback, but the Authorization header is the primary method.
Developer portal showing API key management

The Developer portal for managing API keys and authentication

Obtaining Tokens

Register

Create a new user account and receive tokens.
Response (201):

Login

Authenticate with email and password.
Response (200): Same shape as the register response.

Refreshing Tokens

When the access token expires, exchange the refresh token for a new pair.
Response (200):

Error Responses

The API Gateway cryptographically verifies the JWT signature (HMAC-SHA256) on every request. Downstream services trust the gateway-forwarded identity headers and must never be exposed directly to the internet.

Organization Context

The JWT contains all organizations the user belongs to. The first organization in the array is used as the primary organization for all API requests. Multi-org switching via request headers is planned for a future release. All data in Brainstormer is scoped to an organization. When you create agents, knowledge bases, or other resources, they are automatically associated with your primary organization.