Welcome to Nebutra Sailor Docs 🎉
ChangelogIntroductionLicensing
Help Center (External) ↗

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:

CallerMechanism
Your own frontend (a signed-in user)Better Auth session cookie
Another internal servicex-service-token — a short-lived HS256 JWT signed with SERVICE_SECRET
A per-organization AI credentialThe /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 side

Security best practices

  • Never commit SERVICE_SECRET, BETTER_AUTH_SECRET, or any provider key to source control
  • Use environment variables for all secrets
  • Rotate SERVICE_SECRET if a deployment target is compromised — every caller using it needs the new value

Related

Permissions

Scope reference and RBAC model.

Gateway API

Where the gateway runs and how it documents its own routes.

How is this guide?

Edit on GitHub

Last updated on

On this page

Session cookies (end users)
Service-to-service tokens (internal callers)
AI provider keys (per-organization)
Security best practices
Related