Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.meibel.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sessions & Chat

Sessions represent a conversation between a user and an agent. Each session maintains its own message history and context window. This guide covers creating sessions, sending messages (synchronously or via streaming), and retrieving conversation history.

Create a session

Start a new conversation by creating a session tied to a specific agent.
import os
from meibel import MeibelClient

client = MeibelClient(api_key=os.environ["MEIBEL_API_KEY"])

session = client.agents.create_session(agent_id="agent_123")

print(session.id)
print(session.agent_id)
The response includes the session id, the agent_id it belongs to, and creation timestamps. Store the session id to send messages and retrieve history.

Send a chat message (synchronous)

Send a message and wait for the complete response. This is the simplest approach and works well when you do not need to display partial results.
from meibel.models import ChatMessageRequest

response = client.sessions.send_chat_message(
    session_id=session.id,
    body=ChatMessageRequest(
        user_message="What are the key findings in the Q4 report?",
    ),
)

print(response.message)
print(response.citations)
The response includes the assistant’s message, any citations referencing datasource content, and metadata such as token usage.

Stream a chat response (SSE)

For a more responsive user experience, stream the response as Server-Sent Events. Each event delivers a chunk of the assistant’s reply as it is generated.
from meibel.models import ChatMessageRequest

stream = client.sessions.send_chat_message_stream(
    session_id=session.id,
    body=ChatMessageRequest(
        user_message="Summarize the revenue trends over the last 3 quarters.",
    ),
)

for event in stream:
    if event.type == "content":
        print(event.delta, end="", flush=True)
    elif event.type == "citations":
        print("\n\nCitations:", event.citations)
    elif event.type == "done":
        print("\n\n[Stream complete]")
The streaming endpoint uses Server-Sent Events (SSE). Each event has a type field — common types include content (text chunks), citations (source references), and done (stream finished).

Get session message history

Retrieve all messages exchanged in a session, in chronological order.
messages = client.sessions.get_session_messages(session_id=session.id)

for msg in messages:
    print(f"[{msg.role}] {msg.message}")
Each message includes role (either "user" or "assistant"), the message content, and a timestamp.

Get session details

Retrieve metadata about a session, including its agent, creation time, and status.
session = client.sessions.get_session(session_id="session_456")

print(session.id)
print(session.agent_id)
print(session.created_at)