@@ -35,7 +35,7 @@ The easiest way to add memory capabilities to your OpenAI client is using the `w
3535``` python
3636import asyncio
3737from openai import AsyncOpenAI
38- from supermemory_openai import with_supermemory, OpenAIMiddlewareOptions
38+ from supermemory_openai import with_supermemory, SupermemoryOpenAIOptions
3939
4040async def main ():
4141 # Create OpenAI client
@@ -44,8 +44,9 @@ async def main():
4444 # Wrap with Supermemory middleware
4545 openai_with_memory = with_supermemory(
4646 openai,
47- container_tag = " user-123" , # Unique identifier for user's memories
48- options = OpenAIMiddlewareOptions(
47+ SupermemoryOpenAIOptions(
48+ container_tag = " user-123" , # Unique identifier for user's memories
49+ custom_id = " chat-session-1" , # Required: groups messages into conversations
4950 mode = " full" , # "profile", "query", or "full"
5051 verbose = True , # Enable logging
5152 add_memory = " always" # Automatically save conversations
@@ -118,11 +119,17 @@ The middleware also works with synchronous OpenAI clients:
118119
119120``` python
120121from openai import OpenAI
121- from supermemory_openai import with_supermemory
122+ from supermemory_openai import with_supermemory, SupermemoryOpenAIOptions
122123
123124# Sync client
124125openai = OpenAI(api_key = " your-openai-api-key" )
125- openai_with_memory = with_supermemory(openai, " user-123" )
126+ openai_with_memory = with_supermemory(
127+ openai,
128+ SupermemoryOpenAIOptions(
129+ container_tag = " user-123" ,
130+ custom_id = " chat-session-1"
131+ )
132+ )
126133
127134# Works the same way
128135response = openai_with_memory.chat.completions.create(
@@ -137,12 +144,24 @@ response = openai_with_memory.chat.completions.create(
137144
138145``` python
139146# Async context manager (recommended)
140- async with with_supermemory(openai, " user-123" ) as client:
147+ async with with_supermemory(
148+ openai,
149+ SupermemoryOpenAIOptions(
150+ container_tag = " user-123" ,
151+ custom_id = " chat-session-1"
152+ )
153+ ) as client:
141154 response = await client.chat.completions.create(... )
142155# Background tasks automatically waited for on exit
143156
144157# Manual cleanup
145- client = with_supermemory(openai, " user-123" )
158+ client = with_supermemory(
159+ openai,
160+ SupermemoryOpenAIOptions(
161+ container_tag = " user-123" ,
162+ custom_id = " chat-session-1"
163+ )
164+ )
146165response = await client.chat.completions.create(... )
147166await client.wait_for_background_tasks() # Ensure memory is saved
148167```
@@ -159,8 +178,11 @@ Injects all static and dynamic profile memories into every request. Best for mai
159178``` python
160179openai_with_memory = with_supermemory(
161180 openai,
162- " user-123" ,
163- OpenAIMiddlewareOptions(mode = " profile" )
181+ SupermemoryOpenAIOptions(
182+ container_tag = " user-123" ,
183+ custom_id = " chat-session-1" ,
184+ mode = " profile"
185+ )
164186)
165187```
166188
@@ -170,8 +192,11 @@ Only searches for memories relevant to the current user message. More efficient
170192``` python
171193openai_with_memory = with_supermemory(
172194 openai,
173- " user-123" ,
174- OpenAIMiddlewareOptions(mode = " query" )
195+ SupermemoryOpenAIOptions(
196+ container_tag = " user-123" ,
197+ custom_id = " chat-session-1" ,
198+ mode = " query"
199+ )
175200)
176201```
177202
@@ -181,8 +206,11 @@ Combines both profile and query modes - includes all profile memories plus relev
181206``` python
182207openai_with_memory = with_supermemory(
183208 openai,
184- " user-123" ,
185- OpenAIMiddlewareOptions(mode = " full" )
209+ SupermemoryOpenAIOptions(
210+ container_tag = " user-123" ,
211+ custom_id = " chat-session-1" ,
212+ mode = " full"
213+ )
186214)
187215```
188216
@@ -192,22 +220,30 @@ Control when conversations are automatically saved as memories:
192220
193221``` python
194222# Always save conversations as memories
195- OpenAIMiddlewareOptions(add_memory = " always" )
223+ SupermemoryOpenAIOptions(
224+ container_tag = " user-123" ,
225+ custom_id = " chat-session-1" ,
226+ add_memory = " always"
227+ )
196228
197229# Never save conversations (default)
198- OpenAIMiddlewareOptions(add_memory = " never" )
230+ SupermemoryOpenAIOptions(
231+ container_tag = " user-123" ,
232+ custom_id = " chat-session-1" ,
233+ add_memory = " never"
234+ )
199235```
200236
201237### Complete Configuration Example
202238
203239``` python
204- from supermemory_openai import with_supermemory, OpenAIMiddlewareOptions
240+ from supermemory_openai import with_supermemory, SupermemoryOpenAIOptions
205241
206242openai_with_memory = with_supermemory(
207243 openai_client,
208- container_tag = " user-123 " ,
209- options = OpenAIMiddlewareOptions(
210- conversation_id = " chat-session-456" , # Group messages into conversations
244+ SupermemoryOpenAIOptions(
245+ container_tag = " user-123 " ,
246+ custom_id = " chat-session-456" ,
211247 verbose = True , # Enable detailed logging
212248 mode = " full" , # Use both profile and query
213249 add_memory = " always" # Auto-save conversations
@@ -291,25 +327,25 @@ Wraps an OpenAI client with automatic memory injection middleware.
291327``` python
292328def with_supermemory (
293329 openai_client : Union[OpenAI, AsyncOpenAI],
294- container_tag : str ,
295- options : Optional[OpenAIMiddlewareOptions] = None
330+ options : SupermemoryOpenAIOptions
296331) -> Union[OpenAI, AsyncOpenAI]
297332```
298333
299334** Parameters:**
300335- `openai_client` : OpenAI or AsyncOpenAI client instance
301- - `container_tag` : Unique identifier for memory storage (e.g., user ID )
302- - `options` : Configuration options (see `OpenAIMiddlewareOptions` )
336+ - `options` : Configuration options (see `SupermemoryOpenAIOptions` )
303337
304- # ### `OpenAIMiddlewareOptions `
338+ # ### `SupermemoryOpenAIOptions `
305339
306340Configuration dataclass for middleware behavior.
307341
308342```python
309343@ dataclass
310- class OpenAIMiddlewareOptions:
311- conversation_id: Optional[str ] = None # Group messages into conversations
312- verbose: bool = False # Enable detailed logging
344+ class SupermemoryOpenAIOptions:
345+ container_tag: str # Required: unique identifier for memory storage
346+ custom_id: str # Required: groups messages into conversations
347+ api_key: Optional[str ] = None # Supermemory API key (or use env var)
348+ verbose: bool = False # Enable detailed logging
313349 mode: Literal[" profile" , " query" , " full" ] = " profile" # Memory injection mode
314350 add_memory: Literal[" always" , " never" ] = " never" # Auto-save behavior
315351```
@@ -349,7 +385,13 @@ from supermemory_openai import (
349385
350386try :
351387 # This will raise SupermemoryConfigurationError if API key is missing
352- client = with_supermemory(openai_client, " user-123" )
388+ client = with_supermemory(
389+ openai_client,
390+ SupermemoryOpenAIOptions(
391+ container_tag = " user-123" ,
392+ custom_id = " chat-session-1"
393+ )
394+ )
353395
354396 response = await client.chat.completions.create(
355397 messages = [{" role" : " user" , " content" : " Hello" }],
0 commit comments