API Authentication
How requests to your gateway are authenticated — session cookies, service-to-service tokens, and AI provider keys.
There is no single nbk_live_-style API key that authenticates arbitrary gateway requests, and no
@nebutra/sdk to verify one with. Three real, separate mechanisms exist, each for a different
caller:
| Caller | Mechanism |
|---|---|
| Your own frontend (a signed-in user) | Better Auth session cookie |
| Another internal service | x-service-token — a short-lived HS256 JWT signed with SERVICE_SECRET |
| A per-organization AI credential | The /api/v1/ai/api-keys resource |
Session cookies (end users)
Most gateway routes run requireAuth middleware, which reads the Better Auth session cookie set
when a user signs in. There's no separate bearer token to attach from your own frontend — the
browser sends the cookie automatically on same-origin requests (the default when the gateway is
mounted at /api/[[...route]] inside apps/web).
Service-to-service tokens (internal callers)
For a caller that isn't a signed-in user — a background worker, another internal service — sign an
HS256 JWT with the shared SERVICE_SECRET and send it as x-service-token:
import { signServiceToken, verifyServiceToken } from "@nebutra/auth";
const token = signServiceToken({ service: "my-worker" });See Node.js Quickstart and Python Quickstart for calling this from outside the monorepo.
AI provider keys (per-organization)
/api/v1/ai/api-keys lets an authenticated org member issue, list, patch, and revoke credentials
scoped to that org's AI usage — a resource under the ai capability, not a general-purpose REST
API key. It still requires a valid session (requireAuth + requireOrganization) to manage.
nebutra ai provider list # which providers are enabled, from the CLI sideSecurity best practices
- Never commit
SERVICE_SECRET,BETTER_AUTH_SECRET, or any provider key to source control - Use environment variables for all secrets
- Rotate
SERVICE_SECRETif a deployment target is compromised — every caller using it needs the new value
Related
How is this guide?
Last updated on