JavaScript SDK reference

Package layout and configuration for @surrealdb/spectron.

ItemValue
npm package@surrealdb/spectron
Sourcesurrealdb.js/packages/spectron
OpenAPI inputpackages/spectron/spec/openapi.json
npm install @surrealdb/spectron
import { Spectron } from "@surrealdb/spectron";

const client = new Spectron({
endpoint: process.env.SPECTRON_ENDPOINT!,
context: "acme-prod",
apiKey: process.env.SPECTRON_API_KEY!,
timeout: 30000,
maxRetries: 3,
});

Uses Authorization: Bearer header authentication.

MethodHTTP
remember(...)POST /api/v1/{ctx}/facts
rememberMany(...)POST /api/v1/{ctx}/facts/batch
recall(...)POST /api/v1/{ctx}/query
forget(...)POST /api/v1/{ctx}/forget
chat(...)POST /api/v1/{ctx}/chat (SSE when stream: true)
consolidate(...)POST /api/v1/{ctx}/consolidate
reflect(...)POST /api/v1/{ctx}/reflect
elaborate(...)POST /api/v1/{ctx}/elaborate
context(...)POST /api/v1/{ctx}/context
inspect(...)GET /api/v1/{ctx}/inspect
state()GET /api/v1/{ctx}/state
profile()GET /api/v1/{ctx}/profile
audit(...)GET /api/v1/{ctx}/audit
fsck(...)POST /api/v1/{ctx}/fsck
health()GET /api/v1/health

Python names query_context as context here. Python exposes whoami() and keys.*; the JavaScript client does not include those methods — use REST for those endpoints.

NamespaceHighlights
documentsupload, get, delete, list, query, raw, reprocess, recomputeLinks, chunks, keywords.*
sessionscreateSession with .turns(), .context(), .close()
entitieslist, get, history, delete
scopesregister, list, delete, forget
principalslist, get, effective, grant, revoke
traceslist, get, stats
lifecycledecay, expire
ClassTypical cause
SpectronErrorBase
AuthError401
ScopeError403
NotFoundError404
ValidationError400 / 422
RateLimitError429 (retryAfter when provided)
ServerError5xx
ConnectionErrorNetwork / timeout

Errors and retries

npm install @surrealdb/spectron-vercel-ai

Vercel AI SDK

JavaScript and TypeScript SDK

Was this page helpful?