Skip to main content
If you’ll issue several operations against the same namespace — which is the common case — scope the client once with deyta.namespaces.scope(id) (or deyta.namespaces.scopeByExternalRef(ref)). The scope is a lightweight handle. No network call is made when constructing it.
const ns = deyta.namespaces.scope("ns_123");
// or by your application's external reference:
const ns = deyta.namespaces.scopeByExternalRef("user-abc");

Surface

// Memory ops — no namespace_id needed.
await ns.remember({ content: "..." });
await ns.recall({ query: "..." });
await ns.ask({ query: "..." });
await ns.forget({ document_id: "doc_456" });

// Lifecycle.
const meta = await ns.metadata(); // GETs the namespace
await ns.delete();

// Integrations scoped to this namespace.
const connections = await ns.integrations.list();
const session = await ns.integrations.start({ provider: "google_drive" });
const completed = await ns.integrations.complete({
  id: session.id,
  token: "oauth_token_from_nango",
  account_id: "account_id_from_nango",
  connection_id: "connection_id_from_nango",
  provider: "google_drive",
});
await ns.integrations.delete(completed.id);

Why this pattern

Less repetition

Stop typing namespace_id: "ns_..." on every call.

Fewer bugs

No more accidental cross-namespace operations from a copy-paste.

External refs work everywhere

Scope by your app’s user/tenant ID; the SDK resolves the namespace as needed.

Free to construct

The scope is local — no network call until you issue an operation.

Top-level resources are still there

deyta.memory, deyta.namespaces, and deyta.integrations remain available for unscoped or cross-namespace ad-hoc work. The sub-client is a convenience, not a replacement.

Errors and the scope

Scoping does not change the shape of errors. Operations on a scoped sub-client throw the same DeytaError / DeytaConnectionError types as the top-level client, with the same status codes and error codes.
import { DeytaError } from "@deyta-ai/sdk";

const ns = deyta.namespaces.scopeByExternalRef("user-abc");

try {
  await ns.recall({ query: "..." });
} catch (err) {
  if (err instanceof DeytaError && err.code === "NOT_FOUND") {
    // The namespace's external reference doesn't resolve.
    // Same surface as deyta.namespaces.getByExternalRef("user-abc").
  }
  throw err;
}
One subtlety: because scopeByExternalRef makes no network call, a typo in the reference doesn’t surface until the first real operation. If you want to fail fast on construction, call await ns.metadata() once after scoping.