> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memanto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI SDK Integration

> Give OpenAI Node SDK agents persistent, cross-session memory with Memanto tools.

# OpenAI SDK + Memanto

<img src="https://mintcdn.com/memanto/7cqii5_wGejS32un/logo/integrations/openai.svg?fit=max&auto=format&n=7cqii5_wGejS32un&q=85&s=7483f4632a534a02f01dbd103c110a24" alt="OpenAI" width="64" style={{marginBottom: "1.5rem"}} data-path="logo/integrations/openai.svg" />

Add persistent memory to any [OpenAI Node SDK](https://github.com/openai/openai-node) agent with three ready-made tools, shipped as part of the `@moorcheh-ai/memanto` TypeScript SDK.

## Prerequisites

* Node.js 20+
* [Moorcheh API key](https://console.moorcheh.ai/api-keys) (or an on-prem Memanto backend — see [On-Prem](/on-prem/overview))
* `openai` and `zod` installed in your app (optional peer dependencies of `@moorcheh-ai/memanto`)

## Install

```bash theme={null}
npm install @moorcheh-ai/memanto openai zod
```

`openai` and `zod` are optional peer dependencies of `@moorcheh-ai/memanto` — install them yourself in the host app; `createMemantoOpenAITools` fails fast with a clear error if they're missing.

## Quick Start

```ts theme={null}
import OpenAI from "openai";
import { Memanto } from "@moorcheh-ai/memanto";
import { createMemantoOpenAITools } from "@moorcheh-ai/memanto/openai";

const client = new OpenAI();
const memanto = new Memanto({ agentId: "my-agent" });

const runner = client.chat.completions.runTools({
  model: "gpt-4o",
  tools: createMemantoOpenAITools(memanto),
  messages: [
    { role: "user", content: "What milk does Alex like? Also note he switched to soy today." },
  ],
});

console.log(await runner.finalContent());
```

`createMemantoOpenAITools` returns an array of tools built with `zodFunction`, ready to hand to the OpenAI Node SDK's [`runTools()`](https://github.com/openai/openai-node#automated-function-calls) helper — each tool auto-parses its JSON arguments against a Zod schema before invoking Memanto.

## Available Tools

| Tool             | Backed by                                                  | Description                                                                                                                                           |
| ---------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `recallMemory`   | [Recall](/api-reference/search/recall)                     | Semantic search over stored memories. `query` (required), `limit`, `type` (filter by memory type).                                                    |
| `rememberMemory` | [Remember](/api-reference/data/remember)                   | Persist a durable fact/preference/decision/instruction. `content` (required), `type` (optional — server auto-classifies if omitted), `title`, `tags`. |
| `answerMemory`   | [Generate AI Answer](/api-reference/ai/generate-ai-answer) | RAG-synthesized answer over stored memories. `question` (required), `limit`.                                                                          |

<Note>
  Unlike the Vercel AI SDK and Mastra variants, this integration's schemas use nullable fields (`.nullable()`) instead of optional ones, matching the OpenAI function-calling convention where the model must explicitly pass `null` rather than omit a field.
</Note>

## Options

```ts theme={null}
createMemantoOpenAITools(memanto, {
  include: ["recallMemory", "answerMemory"], // expose a subset — omit for all three
  defaultLimit: 10,                           // default limit for recall/answer when the model doesn't specify one
});
```

## Memory Types

`type` fields are constrained to Memanto's 13 supported types via a shared `MEMORY_TYPES` export:

```ts theme={null}
import { MEMORY_TYPES } from "@moorcheh-ai/memanto/openai";
// ["fact", "preference", "goal", "decision", "artifact", "learning", "event",
//  "instruction", "relationship", "context", "observation", "commitment", "error"]
```

See the [Memory Types Reference](/reference/memory-types) for what each type means.

## On-Prem

The integration talks to Memanto through the `Memanto` client, so it works identically against an on-prem backend — no code changes, just configure the backend once with the CLI. See [On-Prem Overview](/on-prem/overview) and the [TypeScript SDK Reference](/sdk/typescript#on-prem-no-api-key).

## Next Steps

* [TypeScript SDK Reference](/sdk/typescript) for the full `Memanto` client API
* [Vercel AI SDK Integration](/integrations/vercel-ai-sdk) for the equivalent AI SDK tools
* [Mastra Integration](/integrations/mastra) for the equivalent Mastra tools
* [Memory Types Reference](/reference/memory-types)
