Pantry & kitchen
What you can build
“What can I cook tonight?”, missing-ingredient prompts, and cook flows that keep pantry inventory honest after preparation.
1. Establish user context
Partition pantry per end user with external_user_id / X-External-User-ID. External user context
client = FoodAPI(
api_key="foodapi_sb_…",
external_user_id="user_42",
)2. Add pantry inventory
Normalize grocery text to get an ingredient_id, then add it to the pantry.
normalized = client.ingredients.normalize("2 cups rice")
item = client.pantry.add(
ingredient_id=normalized.ingredient_id,
quantity=2,
unit="cup",
)
pantry = client.pantry.list()
print(pantry.total, [i.id for i in pantry.items])3. Select a recipe
page = client.recipes.list(search="stir fry", limit=5) recipe_id = page.items[0].id
4. Evaluate feasibility
Use unified reasoning with goal FEASIBILITY and current pantry item ids.
result = client.reason(
recipe_id=recipe_id,
goal="FEASIBILITY",
pantry_item_ids=[i.id for i in pantry.items],
max_missing_ingredients=3,
allow_substitutions=True,
)
print(result.feasibility_score, result.missing_ingredients)5. Inspect the result
{
"feasibility_score": 0.82,
"missing_ingredients": ["…"],
"pantry_matches": ["…"],
"confidence_score": 0.9
}Use missing_ingredients to drive shopping UI. Shopping guide
6. Record a cook (optional deductions)
After the user cooks, create a prepared-recipe event. The Python SDK exposes prepared_recipes.create. TypeScript can call the same REST endpoint (no dedicated resource yet).
from datetime import datetime, timezone
event = client.prepared_recipes.create(
recipe_id=recipe_id,
prepared_at=datetime.now(timezone.utc),
servings_prepared="4",
idempotency_key="app:cook:unique-key-1",
preparation_type="COOKED",
apply_pantry_deductions=True,
)
print(event.pantry_deduction)Deduction status includes values such as APPLIED, PARTIAL, and NOT_APPLIED. Re-list the pantry afterward to show updated quantities. Use a stable idempotency_key so retries do not double-deduct.
Next
What are you building?