{
  "id": "api-examples",
  "title": "Use the Redis Agent Memory API and SDK",
  "url": "https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/api-examples/",
  "summary": "Learn to use the Redis Agent Memory API for agent memory and semantic memory search.",
  "tags": [
    "docs",
    "develop",
    "ai"
  ],
  "last_updated": "2026-05-18T05:44:54-07:00",
  "page_type": "content",
  "content_hash": "a011e81b50ed7c1798f27321766edfbd2f777baa769e33843ebfbcddd4ab1d0c",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Use the [Agent Memory API](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/api-reference) from your client app to store and retrieve agent memory information.\n\nYou can use any standard REST client or library to access the API. If your app is written in Python, you can also use the [Agent Memory Software Development Kit](https://pypi.org/project/redis-agent-memory/) (SDK) to access the API."
    },
    {
      "id": "authentication",
      "title": "Authentication",
      "role": "security",
      "text": "To access the Agent Memory API, you need:\n\n- Agent Memory API endpoint\n- an Agent Memory API user key\n- a Store ID\n\nWhen you call the API, you need to pass the Agent Memory API key in the `Authorization` header as a Bearer token and the store ID as the `storeId` path parameter.\n\nFor example:\n\n[code example]\n\nThis example expects several variables to be set in the shell:\n\n- **$HOST** - the Agent Memory API endpoint\n- **$STORE_ID** - the Store ID of your Agent Memory service\n- **$API_KEY** - The Agent Memory API token"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": ""
    },
    {
      "id": "add-session-event",
      "title": "Add session event",
      "role": "content",
      "text": "Use [`POST /v1/stores/{storeId}/session-memory/events`](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/api-reference#tag/session-memory/operation/AddSessionEvent) to add an event to a session in short-term memory. If a session doesn't exist yet, it will be created.\n\n[code example]\n\nUse this endpoint to store conversations between your users and your AI agent. You can use the `metadata` object to store additional metadata for your application.\n\nThe Agent Memory model will automatically promote relevant short-term memories to long-term memory."
    },
    {
      "id": "add-long-term-memories",
      "title": "Add Long-term memories",
      "role": "content",
      "text": "You may want to add one or more long-term memories to add specific preference information.\n\nUse [`POST /v1/stores/{storeId}/long-term-memory/`](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/api-reference#tag/long-term-memory/operation/BulkCreateLongTermMemories) to add one or more long-term memories to long-term memory storage.\n\n[code example]"
    },
    {
      "id": "search-long-term-memories",
      "title": "Search Long-term memories",
      "role": "content",
      "text": "Use [`POST /v1/stores/{storeId}/long-term-memory/search`](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory/api-reference#tag/long-term-memory/operation/SearchLongTermMemory) to search for long-term memories.\n\n[code example]\n\nIn the `filter` object of the request body, you can filter the search by any of the following values:\n\n| Filter | Data type | Definition | Supported operators | \n|--------|----------|------------|---------------------|\n| `sessionId` | string | The session ID the memory comes from. | `eq`, `ne`, `in`, `all` |\n| `ownerId` | string | The owner ID of the memory. | `eq`, `ne`, `in`, `all` |\n| `namespace` | string | The namespace of the memory. | `eq`, `ne`, `in`, `all` |\n| `topics` | string | The topics of the memory. | `eq`, `ne`, `in`, `all` |\n| `memoryType` | string | The type of memory (`semantic`, `episodic`, `message`). | `eq`, `ne`, `in`, `all` |\n| `createdAt` | string (ISO 8601) | The timestamp when the memory was created. | `eq`, `gt`, `lt`, `gte`, `lte` |\n\nFor all values, you must set only one of these operators:\n\n| Operator | Definition |\n|----------|---------------------|\n| `eq` | Returns memories with the value equal to the provided value. |\n| `ne` | Returns memories where the value is not the provided value. |\n| `in` | Returns memories where the value is one of a list of provided values. |\n| `all` | Returns memories where the value matches all of the provided values. |\n| `gt` | Returns memories where the value is greater than the provided value. |\n| `lt` | Returns memories where the value is less than the provided value. |\n| `gte` | Returns memories where the value is greater than or equal to the provided value. |\n| `lte` | Returns memories where the value is less than or equal to the provided value. |"
    }
  ],
  "examples": [
    {
      "id": "authentication-ex0",
      "language": "sh",
      "code": "curl -s -X GET \"https://$HOST/v1/stores/$STORE_ID/session-memory\" \\\n    -H \"accept: application/json\" \\\n    -H \"Authorization: Bearer $API_KEY\"",
      "section_id": "authentication"
    },
    {
      "id": "add-session-event-ex0",
      "language": "json",
      "code": "POST /v1/stores/{storeId}/session-memory/events\n{\n    \"sessionId\": \"abcd-efgh\",\n    \"actorId\": \"user-name\",\n    \"role\": \"USER\",\n    \"content\": [\n        {\n            \"text\": \"I'm planning a trip to Japan next month.\"\n        }\n    ],\n    \"createdAt\": \"2026-05-02T18:15:06Z\",\n    \"metadata\": {\n        \"browser\": \"Chrome\",\n        \"source\": \"web-chat\"\n      }\n}",
      "section_id": "add-session-event"
    },
    {
      "id": "add-long-term-memories-ex0",
      "language": "json",
      "code": "POST /v1/stores/{storeId}/long-term-memory\n{\n    \"memories\": [\n        {\n            \"id\": \"cofIXpuMmg\",\n            \"text\": \"The user prefers vegetarian food.\",\n            \"memoryType\": \"episodic\",\n            \"sessionId\": \"abcd-efgh\",\n            \"ownerId\": \"user-name\",\n        }\n    ]\n}",
      "section_id": "add-long-term-memories"
    },
    {
      "id": "search-long-term-memories-ex0",
      "language": "json",
      "code": "POST /v1/stores/{storeId}/long-term-memory/search\n{\n    \"text\": \"user preferences\",\n    \"similarityThreshold\": 0.48725898820184166,\n    \"filter\": {\n        \"sessionId\": {\n            \"eq\": \"abcd-efgh\"\n        },\n        \"ownerId\": {\n            \"in\": [\n                \"user1\",\n                \"user2\"\n            ]\n        }\n    },\n    \"filterOp\": \"any\"\n}",
      "section_id": "search-long-term-memories"
    }
  ]
}
