For the complete documentation index, see llms.txt. This page is also available as Markdown.

Session Management

Sessions are the way PizzaStack tracks all objects (tomatoes, sliced ingredients, sauces, bases, pizzas) across API calls. Every request includes an X-Session-ID header that links it to a session.

How Sessions Work

A session is created automatically the first time you make a request with a given X-Session-ID value. All objects created during that session are tracked and can reference each other by ID.

import requests
import uuid

API_BASE = "https://api.tomatopy.pizza/v1"
HEADERS = {
    "Content-Type": "application/json",
    "X-API-Key": "your-api-key",
    "X-Session-ID": str(uuid.uuid4())  # New session
}

# This request creates the session and a tomato within it
response = requests.post(f"{API_BASE}/tomato/acquire", headers=HEADERS, json={
    "variety": "San Marzano",
    "ripeness": 0.8,
    "weight": 150
})
tomato = response.json()

The X-Session-ID Header

The X-Session-ID header is required on every request. It can be any unique string, but UUIDs are recommended.

All requests in the same workflow should use the same session ID. Objects from one session cannot be referenced in another session.

Object Tracking Within a Session

Every object you create gets a unique ID prefixed by its type:

Prefix
Type
Created By

tom_

Raw tomato

/tomato/acquire

slc_

Sliced tomato

/tomato/slice

jce_

Tomato juice

/tomato/squeeze

sce_

Sauce

/cook/simmer

rst_

Roasted ingredient

/cook/roast

bas_

Pizza base

/pizza/base

pza_

Assembled pizza

/pizza/assemble

bkd_

Baked pizza

/pizza/bake

These IDs are only valid within their session. Passing an ID from one session into a request with a different X-Session-ID will return a 400 error.

Debug Endpoint

GET /v1/session/{session_id}/log

Retrieve a log of all objects and operations in a session. This is useful for debugging pipeline issues.

Using curl:

Session Lifecycle

Sessions have a limited lifetime. After a period of inactivity, sessions expire and their objects are no longer accessible.

Error Handling

Best Practices

  1. One Session Per Workflow

    Use a fresh session ID for each independent pizza-making workflow. Do not reuse session IDs across unrelated workflows.

  2. Use UUIDs for Session IDs

  3. Check Session State When Debugging

    If something is not working as expected, use the debug endpoint to inspect what objects exist and their quality values.

  4. Do Not Share Sessions Across Concurrent Workflows

    Each concurrent workflow should have its own session ID to avoid conflicts.

Endpoint Reference

Endpoint
Method
Description

/v1/session/{session_id}/log

GET

Retrieve session log and object state

Next Steps

Last updated

Was this helpful?