Compare USDA Foods
usda_compare_foodsCompare nutrients side-by-side for 2–5 foods. Returns a structured table — one row per nutrient, one column per food — formatted as markdown. Best for "spinach vs kale iron" or "which has more protein?" questions. Omit nutrients[] to use the 12 most common defaults (energy, protein, fat, saturated fat, carbs, fiber, sugars, sodium, potassium, calcium, iron, vitamin C); provide nutrients[] with specific FDC IDs to compare different nutrients. All values are scaled to the same gram basis (default 100g). If one or more FDC IDs are not found, the comparison proceeds with the valid foods — only throws too_few_foods when fewer than 2 IDs return data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| unit | No | Unit for quantity. Default "g". Does not support "serving" (use a fixed gram basis for consistent comparison). | g |
| fdcIds | Yes | FDC IDs to compare — 2 to 5 foods. Use usda_search_foods to discover IDs. | |
| quantity | No | Gram basis for comparison. All values scaled to this amount. Must be positive. Default 100. | |
| nutrients | No | Nutrient IDs to include in the comparison. Defaults to the 12 most common: energy (1008), protein (1003), total fat (1004), saturated fat (1258), carbohydrate (1005), fiber (1079), total sugars (2000), sodium (1093), potassium (1092), calcium (1087), iron (1089), vitamin C (1162). Use usda_list_nutrients to look up other IDs. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| basis | No | The common scaling basis applied to all nutrient values. | |
| error | No | Present when the call failed. Absent on success. | |
| foods | No | The compared foods, in the same order as the values arrays below. | |
| nutrients | No | Nutrient rows — one entry per requested nutrient, with per-food values in the values[] array. | |
| missingData | No | Foods or food+nutrient pairs where data was unavailable. Absent when all data was present. |