@authai-io/server
v0.1.0
Published
AuthAI server SDK — authai.session() and decodeAuthAIToken() for verifying AuthAI JWTs in your backend.
Readme
@authai-io/server
Backend SDK for AuthAI — verify AuthAI session JWTs and turn them into an OpenAI-compatible client.
Quick start
import { authai, AuthAIUnauthorized } from "@authai-io/server";
const { user, openai } = await authai.session({
jwt: req.headers.get("authorization")?.slice("Bearer ".length),
relayUrl: "https://relay.authai.io",
// For AuthAI Cloud apps:
secret: process.env.AUTH_AI_SECRET,
});
const stream = await openai.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "hi" }],
stream: true,
});openai is present when the optional openai peer dep is installed. Otherwise use the returned { apiKey, baseURL } with any OpenAI-compatible client (LangChain, Vercel AI SDK, custom fetch).
API surface
authai.session({ jwt, relayUrl, secret? })→{ user, apiKey, baseURL, openai? }decodeAuthAIToken(jwt)— local JWT decode (no signature verification)AuthAIUnauthorized— thrown on missing / invalid / revoked sessions
See docs/integration.md for the full walk-through.
