> For the complete documentation index, see [llms.txt](https://tomatopy.pizza/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tomatopy.pizza/docs/tutorials/advanced-flavor-profiling.md).

# Advanced Flavor Profiling

This tutorial covers advanced techniques for analyzing and comparing flavor profiles using the PizzaStack taste endpoints.

## Prerequisites

Before starting, make sure you have:

* A PizzaStack API key
* Python with the `requests` library installed
* Some dishes already created in a session (see [Making Your First Sauce](/docs/tutorials/making-your-first-marinara.md))

## Setup

```python
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())
}

def api_post(endpoint, payload):
    """Helper to make API calls."""
    response = requests.post(f"{API_BASE}{endpoint}", headers=HEADERS, json=payload)
    response.raise_for_status()
    return response.json()
```

## Step 1: Create Test Ingredients

Let's create several tomato varieties to compare:

```python
# Acquire different tomato varieties
varieties = [
    {"variety": "San Marzano", "ripeness": 0.9, "weight": 150},
    {"variety": "Roma", "ripeness": 0.85, "weight": 120},
    {"variety": "Cherry", "ripeness": 0.8, "weight": 30}
]

tomatoes = []
for v in varieties:
    tomato = api_post("/tomato/acquire", v)
    tomatoes.append(tomato)
    print(f"Acquired {tomato['variety']} (type: {tomato['type']})")
```

## Step 2: Basic Flavor Analysis

Analyze a single ingredient with comprehensive depth:

```python
# Comprehensive analysis of a San Marzano tomato
profile = api_post("/taste/analyze", {
    "dish_id": tomatoes[0]["id"],
    "depth": "comprehensive",
    "include_aroma": True,
    "include_texture": True
})

print(f"Sweetness: {profile['sweetness']}")
print(f"Acidity:   {profile['acidity']}")
print(f"Umami:     {profile['umami']}")
print(f"Aroma intensity: {profile['aroma']['intensity']}")
print(f"Aroma notes: {profile['aroma']['notes']}")
print(f"Texture score: {profile['texture']['score']}")
print(f"Firmness: {profile['texture']['firmness']}")
```

## Step 3: Compare Tomato Varieties

Use `/taste/compare` to see how different varieties stack up:

```python
# Compare all three varieties
tomato_ids = [t["id"] for t in tomatoes]

comparison = api_post("/taste/compare", {
    "dish_ids": tomato_ids,
    "metrics": ["sweetness", "acidity", "umami", "aroma"]
})

# Print results for each tomato
for result in comparison["results"]:
    print(f"\n{result['id']}:")
    print(f"  Sweetness: {result['sweetness']}")
    print(f"  Acidity:   {result['acidity']}")
    print(f"  Umami:     {result['umami']}")
    print(f"  Aroma:     {result['aroma']}")

# Print rankings
print(f"\nSweetest: {comparison['rankings']['sweetness'][0]}")
print(f"Most acidic: {comparison['rankings']['acidity'][0]}")
print(f"Most umami: {comparison['rankings']['umami'][0]}")
```

## Step 4: Track Flavor Through the Pipeline

Analyze how flavors change from raw tomato to finished sauce:

```python
# Create a sauce from one of the tomatoes
sliced = api_post("/tomato/slice", {
    "tomato_ids": [tomatoes[0]["id"]],
    "method": "dice",
    "size": "medium",
    "consistency": "uniform"
})

sauce = api_post("/cook/simmer", {
    "ingredients": [
        {"id": sliced["id"], "name": "tomato", "amount": 150, "unit": "g"}
    ],
    "temperature": 100,
    "duration": "30m"
})

# Analyze at each stage
raw_profile = api_post("/taste/analyze", {
    "dish_id": tomatoes[0]["id"],
    "depth": "comprehensive",
    "include_aroma": True
})

sauce_profile = api_post("/taste/analyze", {
    "dish_id": sauce["id"],
    "depth": "comprehensive",
    "include_aroma": True
})

print("Raw tomato vs Sauce:")
print(f"  Sweetness: {raw_profile['sweetness']} -> {sauce_profile['sweetness']}")
print(f"  Acidity:   {raw_profile['acidity']} -> {sauce_profile['acidity']}")
print(f"  Umami:     {raw_profile['umami']} -> {sauce_profile['umami']}")
print(f"  Aroma:     {raw_profile['aroma']['intensity']} -> {sauce_profile['aroma']['intensity']}")
```

## Step 5: Compare Raw vs Cooked

Use the compare endpoint to see the changes side by side:

```python
# Direct comparison of raw tomato and sauce
comparison = api_post("/taste/compare", {
    "dish_ids": [tomatoes[0]["id"], sauce["id"]],
    "metrics": ["sweetness", "acidity", "umami"]
})

for result in comparison["results"]:
    print(f"{result['id']}:")
    print(f"  Sweetness: {result['sweetness']}")
    print(f"  Acidity:   {result['acidity']}")
    print(f"  Umami:     {result['umami']}")
```

## Step 6: Analyze a Finished Pizza

Make a complete pizza and analyze it:

```python
# Complete the pizza
base = api_post("/pizza/base", {
    "thickness": "medium",
    "size": "12inch",
    "style": "neapolitan",
    "hydration": 0.65
})

pizza = api_post("/pizza/assemble", {
    "base_id": base["id"],
    "sauce_id": sauce["id"],
    "toppings": [
        {"name": "mozzarella", "amount": 200, "unit": "g"},
        {"name": "basil", "amount": 10, "unit": "leaves"}
    ]
})

baked = api_post("/pizza/bake", {
    "pizza_id": pizza["id"],
    "temperature": 450,
    "duration": "2m"
})

# Full analysis of the finished pizza
pizza_profile = api_post("/taste/analyze", {
    "dish_id": baked["id"],
    "depth": "comprehensive",
    "include_aroma": True,
    "include_texture": True
})

print(f"\n--- Finished Pizza Profile ---")
print(f"Quality score: {baked['quality_score']}")
print(f"Sweetness: {pizza_profile['sweetness']}")
print(f"Acidity:   {pizza_profile['acidity']}")
print(f"Umami:     {pizza_profile['umami']}")
print(f"Aroma:     {pizza_profile['aroma']['intensity']}")
print(f"Texture:   {pizza_profile['texture']['score']}")
```

## Step 7: Compare Multiple Finished Dishes

Compare sauce vs finished pizza to see how baking affects the flavor:

```python
# Compare sauce to baked pizza
comparison = api_post("/taste/compare", {
    "dish_ids": [sauce["id"], baked["id"]],
    "metrics": ["sweetness", "acidity", "umami", "aroma", "texture"]
})

print("\nSauce vs Baked Pizza:")
for result in comparison["results"]:
    print(f"\n{result['id']}:")
    for metric in ["sweetness", "acidity", "umami", "aroma", "texture"]:
        print(f"  {metric}: {result[metric]}")
```

## Best Practices

1. **Use Comprehensive Depth for Final Products**

   For intermediate ingredients, `"basic"` is usually sufficient. Save `"comprehensive"` with aroma and texture for finished dishes.
2. **Compare at the Same Pipeline Stage**

   Comparing a raw tomato to a baked pizza is possible but the results are more meaningful when comparing items at the same stage (e.g., two different sauces).
3. **Check Response Quality Fields**

   ```python
   profile = api_post("/taste/analyze", {
       "dish_id": dish_id,
       "depth": "comprehensive"
   })
   if profile.get("sweetness", 0) < 0.3:
       print("Low sweetness - check ingredient ripeness")
   ```

## Next Steps

* [API Usage Best Practices](/docs/best-practices/code-efficiency.md) - Optimize your API usage
* [Session Management](/docs/best-practices/virtual-kitchen-management.md) - Manage sessions effectively
* [Core API Endpoints](/docs/core-modules.md) - Explore all endpoints


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://tomatopy.pizza/docs/tutorials/advanced-flavor-profiling.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
