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

# Anthropic Integration

> Complete working MemoryOS integration with Anthropic Claude.

Tenant-scoped MemoryOS with Anthropic Claude. Same pattern as OpenAI: add memories, retrieve before the model call, skip context only when passthrough is active.

<CodeGroup>
  ```python Python theme={null}
  import os
  from anthropic import Anthropic
  from memoryos import Memory

  memory = Memory(api_key=os.environ["MEMORYOS_API_KEY"])
  anthropic = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

  external_user_id = "customer-123"
  latest_user_message = "How should you tailor the response for me?"

  memory.add(
      messages=[{"role": "user", "content": "I like structured answers with short bullet points."}],
      external_user_id=external_user_id,
  )

  memories = memory.get(query=latest_user_message, external_user_id=external_user_id, limit=5)

  system_prompt = "You are a helpful assistant."
  if not memories.is_passthrough and memories.system_prompt_addition:
      system_prompt = f"{system_prompt}\n\n{memories.system_prompt_addition}"

  response = anthropic.messages.create(
      model="claude-sonnet-4-20250514",
      max_tokens=500,
      system=system_prompt,
      messages=[{"role": "user", "content": latest_user_message}],
  )

  print(response.content[0].text)
  memory.close()
  ```

  ```ts TypeScript theme={null}
  import Anthropic from "@anthropic-ai/sdk";
  import { MemoryOS } from "@memoryos/sdk";

  const memory = new MemoryOS(process.env.MEMORYOS_API_KEY!);
  const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY! });

  const externalUserId = "customer-123";
  const latestUserMessage = "How should you tailor the response for me?";

  await memory.add(
    [{ role: "user", content: "I like structured answers with short bullet points." }],
    externalUserId,
  );

  const memories = await memory.get(latestUserMessage, externalUserId, 5);

  let systemPrompt = "You are a helpful assistant.";
  if (!memories.isPassthrough && memories.systemPromptAddition) {
    systemPrompt = `${systemPrompt}\n\n${memories.systemPromptAddition}`;
  }

  const response = await anthropic.messages.create({
    model: "claude-sonnet-4-20250514",
    max_tokens: 500,
    system: systemPrompt,
    messages: [{ role: "user", content: latestUserMessage }],
  });

  const firstBlock = response.content[0];
  if (firstBlock.type === "text") {
    console.log(firstBlock.text);
  }
  ```
</CodeGroup>

**Key rules:**

* Keep `MEMORYOS_API_KEY` server-side
* Always call Claude, even when MemoryOS is in passthrough
* Use Memory Passport only when one user intentionally shares memory across multiple agents

For the cross-agent flow, see [Cross-agent memory sharing](/guides/cross-agent-sharing).
