Skip to main content
Acontext stores messages in OpenAI, Anthropic, or Gemini format and automatically converts between them on retrieval.

Store Messages

1

Create a session

import os
from acontext import AcontextClient

client = AcontextClient(
    api_key=os.getenv("ACONTEXT_API_KEY"),
)
session = client.sessions.create()
You can create a session with a specific UUID:
session = client.sessions.create(use_uuid="123e4567-e89b-12d3-a456-426614174000")
This is useful for correlating sessions with external systems. A 409 Conflict error is returned if the UUID already exists.
2

Store messages in any format

client.sessions.store_message(
    session_id=session.id,
    blob={"role": "user", "content": "What is the capital of France?"},
    format="openai"
)

Retrieve Messages

Retrieve in any format—Acontext converts automatically:
# Stored as OpenAI, retrieve as Anthropic
result = client.sessions.get_messages(session_id=session.id, format="anthropic")

for msg in result.items:
    print(f"{msg.role}: {msg.content}")

Delete Session

client.sessions.delete(session_id)
Deleting a session permanently removes all messages.

Next Steps