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

API Usage Best Practices

This guide covers best practices for using the PizzaStack API efficiently and correctly.

Error Handling

Always Check Response Status

import requests

API_BASE = "https://api.tomatopy.pizza/v1"
HEADERS = {
    "Content-Type": "application/json",
    "X-API-Key": "your-api-key",
    "X-Session-ID": "your-session-id"
}

# GOOD: Check status and handle errors
response = requests.post(f"{API_BASE}/tomato/acquire", headers=HEADERS, json={
    "variety": "San Marzano",
    "ripeness": 0.8,
    "weight": 150
})

if response.status_code == 200:
    tomato = response.json()
elif response.status_code == 400:
    print(f"Bad request: {response.json()['message']}")
elif response.status_code == 401:
    print("Invalid API key")
else:
    print(f"Unexpected error: {response.status_code}")

Use raise_for_status()

For simpler scripts, use raise_for_status() to throw exceptions on errors:

Create a Helper Function

Reduce boilerplate with a wrapper:

Checking Response Quality Fields

Sauce responses include a sauce_quality field. Always check it to catch pipeline issues early.

Validating Pipeline Order

The PizzaStack pipeline has strict ordering requirements. Two key rules to follow:

Rule 1: Slice Before Simmering

Raw tomato IDs passed to /cook/simmer will not cause an error, but the sauce quality will silently degrade.

Rule 2: Assemble Before Baking

Passing a base_id to /pizza/bake returns a 400 error. You must assemble first.

Reusing Session IDs Correctly

Do Not: Mix Unrelated Workflows in One Session

Do Not: Change Session ID Mid-Workflow

Retry Logic

For production use, add retry logic for transient errors:

Best Practices Summary

  1. Always handle errors -- check status codes or use raise_for_status()

  2. Check quality fields -- catch pipeline issues before they cascade

  3. Follow pipeline order -- slice before simmer, assemble before bake

  4. One session per workflow -- do not mix unrelated operations

  5. Keep session IDs consistent -- do not change mid-workflow

  6. Add retry logic for production applications

  7. Use a helper function to reduce boilerplate

Next Steps

Last updated

Was this helpful?