Adding Nutrition Data to Your App or AI Agent: A Nutrition API Guide

If you're building a meal-planning app, a recipe site, a food-logging feature, or an AI agent that reasons about food, you eventually hit the same wall: you need accurate nutrition numbers, and you don't want them to be a language model's best guess. This guide shows how to pull real, USDA-cited nutrition data into your app or agent with a single HTTP call, and how the same capability is exposed to LLMs over MCP.
- A nutrition API returns deterministic, USDA-cited values instead of a language model's best guess at a food's nutrient content.
- The core endpoint, POST /api/v1/analyze, takes free-text ingredients and a serving count and returns per-serving nutrition with FDA rounding already applied.
- A public sandbox key (mly_test_sandbox) lets you try the shape of the API with no signup.
- The same four capabilities are exposed to LLM agents through a hosted MCP server, so an agent can compute nutrition mid-task without custom glue code.
- /openapi.json and /llms.txt make the API self-describing for both human developers and agents landing on the site cold.
Why not just ask a model?
An LLM will happily tell you a cup of flour has 'about 455 calories', and it will often be roughly right. But 'roughly right' is unusable for a Nutrition Facts label, a diabetic meal plan, or anything a user will trust. A nutrition API gives you deterministic values computed from a fixed database (USDA FoodData Central), with a citation back to the exact source record — so the number is verifiable, not vibes. That verifiability is exactly what makes it a good tool for an agent to call rather than a fact to hallucinate.
The core call: analyze a recipe
The main endpoint takes a list of free-text ingredients and a serving count, and returns per-serving nutrition. You can try it immediately with the public sandbox key — no signup:
curl -X POST https://mealary.com/api/v1/analyze \
-H "Authorization: Bearer mly_test_sandbox" \
-H "content-type: application/json" \
-d '{
"ingredients": [
"2 cups all-purpose flour",
"1 cup granulated sugar",
"2 large eggs",
"1/2 cup unsalted butter"
],
"servings": 12
}'The response gives you the parsed ingredients (each matched to a USDA record you can inspect), the per-serving nutrition facts with FDA rounding already applied, the % Daily Values, a detected-allergens list, and the source citations:
{
"servings": 12,
"per_serving": {
"calories": 220,
"total_fat_g": 9,
"saturated_fat_g": 5,
"sodium_mg": 15,
"total_carbohydrate_g": 33,
"total_sugars_g": 17,
"added_sugars_g": 17,
"protein_g": 4
},
"daily_values": { "total_fat": 12, "sodium": 1, "added_sugars": 34 },
"allergens": ["Wheat", "Eggs", "Milk"],
"sources": [
{ "ingredient": "all-purpose flour", "fdc_id": 789890 }
]
}Authentication and limits
Auth is a bearer token in the Authorization header. The sandbox key mly_test_sandbox is shared, rate-limited, and meant for trying the shape of the API. For production you generate your own key from the dashboard; free-tier keys allow 100 calls/month and Pro keys allow 10,000/month with metered overage. Errors come back as structured JSON with a stable code field so your client can branch on them, and the API honors an Idempotency-Key header on POSTs so a retried request never double-counts against your quota.
The other endpoints
| Endpoint | Input | Returns |
|---|---|---|
| POST /api/v1/analyze | Ingredients list + servings | Per-serving nutrition, %DV, allergens, USDA citations |
| POST /api/v1/label | Ingredients list + servings | Rendered FDA Nutrition Facts label (PDF/PNG/SVG on Pro) |
| GET /api/v1/foods?q= | Free-text food name | Matching USDA foods with fdc_id |
| GET /api/v1/foods/{fdc_id} | A USDA fdc_id | Full nutrient profile for that food record |
Mealary API endpoints at a glance
- POST /api/v1/analyze — the recipe analysis above.
- POST /api/v1/label — same input, but returns a rendered FDA Nutrition Facts label (watermarked on free, clean PDF/PNG/SVG on Pro).
- GET /api/v1/foods?q=cheddar — search USDA foods by name, returning fdc_id and description.
- GET /api/v1/foods/{fdc_id} — fetch the full nutrient profile for one USDA food record.
A small meal-planning startup we talked to had been maintaining their own spreadsheet of about 200 common ingredients, hand-updated whenever someone noticed a number looked off. Swapping that for /api/v1/analyze took one engineer roughly an afternoon — parse the existing recipe format, map it to the ingredients array, and drop the spreadsheet lookup entirely. The unexpected win wasn't speed, it was the citation: their support team could now point a skeptical user straight at the USDA fdc_id behind a number instead of saying 'trust us'.
Using it from an AI agent (MCP)
The same capability is exposed to LLM agents through a hosted Model Context Protocol (MCP) server, so a Claude- or GPT-based agent can compute nutrition mid-task without you writing glue code. The server advertises four tools that map onto the endpoints above:
- analyze_recipe — ingredients + servings → per-serving nutrition facts and allergens.
- generate_label — the same input → a compliant Nutrition Facts label.
- search_foods — free-text query → matching USDA foods.
- get_food — an fdc_id → the full nutrient breakdown for that food.
Point your MCP-capable client at the Mealary MCP endpoint and the tools appear automatically. Because each result carries its USDA citation, the agent can show its work — the trust surface an LLM otherwise can't provide on its own.
“MCP has grown from an emerging idea to table stakes, with over 97 million monthly SDK downloads and more than 10,000 active MCP servers.”
That scale is exactly why exposing nutrition data as an MCP tool rather than only a REST endpoint matters now. An agent ecosystem that large means a meaningful share of the requests your API sees in production may never come from a human clicking a button — they'll come from an agent mid-task, deciding on its own that it needs a nutrition lookup to answer a user's question accurately.
Discoverability: /llms.txt and OpenAPI
Two files make Mealary easy for both machines and humans to onboard against. The OpenAPI spec at /openapi.json fully describes every endpoint, so you can generate a typed client in your language of choice. And /llms.txt is a compact, LLM-friendly description of what Mealary does and how to call it, so an agent that lands on the site can figure out the API without scraping marketing pages. Between the sandbox key, the MCP server, and these two files, wiring nutrition into an app or agent is usually a single afternoon.
The short version: don't ask a model to invent nutrition numbers when it can call a tool that computes them from USDA data and hands back a citation. Start with the curl above, swap in your own key, and you're done. If you want to see how this compares to other nutrition APIs on the market before committing, our Nutritionix vs. Edamam vs. Mealary API comparison walks through pricing, rate limits and MCP support side by side. And if you're calculating the underlying nutrition numbers manually before wiring up the API, our recipe nutrition calculation guide covers the exact method this endpoint automates.
Yes, for low volume — free-tier keys include 100 calls per month, and the shared mly_test_sandbox key lets you try every endpoint with no signup at all. Pro keys allow 10,000 calls/month with metered overage.
The API returns the ingredient as unresolved with a warning rather than guessing or silently substituting a similar food, so your app can flag it for a manual check instead of shipping a wrong number.
Yes — POST requests honor an Idempotency-Key header, so a retried request after a timeout or network error never double-counts against your monthly quota.
Absolutely — the REST endpoints (/api/v1/analyze, /api/v1/label, /api/v1/foods) work as a standard HTTP API for any app. MCP is an additional interface for agent clients, not a requirement.
Send your API key as a bearer token in the Authorization header. Generate a production key from your Mealary dashboard, or use the public mly_test_sandbox key while prototyping.
Stop calculating nutrition by hand
Mealary turns any recipe into per-serving nutrition and a print-ready FDA Nutrition Facts label — computed from USDA FoodData Central, with the rounding and %DV done for you and every value cited to its source.