# Pizza Creation System

The pizza endpoints handle creating bases, assembling pizzas, and baking them.

## Creating a Base

### POST /v1/pizza/base

Create a pizza base (dough). This is the foundation of your pizza.

```python
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"
}

# Create a Neapolitan-style base
response = requests.post(f"{API_BASE}/pizza/base", headers=HEADERS, json={
    "thickness": "medium",
    "size": "12inch",
    "style": "neapolitan",
    "hydration": 0.65
})
base = response.json()

print(base["id"])         # "bas_pqr678"
print(base["style"])      # "neapolitan"
print(base["thickness"])  # "medium"
```

#### Request Body

| Field       | Type   | Required | Description                                               |
| ----------- | ------ | -------- | --------------------------------------------------------- |
| `thickness` | string | yes      | "thin", "medium", or "thick"                              |
| `size`      | string | yes      | Pizza size (e.g., "10inch", "12inch", "14inch", "18inch") |
| `style`     | string | yes      | "neapolitan", "new\_york", "chicago", "roman"             |
| `hydration` | float  | no       | Dough hydration ratio, 0.0 to 1.0 (default: 0.6)          |

### Different Base Styles

```python
# New York style
response = requests.post(f"{API_BASE}/pizza/base", headers=HEADERS, json={
    "thickness": "thin",
    "size": "18inch",
    "style": "new_york",
    "hydration": 0.63
})
ny_base = response.json()

# Chicago deep dish
response = requests.post(f"{API_BASE}/pizza/base", headers=HEADERS, json={
    "thickness": "thick",
    "size": "10inch",
    "style": "chicago",
    "hydration": 0.55
})
chicago_base = response.json()
```

## Assembling a Pizza

### POST /v1/pizza/assemble

Assemble a pizza by combining a base, sauce, and toppings. This step is required before baking.

```python
# Assemble the pizza
response = requests.post(f"{API_BASE}/pizza/assemble", headers=HEADERS, json={
    "base_id": base["id"],
    "sauce_id": sauce["id"],
    "toppings": [
        {"name": "mozzarella", "amount": 200, "unit": "g"},
        {"name": "basil", "amount": 10, "unit": "leaves"},
        {"name": "pepperoni", "amount": 100, "unit": "g"}
    ]
})
pizza = response.json()

print(pizza["id"])       # "pza_stu901"
print(pizza["style"])    # "neapolitan"
print(pizza["toppings"]) # [{"name": "mozzarella", ...}, ...]
```

#### Request Body

| Field      | Type   | Required | Description                                          |
| ---------- | ------ | -------- | ---------------------------------------------------- |
| `base_id`  | string | yes      | ID from `/pizza/base`                                |
| `sauce_id` | string | yes      | ID from `/cook/simmer` or `/cook/roast`              |
| `toppings` | array  | yes      | List of toppings, each with `name`, `amount`, `unit` |

## Assembly Required

{% hint style="warning" %}
**You must assemble before baking.** The `/pizza/bake` endpoint requires a `pizza_id` returned by `/pizza/assemble`. Passing a `base_id` directly to `/pizza/bake` will return a **400 error**.
{% endhint %}

### Correct Flow: Assemble Then Bake

```python
# Step 1: Create a base
response = requests.post(f"{API_BASE}/pizza/base", headers=HEADERS, json={
    "thickness": "medium",
    "size": "12inch",
    "style": "neapolitan",
    "hydration": 0.65
})
base = response.json()

# Step 2: Assemble the pizza (REQUIRED before baking)
response = requests.post(f"{API_BASE}/pizza/assemble", headers=HEADERS, json={
    "base_id": base["id"],
    "sauce_id": sauce["id"],
    "toppings": [
        {"name": "mozzarella", "amount": 200, "unit": "g"}
    ]
})
pizza = response.json()

# Step 3: Bake using the pizza_id from assemble
response = requests.post(f"{API_BASE}/pizza/bake", headers=HEADERS, json={
    "pizza_id": pizza["id"],
    "temperature": 450,
    "duration": "2m"
})
baked = response.json()
print(baked["quality_score"])  # 0.91
```

### Incorrect Flow: Baking Without Assembly

```python
# WRONG: Trying to bake a base_id directly
response = requests.post(f"{API_BASE}/pizza/bake", headers=HEADERS, json={
    "pizza_id": base["id"],  # This is a base_id, not a pizza_id!
    "temperature": 450,
    "duration": "2m"
})
print(response.status_code)  # 400
print(response.json())       # {"error": "Invalid pizza_id. Use /pizza/assemble first."}
```

## Baking a Pizza

### POST /v1/pizza/bake

Bake an assembled pizza. Returns the finished pizza with a quality score.

```python
# Bake the pizza
response = requests.post(f"{API_BASE}/pizza/bake", headers=HEADERS, json={
    "pizza_id": pizza["id"],
    "temperature": 450,
    "duration": "2m"
})
baked = response.json()

print(baked["id"])             # "bkd_vwx234"
print(baked["quality_score"])  # 0.92
print(baked["crust"])          # "crispy"
print(baked["doneness"])       # "perfect"
```

#### Request Body

| Field         | Type    | Required | Description                               |
| ------------- | ------- | -------- | ----------------------------------------- |
| `pizza_id`    | string  | yes      | ID from `/pizza/assemble`                 |
| `temperature` | integer | yes      | Baking temperature in Celsius             |
| `duration`    | string  | yes      | Baking duration (e.g., "2m", "90s", "3m") |

## The Full Assembly Flow

Here is the complete pizza creation pipeline in one script:

```python
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"
}

# 1. Acquire tomato
tomato = requests.post(f"{API_BASE}/tomato/acquire", headers=HEADERS, json={
    "variety": "San Marzano", "ripeness": 0.9, "weight": 400
}).json()

# 2. Slice it
sliced = requests.post(f"{API_BASE}/tomato/slice", headers=HEADERS, json={
    "tomato_ids": [tomato["id"]], "method": "dice", "size": "medium", "consistency": "uniform"
}).json()

# 3. Simmer into sauce
sauce = requests.post(f"{API_BASE}/cook/simmer", headers=HEADERS, json={
    "ingredients": [{"id": sliced["id"], "name": "tomato", "amount": 400, "unit": "g"}],
    "temperature": 100, "duration": "30m"
}).json()

# 4. Create base
base = requests.post(f"{API_BASE}/pizza/base", headers=HEADERS, json={
    "thickness": "medium", "size": "12inch", "style": "neapolitan", "hydration": 0.65
}).json()

# 5. Assemble
pizza = requests.post(f"{API_BASE}/pizza/assemble", headers=HEADERS, json={
    "base_id": base["id"], "sauce_id": sauce["id"],
    "toppings": [{"name": "mozzarella", "amount": 200, "unit": "g"}]
}).json()

# 6. Bake
baked = requests.post(f"{API_BASE}/pizza/bake", headers=HEADERS, json={
    "pizza_id": pizza["id"], "temperature": 450, "duration": "2m"
}).json()

print(f"Pizza quality: {baked['quality_score']}")
```

## Error Handling

```python
# Handle assembly errors
response = requests.post(f"{API_BASE}/pizza/assemble", headers=HEADERS, json={
    "base_id": "invalid_id",
    "sauce_id": sauce["id"],
    "toppings": [{"name": "mozzarella", "amount": 200, "unit": "g"}]
})

if response.status_code == 400:
    error = response.json()
    print(f"Error: {error['message']}")  # "Invalid base_id"
```

## Best Practices

1. **Always Assemble Before Baking**

   The `/pizza/bake` endpoint only accepts `pizza_id` values from `/pizza/assemble`. Passing a `base_id` will return a 400 error.
2. **Use Quality Sauce**

   The sauce quality directly affects the final pizza score. Make sure you sliced your tomatoes before simmering.
3. **Check the Quality Score**

   ```python
   baked = response.json()
   if baked["quality_score"] < 0.7:
       print("Consider improving ingredient quality or adjusting bake parameters")
   ```

## Endpoint Reference

| Endpoint             | Method | Description                                     |
| -------------------- | ------ | ----------------------------------------------- |
| `/v1/pizza/base`     | POST   | Create a pizza base                             |
| `/v1/pizza/assemble` | POST   | Assemble a pizza from base, sauce, and toppings |
| `/v1/pizza/bake`     | POST   | Bake an assembled pizza                         |

## Next Steps

* [Taste Endpoints](/docs/core-modules/taste-testing-module.md) - Analyze your baked pizza
* [Session Management](/docs/core-modules/kitchen-hardware-interface.md) - Debug and track your session
* [Cooking Endpoints](/docs/core-modules/cooking-operations.md) - Go back to sauce preparation


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tomatopy.pizza/docs/core-modules/pizza-creation-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
