Skip to content
Navigation

Session management API routes. Provides CRUD endpoints for chat sessions. Each session groups a conversation with a specific agent, storing messages exchanged during the interaction.

python
from orbiter_server.sessions import (
    AppendMessageRequest,
    CreateSessionRequest,
    Session,
    SessionMessage,
    SessionSummary,
    UpdateSessionRequest,
    session_router,
)

SessionMessage

python
class SessionMessage(BaseModel)

A single message within a session.

FieldTypeDefaultDescription
rolestr(required)Message role (e.g. "user", "assistant")
contentstr(required)Message text content
timestampfloattime.time()When the message was created

Session

python
class Session(BaseModel)

A chat session grouping a conversation with an agent.

FieldTypeDefaultDescription
idstr(auto: 16-char hex)Unique session identifier
agent_namestr""Name of the associated agent
titlestr""Session title
messageslist[SessionMessage][]Conversation messages
created_atfloattime.time()Creation timestamp
updated_atfloattime.time()Last update timestamp

CreateSessionRequest

python
class CreateSessionRequest(BaseModel)

Request body for creating a new session.

FieldTypeDefaultDescription
agent_namestr""Name of the agent for this session
titlestr""Session title

UpdateSessionRequest

python
class UpdateSessionRequest(BaseModel)

Request body for updating a session.

FieldTypeDefaultDescription
titlestr | NoneNoneNew title (unchanged if None)
agent_namestr | NoneNoneNew agent name (unchanged if None)

AppendMessageRequest

python
class AppendMessageRequest(BaseModel)

Request body for appending a message to a session.

FieldTypeDefaultDescription
rolestr(required)Message role
contentstr(required)Message content

SessionSummary

python
class SessionSummary(BaseModel)

Lightweight session info for list responses.

FieldTypeDefaultDescription
idstr(required)Session identifier
agent_namestr(required)Associated agent name
titlestr(required)Session title
message_countint(required)Number of messages
created_atfloat(required)Creation timestamp
updated_atfloat(required)Last update timestamp

session_router

python
session_router = APIRouter(prefix="/sessions", tags=["sessions"])

FastAPI router for session management endpoints. Sessions are stored in-memory on the app state.

Endpoints

POST /sessions

Create a new chat session.

Request body: CreateSessionRequest

Response: Session (status 201)

bash
curl -X POST http://localhost:8000/sessions \
  -H "Content-Type: application/json" \
  -d '{"agent_name": "helper", "title": "Python help"}'

GET /sessions

List all sessions, newest first.

Response: list[SessionSummary]

bash
curl http://localhost:8000/sessions

GET /sessions/{session_id}

Retrieve a single session by ID.

ParameterTypeDescription
session_idstr (path)Session identifier

Response: Session

Errors: 404 if session not found.

PATCH /sessions/{session_id}

Update session metadata (title, agent_name). Only provided fields are updated.

ParameterTypeDescription
session_idstr (path)Session identifier

Request body: UpdateSessionRequest

Response: Session

Errors: 404 if session not found.

bash
curl -X PATCH http://localhost:8000/sessions/abc123 \
  -H "Content-Type: application/json" \
  -d '{"title": "Updated title"}'

DELETE /sessions/{session_id}

Delete a session.

ParameterTypeDescription
session_idstr (path)Session identifier

Response: 204 No Content

Errors: 404 if session not found.

POST /sessions/{session_id}/messages

Append a message to a session’s conversation history.

ParameterTypeDescription
session_idstr (path)Session identifier

Request body: AppendMessageRequest

Response: SessionMessage (status 201)

Errors: 404 if session not found.

bash
curl -X POST http://localhost:8000/sessions/abc123/messages \
  -H "Content-Type: application/json" \
  -d '{"role": "user", "content": "What is Python?"}'

GET /sessions/{session_id}/messages

List all messages in a session.

ParameterTypeDescription
session_idstr (path)Session identifier

Response: list[SessionMessage]

Errors: 404 if session not found.

Example

python
import httpx

async with httpx.AsyncClient(base_url="http://localhost:8000") as client:
    # Create session
    resp = await client.post("/sessions", json={"agent_name": "helper", "title": "Demo"})
    session = resp.json()
    session_id = session["id"]

    # Add messages
    await client.post(f"/sessions/{session_id}/messages", json={"role": "user", "content": "Hello"})
    await client.post(f"/sessions/{session_id}/messages", json={"role": "assistant", "content": "Hi!"})

    # List messages
    resp = await client.get(f"/sessions/{session_id}/messages")
    messages = resp.json()
    print(f"Session has {len(messages)} messages")

    # Delete session
    await client.delete(f"/sessions/{session_id}")