Skip to content

Authority Headers & OBO

The MemoryLayer TypeScript SDK talks HTTP through fetch. Unlike the Python SDK and the Go SDK, it has no built-in Aether transport option, but you can plug one in through the fetch config option (see Routing Over Aether below). It does support the client-side half of Aether’s on-behalf-of (OBO) delegation: pass an AuthorityContext with a call and the SDK emits the four X-Aether-* headers, which an Aether terminator (or a MemoryLayer server using Aether authentication) verifies.

This page describes that surface. For the broader picture of what Aether brings to MemoryLayer, see Server -> Aether Transport and aetherlayer.ai.


When to Use This

Use authority context any time the calling principal is not the same as the principal whose memories you want to read or write — typically:

  • A SaaS backend handling a request from end user Alice and storing memories as Alice
  • An agent service running across many tenants that needs per-tenant scoping
  • A trusted internal service acting on behalf of a customer for support / debugging

If your application is single-tenant and the API key already represents the right principal, you don’t need any of this.


The AuthorityContext Type

interface AuthorityContext {
grantId: string;
subject: PrincipalRef;
}
interface PrincipalRef {
type: string; // e.g. "User", "Application"
id: string; // tenant-stable principal ID
}

The grantId is an opaque token issued by your identity layer (typically Aether’s token gRPC service); the MemoryLayer server / Aether terminator verifies it and refuses requests with bogus grants.


Three Ways to Attach an Authority

Per-call

remember(), recall(), and reflect() accept an optional authority field, as do the skills, mcpServers, kb, and rpg namespace calls:

import { MemoryLayerClient } from "@scitrera/memorylayer-sdk";
const client = new MemoryLayerClient({
baseUrl: "https://memorylayer.example.com",
apiKey: process.env.MEMORYLAYER_API_KEY,
});
await client.remember("Alice prefers dark mode", {
type: "semantic",
importance: 0.7,
authority: {
grantId: "grant_abc123",
subject: { type: "User", id: "alice@example.com" },
},
});

The SDK emits these headers for that single request:

HeaderValue
X-Aether-Grant-IDgrant_abc123
X-Aether-Authority-Modeon_behalf_of
X-Aether-Subject-TypeUser
X-Aether-Subject-IDalice@example.com

Scoped proxy with actingFor()

actingFor() returns a lightweight OboProxy bound to one grant and subject. It does not mutate the client, so a single client can serve many users concurrently:

const alice = client.actingFor({
grantId: "grant_abc123",
subject: { type: "User", id: "alice@example.com" },
});
await alice.remember("Alice prefers dark mode", { type: "semantic" });
const prefs = await alice.forWorkspace("ws_alice").recall("preferences");
const skills = await alice.skills.list();

The proxy exposes remember, recall, reflect, forWorkspace, skills, and mcpServers.

Default authority on the client

If every call from a given client should run as the same principal, pass defaultAuthority to the constructor. It applies to every request the client makes, including uploads and exports. Any per-call authority argument overrides it.

const aliceClient = new MemoryLayerClient({
baseUrl: "https://memorylayer.example.com",
apiKey: process.env.MEMORYLAYER_API_KEY,
defaultAuthority: {
grantId: "grant_abc123",
subject: { type: "User", id: "alice@example.com" },
},
});

Short-lived per-request clients

For multi-tenant services it is often clearest to build a short-lived client per request:

function clientFor(req: Request) {
return new MemoryLayerClient({
baseUrl: process.env.MEMORYLAYER_URL!,
apiKey: process.env.MEMORYLAYER_API_KEY!,
workspaceId: tenantWorkspace(req),
defaultAuthority: req.user.toAuthority(), // your auth layer
});
}

The SDK is intentionally cheap to construct; per-request instantiation is fine.


What the Server Does With These Headers

When MemoryLayer is fronted by an Aether terminator (the default in mesh deployments), the terminator validates the grant signature, then rewrites the inbound headers into trusted X-Auth-* headers that FastAPI consumes. In strict mode, any inbound X-Auth-* or unsigned X-Aether-* headers are stripped before minting. Header-based propagation only works because the mesh-signed X-Aether-Grant-ID is what makes the request trustworthy.

When MemoryLayer is configured with MEMORYLAYER_AUTHENTICATION_SERVICE=aether, the same path is used internally even when calls arrive on plain HTTP (still requiring a verifiable grant).

In OSS open-auth mode (MEMORYLAYER_AUTHENTICATION_SERVICE=default) these headers are accepted but not cryptographically verified — they are useful for local development and demos but should not be relied on for security boundaries.

See Server -> Aether Transport for the server-side details.


Routing Over Aether

The fetch config option accepts any WHATWG-compatible fetch implementation. The Aether TypeScript client (@scitrera/aether-client) provides AetherFetchTransport, which tunnels each request through an Aether connection to a service topic:

import { AetherClient, AetherFetchTransport } from "@scitrera/aether-client";
import { MemoryLayerClient } from "@scitrera/memorylayer-sdk";
const aether = new AetherClient({ address: "localhost:50051" });
await aether.connect();
const transport = new AetherFetchTransport(aether, "sv::memorylayer", 30_000);
const client = new MemoryLayerClient({
workspaceId: "my-workspace",
fetch: transport.fetch.bind(transport),
defaultAuthority: {
grantId: "grant_abc123",
subject: { type: "User", id: "alice@example.com" },
},
});

AetherFetchTransport uses only the path and query of each URL, so baseUrl has no effect. You own the AetherClient connection and must close it yourself. It forwards X-Aether-* authority headers as ordinary HTTP headers, rather than converting them into the proxy’s structured authorization envelope as the Python and Go transports do. It also only forwards string, ArrayBuffer/Uint8Array, and ReadableStream bodies. The FormData bodies used by uploadDocument() and uploadDataset() are not supported over it.