SDK
The @sypnia/ai package for servers and browsers: every function, its options and what it returns.
npm install @sypnia/aiTypeScript, for Node 20 or newer, Bun, Deno and edge runtimes. MIT.
On your server: @sypnia/ai/server
import { createAI } from '@sypnia/ai/server';
const ai = createAI({ apiKey: process.env.SYPNIA_SECRET_KEY! });| Option | Default | What it does |
|---|---|---|
apiKey | — | the project’s secret key, or a key made for AI |
baseUrl | https://ai.api.sypnia.com/v1 | your gateway’s /v1 when self-hosted |
defaultCase | — | the case used when a call names none and no trace says it |
timeoutMs | 600000 | the longest a call may take |
retries | 2 | retries on network errors and 429 (after retry-after) |
| Function | Returns |
|---|---|
chat({ task, case, endUser, messages, tools, maxToolRounds, stream, budget, store, params }) | { text, message, toolCalls, usage, model, callId, finishReason }; with stream: true an async iterator with final() |
extract({ task, case, schema, input }) | { data, usage, callId }: data typed from a zod schema or JSON Schema |
embed({ task, case, input, dimensions }) | { vectors, usage } |
browserTokens.create({ endUser, tasks, ttlSeconds }) | { token, expiresAt }, at most 600 seconds |
usage({ groupBy, since }) | rows of usage |
untrusted(text) | the text wrapped as data (Prompt injection) |
usage is always { input_tokens, output_tokens, cached_input_tokens, credits }.
In the browser: @sypnia/ai/browser
import { createAI } from '@sypnia/ai/browser';
const ai = createAI({ project: 'la-espiga', getToken: () => data.auth.session() });chat, extract and embed, for tasks with browser: true only (From the browser). The SDK exchanges and refreshes the browser token by itself.
Errors
Every failure is an AIError with code (as in the API), status, message, callId and, for 429, retryAfter.
try { await ai.chat({ … }); }
catch (e) { if (e instanceof AIError && e.code === 'end_user_limit') return tell('TooManyQuestions'); throw e; }With Telemetry
When @sypnia/telemetry traces the request, the SDK sends the trace along and reads the current case, so each call appears inside it.