{
  "id": "api-examples",
  "title": "Self-managed API examples",
  "url": "https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/self-managed/api-examples/",
  "summary": "Use curl examples with the Redis Agent Memory self-managed Control Plane and Data Plane APIs.",
  "tags": [
    "docs",
    "develop",
    "ai"
  ],
  "last_updated": "2026-07-28T14:23:48-07:00",
  "page_type": "content",
  "content_hash": "078359a06b2a2a843fde57adee41bfcba531723d8f7c9713e68f8e6ce05a028a",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "These examples show self-managed Control Plane and Data Plane requests.\n\nThey assume either an auth-disabled private Data Plane or agent-key auth\nconfigured as described in [Authentication and authorization](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/self-managed/authentication).\n\nFor the complete shared Data Plane schema, see the\n[Redis Agent Memory API](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/api-reference).\nFor the self-managed admin schema, see the\n[Control Plane API reference](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/self-managed/control-plane-api-reference)."
    },
    {
      "id": "control-plane-api-examples",
      "title": "Control Plane API examples",
      "role": "content",
      "text": "Set variables:\n\n[code example]\n\nList stores:\n\n[code example]\n\nCreate a store:\n\n[code example]\n\nResponse:\n\n[code example]\n\nMint an agent key:\n\n[code example]\n\nResponse:\n\n[code example]\n\nAgent-key fields:\n\n| Field | Notes |\n| ----- | ----- |\n| Endpoint | Use `/v1/api-keys`. |\n| `name` | Required. |\n| `grants` | Required. |\n| `resourceType` | Use `mem-store`. |\n| `resourceId` | Set to the store ID. |\n| `actions` | Use `read`, `write`, or both. |\n| Token | Returned only when you mint or rotate a key. Store it immediately. |"
    },
    {
      "id": "data-plane-api-examples",
      "title": "Data Plane API examples",
      "role": "content",
      "text": "Set variables:\n\n[code example]\n\nFor auth-disabled deployments, omit the `Authorization` header and rely on the\ndeployment's hosting controls."
    },
    {
      "id": "write-a-session-event",
      "title": "Write a session event",
      "role": "content",
      "text": "[code example]\n\nRequest body fields:\n\n| Field | Notes |\n| ----- | ----- |\n| `actorId` | Required. |\n| `role` | Required. Use `USER`, `ASSISTANT`, or `SYSTEM`. |\n| `content` | Required. For text, use a content object such as `{\"text\": \"...\"}`. |\n| `createdAt` | Required. Use an RFC 3339 timestamp, for example `2026-06-25T18:00:00Z`. |\n| `sessionId` | Optional. If omitted, Agent Memory generates one. |"
    },
    {
      "id": "read-session-memory",
      "title": "Read session memory",
      "role": "content",
      "text": "[code example]"
    },
    {
      "id": "list-sessions",
      "title": "List sessions",
      "role": "content",
      "text": "List sessions for a specific owner:\n\n[code example]\n\nList all sessions:\n\n[code example]\n\n`filterOwnerId` and `includeAll` are mutually exclusive."
    },
    {
      "id": "create-long-term-memories-directly",
      "title": "Create long-term memories directly",
      "role": "content",
      "text": "[code example]"
    },
    {
      "id": "search-long-term-memory",
      "title": "Search long-term memory",
      "role": "content",
      "text": "[code example]"
    }
  ],
  "examples": [
    {
      "id": "control-plane-api-examples-ex0",
      "language": "bash",
      "code": "CP_URL=\"http://localhost:9100\"\nRAM_ADMIN_TOKEN=\"<admin-token>\"",
      "section_id": "control-plane-api-examples"
    },
    {
      "id": "control-plane-api-examples-ex1",
      "language": "bash",
      "code": "curl -sS \"$CP_URL/v1/stores\" \\\n  -H \"Authorization: Bearer $RAM_ADMIN_TOKEN\"",
      "section_id": "control-plane-api-examples"
    },
    {
      "id": "control-plane-api-examples-ex2",
      "language": "bash",
      "code": "curl -sS -X POST \"$CP_URL/v1/stores\" \\\n  -H \"Authorization: Bearer $RAM_ADMIN_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"my-store\"\n  }'",
      "section_id": "control-plane-api-examples"
    },
    {
      "id": "control-plane-api-examples-ex3",
      "language": "json",
      "code": "{\n  \"storeId\": \"<store-id>\"\n}",
      "section_id": "control-plane-api-examples"
    },
    {
      "id": "control-plane-api-examples-ex4",
      "language": "bash",
      "code": "curl -sS -X POST \"$CP_URL/v1/api-keys\" \\\n  -H \"Authorization: Bearer $RAM_ADMIN_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"my-agent-key\",\n    \"grants\": [\n      {\n        \"resourceType\": \"mem-store\",\n        \"resourceId\": \"<store-id>\",\n        \"actions\": [\"read\", \"write\"]\n      }\n    ]\n  }'",
      "section_id": "control-plane-api-examples"
    },
    {
      "id": "control-plane-api-examples-ex5",
      "language": "json",
      "code": "{\n  \"keyId\": \"0123456789abcdef0123456789abcdef\",\n  \"token\": \"<agent-key>\",\n  \"createdAt\": 1780000000\n}",
      "section_id": "control-plane-api-examples"
    },
    {
      "id": "data-plane-api-examples-ex0",
      "language": "bash",
      "code": "DP_URL=\"http://localhost:9000\"\nSTORE_ID=\"<store-id>\"\nRAM_AGENT_KEY=\"<agent-key>\"",
      "section_id": "data-plane-api-examples"
    },
    {
      "id": "write-a-session-event-ex0",
      "language": "bash",
      "code": "curl -sS -X POST \"$DP_URL/v1/stores/$STORE_ID/session-memory/events\" \\\n  -H \"Authorization: Bearer $RAM_AGENT_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"sessionId\": \"session-001\",\n    \"actorId\": \"user-001\",\n    \"role\": \"USER\",\n    \"content\": [\n      {\n        \"text\": \"What is the capital of France?\"\n      }\n    ],\n    \"createdAt\": \"2026-06-25T18:00:00Z\"\n  }'",
      "section_id": "write-a-session-event"
    },
    {
      "id": "read-session-memory-ex0",
      "language": "bash",
      "code": "curl -sS \"$DP_URL/v1/stores/$STORE_ID/session-memory/session-001\" \\\n  -H \"Authorization: Bearer $RAM_AGENT_KEY\"",
      "section_id": "read-session-memory"
    },
    {
      "id": "list-sessions-ex0",
      "language": "bash",
      "code": "curl -sS \"$DP_URL/v1/stores/$STORE_ID/session-memory?filterOwnerId=user-001\" \\\n  -H \"Authorization: Bearer $RAM_AGENT_KEY\"",
      "section_id": "list-sessions"
    },
    {
      "id": "list-sessions-ex1",
      "language": "bash",
      "code": "curl -sS \"$DP_URL/v1/stores/$STORE_ID/session-memory?includeAll=true\" \\\n  -H \"Authorization: Bearer $RAM_AGENT_KEY\"",
      "section_id": "list-sessions"
    },
    {
      "id": "create-long-term-memories-directly-ex0",
      "language": "bash",
      "code": "curl -sS -X POST \"$DP_URL/v1/stores/$STORE_ID/long-term-memory\" \\\n  -H \"Authorization: Bearer $RAM_AGENT_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"memories\": [\n      {\n        \"id\": \"pref-email-updates\",\n        \"text\": \"User prefers email updates.\",\n        \"memoryType\": \"semantic\",\n        \"ownerId\": \"user-001\",\n        \"namespace\": \"preferences\",\n        \"topics\": [\"communications\"]\n      }\n    ]\n  }'",
      "section_id": "create-long-term-memories-directly"
    },
    {
      "id": "search-long-term-memory-ex0",
      "language": "bash",
      "code": "curl -sS -X POST \"$DP_URL/v1/stores/$STORE_ID/long-term-memory/search\" \\\n  -H \"Authorization: Bearer $RAM_AGENT_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"text\": \"How should we contact this user?\",\n    \"filter\": {\n      \"ownerId\": {\n        \"eq\": \"user-001\"\n      }\n    },\n    \"limit\": 5\n  }'",
      "section_id": "search-long-term-memory"
    }
  ]
}
