SDKs
TypeScript SDK
Install, configure, and use the MemHQ TypeScript SDK.
TypeScript SDK
@memhq/sdk is the canonical client for MemHQ from a Node, edge, or
browser-server agent. It ships full TypeScript types and works
unchanged on Node 18+, Bun, Deno, and the major edge runtimes.
Install
npm install @memhq/sdk
# or
pnpm add @memhq/sdk
# or
yarn add @memhq/sdkConfigure
Set MEMHQ_API_KEY in your environment:
export MEMHQ_API_KEY="mhq_live_..."The client picks it up automatically:
import { MemoryClient } from "@memhq/sdk";
const client = new MemoryClient();Or pass the key explicitly:
const client = new MemoryClient({ apiKey: "mhq_live_..." });Available constructor options:
| Option | Default | Description |
|---|---|---|
apiKey | process.env.MEMHQ_API_KEY | Project API key. |
baseUrl | https://api.memhq.ai | Override for self-hosted control planes. |
timeout | 30000 (ms) | Per-request timeout. |
maxRetries | 3 | Retries on 429/5xx with exponential backoff. |
fetch | global fetch | Inject a custom fetch (e.g. for proxy support). |
Usage
The methods mirror the Memory API:
// Ingest
const episode = await client.add({
userId: "user_42",
messages: [{ role: "user", content: "I'm vegetarian." }],
});
// Search
const results = await client.search({
userId: "user_42",
query: "dietary preferences",
});
// Ask
const answer = await client.ask({
userId: "user_42",
question: "What should I order them?",
});
console.log(answer.text);Streaming ask
ask supports server-sent events for token-by-token streaming:
const stream = await client.ask.stream({
userId: "user_42",
question: "Summarize their food preferences.",
});
for await (const chunk of stream) {
process.stdout.write(chunk.delta);
}Coming soon — full guide. Error classes, the dashboard-side client surface, and framework-specific recipes (Next.js, Hono, Vercel AI SDK) will be documented in the next pass.