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

# Extract Facts

> POST /v1/memories/extract — Extract and store facts from conversation via LLM.

<Snippet file="snippets/x402-callout.mdx" />

**Price:** \$0.01 USDC (includes LLM processing)

Extract automatically identifies and stores important facts from a conversation. The LLM parses the messages and creates individual memories for each distinct fact, with automatic deduplication.

## Request Body

<ParamField body="messages" type="array" required>
  Array of conversation messages. Each message must have `role` (string) and `content` (string). Max 100 messages, 32,768 characters per message.
</ParamField>

<ParamField body="namespace" type="string">
  Namespace for extracted memories. Default: `"default"`.
</ParamField>

<ParamField body="session_id" type="string">
  Associate extracted memories with a session.
</ParamField>

<ParamField body="agent_id" type="string">
  Associate extracted memories with an agent.
</ParamField>

## Response (201 Created)

<ResponseField name="memory_ids" type="string[]">
  UUIDs of the stored memories (includes both new and deduplicated).
</ResponseField>

<ResponseField name="facts_extracted" type="number">
  Total facts identified by the LLM.
</ResponseField>

<ResponseField name="facts_stored" type="number">
  New facts stored (not duplicates).
</ResponseField>

<ResponseField name="facts_deduplicated" type="number">
  Facts that matched existing memories (skipped).
</ResponseField>

<ResponseField name="tokens_used" type="number">
  Total tokens consumed (LLM + embeddings).
</ResponseField>

## Example

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.memoclaw.com/v1/memories/extract \
    -H "Content-Type: application/json" \
    -d '{
      "messages": [
        {"role": "user", "content": "I prefer dark mode in all my apps. Also, my timezone is PST."},
        {"role": "assistant", "content": "Got it! I will remember your preferences."}
      ]
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api.memoclaw.com/v1/memories/extract", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      messages: [
        { role: "user", content: "I prefer dark mode in all my apps. Also, my timezone is PST." },
        { role: "assistant", content: "Got it! I will remember your preferences." },
      ],
    }),
  });

  const data = await response.json();
  ```

  ```python Python theme={null}
  from memoclaw import MemoClaw

  client = MemoClaw()
  result = client.extract([
      {"role": "user", "content": "I prefer dark mode in all my apps. Also, my timezone is PST."},
      {"role": "assistant", "content": "Got it! I will remember your preferences."},
  ])
  ```
</CodeGroup>

```json Response theme={null}
{
  "memory_ids": [
    "550e8400-e29b-41d4-a716-446655440010",
    "550e8400-e29b-41d4-a716-446655440011"
  ],
  "facts_extracted": 2,
  "facts_stored": 2,
  "facts_deduplicated": 0,
  "tokens_used": 185
}
```

<Note>
  The LLM automatically assigns importance and memory type based on the content. Corrections and preferences get higher importance; observations get lower. Each fact is deduplicated against existing memories.
</Note>
