# Taste Testing Module

The taste endpoints let you analyze and compare finished dishes and ingredients.

## Analyzing a Dish

### POST /v1/taste/analyze

Analyze the flavor profile of any dish or ingredient in your session.

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

# Basic analysis
response = requests.post(f"{API_BASE}/taste/analyze", headers=HEADERS, json={
    "dish_id": "bkd_vwx234",
    "depth": "basic"
})
profile = response.json()

print(f"Sweetness: {profile['sweetness']}")  # 0.3
print(f"Acidity: {profile['acidity']}")      # 0.7
print(f"Umami: {profile['umami']}")          # 0.8
```

### Comprehensive Analysis

Include aroma and texture data for a fuller picture:

```python
# Comprehensive analysis with aroma and texture
response = requests.post(f"{API_BASE}/taste/analyze", headers=HEADERS, json={
    "dish_id": "bkd_vwx234",
    "depth": "comprehensive",
    "include_aroma": True,
    "include_texture": True
})
profile = response.json()

# Basic taste metrics
print(f"Sweetness: {profile['sweetness']}")
print(f"Acidity: {profile['acidity']}")
print(f"Umami: {profile['umami']}")

# Aroma metrics
print(f"Aroma intensity: {profile['aroma']['intensity']}")
print(f"Aroma notes: {profile['aroma']['notes']}")

# Texture metrics
print(f"Texture score: {profile['texture']['score']}")
print(f"Firmness: {profile['texture']['firmness']}")
```

#### Request Body

| Field             | Type    | Required | Description                                   |
| ----------------- | ------- | -------- | --------------------------------------------- |
| `dish_id`         | string  | yes      | ID of any dish or ingredient in the session   |
| `depth`           | string  | no       | "basic" or "comprehensive" (default: "basic") |
| `include_aroma`   | boolean | no       | Include aroma analysis (default: false)       |
| `include_texture` | boolean | no       | Include texture analysis (default: false)     |

## Comparing Dishes

### POST /v1/taste/compare

Compare multiple dishes or ingredients side by side on specific metrics.

```python
# Compare three sauces
response = requests.post(f"{API_BASE}/taste/compare", headers=HEADERS, json={
    "dish_ids": ["sce_001", "sce_002", "sce_003"],
    "metrics": ["sweetness", "acidity", "umami"]
})
comparison = response.json()

# Access comparison results
for dish in comparison["results"]:
    print(f"Dish {dish['id']}:")
    print(f"  Sweetness: {dish['sweetness']}")
    print(f"  Acidity: {dish['acidity']}")
    print(f"  Umami: {dish['umami']}")

# Rankings
print(f"Sweetest: {comparison['rankings']['sweetness'][0]}")
print(f"Most acidic: {comparison['rankings']['acidity'][0]}")
```

#### Request Body

| Field      | Type             | Required | Description                                                                    |
| ---------- | ---------------- | -------- | ------------------------------------------------------------------------------ |
| `dish_ids` | array of strings | yes      | IDs of dishes to compare (minimum 2)                                           |
| `metrics`  | array of strings | yes      | Metrics to compare (e.g., "sweetness", "acidity", "umami", "aroma", "texture") |

## Analyzing Different Stages

You can analyze ingredients at any stage of the pipeline -- raw tomatoes, sliced tomatoes, sauces, or finished pizzas:

```python
# Analyze a raw tomato
response = requests.post(f"{API_BASE}/taste/analyze", headers=HEADERS, json={
    "dish_id": tomato["id"],
    "depth": "comprehensive",
    "include_aroma": True
})
raw_profile = response.json()

# Analyze the sauce made from that tomato
response = requests.post(f"{API_BASE}/taste/analyze", headers=HEADERS, json={
    "dish_id": sauce["id"],
    "depth": "comprehensive",
    "include_aroma": True
})
sauce_profile = response.json()

# Compare raw vs cooked
response = requests.post(f"{API_BASE}/taste/compare", headers=HEADERS, json={
    "dish_ids": [tomato["id"], sauce["id"]],
    "metrics": ["sweetness", "acidity", "umami"]
})
comparison = response.json()
print("Raw vs Cooked comparison:", comparison)
```

## Error Handling

```python
# Handle invalid dish ID
response = requests.post(f"{API_BASE}/taste/analyze", headers=HEADERS, json={
    "dish_id": "invalid_id",
    "depth": "basic"
})

if response.status_code == 400:
    error = response.json()
    print(f"Error: {error['message']}")  # "Dish not found in session"

# Handle empty comparison list
response = requests.post(f"{API_BASE}/taste/compare", headers=HEADERS, json={
    "dish_ids": [],
    "metrics": ["sweetness"]
})

if response.status_code == 400:
    error = response.json()
    print(f"Error: {error['message']}")  # "At least 2 dish IDs required"
```

## Best Practices

1. **Choose the Right Depth**

   Use `"basic"` for quick checks and `"comprehensive"` when you need full details. Comprehensive analysis includes more data but takes longer.
2. **Compare at the Same Stage**

   For meaningful comparisons, compare dishes at the same pipeline stage (e.g., sauce vs sauce, not sauce vs raw tomato).
3. **Use Aroma and Texture for Final Products**

   ```python
   # Best for finished pizzas
   response = requests.post(f"{API_BASE}/taste/analyze", headers=HEADERS, json={
       "dish_id": baked_pizza["id"],
       "depth": "comprehensive",
       "include_aroma": True,
       "include_texture": True
   })
   ```

## Endpoint Reference

| Endpoint            | Method | Description                                 |
| ------------------- | ------ | ------------------------------------------- |
| `/v1/taste/analyze` | POST   | Analyze flavor profile of a dish            |
| `/v1/taste/compare` | POST   | Compare multiple dishes on specific metrics |

## Next Steps

* [Session Management](/docs/core-modules/kitchen-hardware-interface.md) - Debug and track your session
* [Tutorials](/docs/tutorials/advanced-flavor-profiling.md) - Learn advanced flavor profiling techniques
* [Best Practices](/docs/best-practices.md) - API usage tips


---

# 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/taste-testing-module.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.
