Aether Transport (Python SDK)
The MemoryLayer Python SDK can be configured to talk to the server over Aether instead of plain HTTP. Aether is an optional service-mesh transport that brings mTLS, signed identity headers, on-behalf-of (OBO) delegation, and cross-datacenter service discovery. For background on Aether itself, see aetherlayer.ai; for how the MemoryLayer server side is wired up, see Server -> Aether Transport.
This page describes the client-side surface in memorylayer-client.
When to Use This
Switch the SDK to Aether transport when:
- The MemoryLayer server is reachable through your Aether mesh (registered under the
sv::memorylayerservice topic) - You want mTLS rather than terminating HTTPS yourself
- You need to call MemoryLayer on behalf of an end user with an audit trail (OBO)
- You are deploying across datacenters and don’t want to expose the MemoryLayer HTTP port directly
For local development or single-process deployments, the default HTTP transport remains the right choice.
Installation
The Aether client library is an optional extra:
pip install "memorylayer-client[aether]"This pulls in scitrera-aether-client>=0.2.3. The default HTTP transport does not need it.
Quick Start
import asynciofrom memorylayer import MemoryLayerClientfrom scitrera_aether_client import AsyncAgentClient # provided by Aether
async def main(): aether_client = AsyncAgentClient(...) # built per your Aether install await aether_client.connect()
async with MemoryLayerClient( transport="aether", aether_client=aether_client, aether_target="sv::memorylayer", workspace_id="my-workspace", ) as client: await client.remember("MemoryLayer reached via Aether") results = await client.recall("Aether") for m in results.memories: print(m.content)
await aether_client.close()
asyncio.run(main())Two things change relative to the HTTP example:
- The client is constructed with
transport="aether"and an already-connectedaether_clientplus aaether_targettopic. - The SDK does not own the
aether_clientconnection. Leaving theasync withblock does not close it; you construct and dispose of theaether_clientyourself.
Constructor Parameters
| Parameter | Default | Description |
|---|---|---|
transport | "http" | "http" for direct httpx calls (uses base_url), "aether" to route through Aether, or a custom Transport instance. |
aether_client | None | Required when transport="aether". An already-connected AsyncAgentClient (or compatible) from scitrera_aether_client. |
aether_target | "sv::memorylayer" | Service topic to address. The bare topic lets Aether route to any available MemoryLayer instance; use sv::memorylayer::<specifier> to pin one. |
default_authority | None | Optional AuthorityContext applied to every request (see OBO below). |
api_key | None | Same as HTTP — passed through as Authorization: Bearer for the terminator to forward. |
session_id | None | Sent as X-Session-ID. |
workspace_id | None | Default workspace, sent in request bodies and query parameters exactly as over HTTP. |
timeout | 30.0 | Per-request timeout in seconds. |
base_url and max_retries are ignored by the Aether transport. Requests are mounted under /v1 to match the terminator’s allowed paths.
When transport="aether" is set and aether_client is None, the constructor raises ValueError immediately. This is intentional: the SDK does not attempt to import or initialize the Aether client library on your behalf.
On-Behalf-Of (OBO) Delegation
Aether’s strongest feature for multi-user applications is OBO: your application service can call MemoryLayer as a specific end user, with the mesh signing the delegation. The SDK exposes this through an acting_for(...) context manager.
Scoped proxy with acting_for
acting_for(grant_id, subject=(type, id)) is an async context manager that yields a proxy. The shared client is not mutated, so concurrent requests for different users on the same client don’t interfere:
async with client.acting_for("grant_abc123", subject=("User", "alice@example.com")) as alice: # Every request made through `alice` is on Alice's behalf await alice.remember("Alice's preference: dark mode") results = await alice.recall("preferences") skills = await alice.skills.list()The proxy exposes remember, recall, reflect, append_messages, delete_message, for_workspace, and the skills, mcp_servers, and kb namespaces. For any other method, call the client directly and pass authority=.
Per-call authority
from memorylayer import AuthorityContext, PrincipalRef
authority = AuthorityContext( grant_id="grant_abc123", # issued by your auth layer subject=PrincipalRef(type="User", id="alice@example.com"),)
await client.remember("Alice's preference: dark mode", authority=authority)Under the hood the SDK builds four headers:
| Header | Value |
|---|---|
X-Aether-Grant-ID | The grant token id |
X-Aether-Authority-Mode | on_behalf_of when a subject is given, otherwise direct |
X-Aether-Subject-Type | Subject principal type (only with a subject) |
X-Aether-Subject-ID | Subject principal id (only with a subject) |
When routed over Aether transport, these headers are translated into the canonical AuthorizationContext proto field on the ProxyHttpRequest, which the server’s Aether terminator then verifies and mints into X-Auth-* headers for FastAPI. Header-based propagation is intentionally avoided — strict-mode terminators strip inbound X-Aether-* / X-Auth-* headers before minting anyway, so the proto field is the reliable channel.
Default authority
If every request from a client instance should run as the same principal, pass default_authority= to the constructor instead of using acting_for:
client = MemoryLayerClient( transport="aether", aether_client=aether_client, default_authority=authority,)Precedence, from highest to lowest: a per-call authority= argument, then the authority bound to an acting_for(...) proxy, then default_authority.
Connection Ownership
The AetherTransport does not own the underlying aether_client. Concretely:
MemoryLayerClient.__aexit__closes the SDK’s transport wrapper (AetherTransport.aclose()is a no-op), but it does not disconnect theaether_client.- You are responsible for
await aether_client.close()at process shutdown.
This matches the pattern used by other Aether-aware Python services (cowork, embed-server’s internal embed client, etc.) — one shared, long-lived Aether connection per process, fan-out across many client wrappers.
Streaming & Uploads
All current SDK methods work identically over HTTP and Aether transport, including:
- NDJSON streaming —
export_workspace_stream(...)andimport_workspace_stream(...)yield/accept parsed line objects and run through the sharedTransport.request(...)surface. The public API and the yielded shape are unchanged. - Multipart uploads — document ingestion serializes the multipart body to bytes transport-agnostically (
_encode_multipart) and ships the raw bytes + caller-providedcontent-typethrough whichever transport is active.
Underlying chunked-bytes support
Aether itself supports incremental byte-streaming end-to-end. The underlying scitrera_aether_client.proxy module accepts stream_response=True (and stream_idle_timeout_ms) on its proxy call and returns an _ProxyStreamAsync iterator that yields bytes chunks as ProxyHttpBodyChunk frames arrive, terminated by a fin flag (or a mid-stream ProxyError). So the mesh does not buffer the whole response on either side.
What the MemoryLayer SDK’s current AetherTransport.request(...) does is call proxy_http_async(...) without stream_response=True, which means today the SDK consumes the body as a single ProxyHttpResponse. That is a SDK-side implementation choice, not an Aether limitation. The two currently-shipped streaming methods buffer-then-split anyway, so no behaviour is lost over Aether transport.
If a future SDK method needs true aiter_bytes-style chunk-by-chunk consumption (e.g. tailing a server-sent event endpoint, downloading a huge export without buffering), AetherTransport can be extended with a sibling astream(...) entry point that sets stream_response=True and returns the chunk iterator — no protocol or terminator changes required. Until that lands, the _ensure_client() escape hatch on the client is the way to get the raw httpx.Response with aiter_bytes when running on the HTTP transport.
Error Handling
The same exception hierarchy applies regardless of transport: MemoryLayerError, AuthenticationError, AuthorizationError, NotFoundError, ValidationError, RateLimitError, ServerError, and EnterpriseRequiredError. The client maps the ProxyHttpResponse status code exactly as it maps HTTP status codes.
If the proxy response carries an Aether-level error (for example a mesh routing failure or an unreachable target topic), the transport raises MemoryLayerError with the message Aether proxy error: .... Its status_code is the proxy’s status code, or 502 if there is none.
Related Pages
- aetherlayer.ai — Aether product site
- Server -> Aether Transport — server-side wiring, identity headers, OBO terminator
- Python SDK API Reference — full method surface (transport-agnostic)
- TypeScript SDK -> Authority Headers — equivalent OBO surface in the TypeScript SDK
- Go SDK -> Aether Transport — the Go SDK’s Aether transport module