USDA FoodData Central API
US government database of detailed food and nutrient data.
What it does
USDA FoodData Central (FDC) is the US government’s authoritative food-composition database: Foundation Foods, SR Legacy, branded products (label data for 400k+ items) and the FNDDS survey database. Search foods and retrieve complete nutrient profiles with citable provenance.
Base URL
Authentication
Get a free api.data.gov key and pass it as ?api_key=YOUR_KEY. DEMO_KEY works for a quick test at a very low limit.
Code examples
curl -s "https://api.nal.usda.gov/fdc/v1/foods/search?query=cheddar%20cheese&pageSize=3&api_key=$FDC_KEY"
import requests
r = requests.get("https://api.nal.usda.gov/fdc/v1/foods/search",
params={"query": "banana raw", "dataType": "Foundation,SR Legacy",
"pageSize": 1, "api_key": KEY}, timeout=10)
food = r.json()["foods"][0]
for n in food["foodNutrients"]:
if n["nutrientName"] in ("Energy", "Protein", "Potassium, K"):
print(n["nutrientName"], n["value"], n["unitName"])Rate limits & quotas
api.data.gov standard limit: 1,000 requests/hour per key (per IP for DEMO_KEY, which is far lower). Rate-limit headers (X-RateLimit-Remaining) are returned; over the limit is HTTP 429. Search pageSize max 200; use dataType to scope results.
Key response fields
| foods[].fdcId | Stable identifier — use with /food/{fdcId} |
| foods[].description / brandOwner | Food name and (branded) manufacturer |
| foods[].dataType | Foundation, SR Legacy, Branded, Survey (FNDDS) |
| foods[].foodNutrients[].nutrientName / value / unitName | Each nutrient per 100 g |
| totalHits / currentPage / totalPages | Pagination |
Common errors
| 403 API_KEY_INVALID / OVER_RATE_LIMIT | Bad key, or hourly cap hit (tiny for DEMO_KEY). |
| 400 | Missing query, or an invalid dataType value. |
| 404 | Unknown fdcId on the detail endpoint. |
When to use it (and alternatives)
The reference source when you need trustworthy, citable nutrient data — nutrition science, labelling checks, public-health tools. For natural-language food logging, Nutritionix is friendlier; for recipes, Spoonacular.
FAQ
Which dataType should I search?
For whole foods and cooking, prefer Foundation and SR Legacy (lab-analysed, per 100 g). Branded is label-declared and huge but noisier. Survey (FNDDS) is for dietary intake studies.
Are nutrient values per serving or per 100 g?
Per 100 g / 100 mL in Foundation and SR Legacy. Branded items also include servingSize and label-serving nutrients. Convert explicitly.
Is DEMO_KEY enough?
Only for a first look — it is rate-limited to a handful of requests. A free api.data.gov key (1,000/hour) takes a minute to get.
New to APIs?
Short guides for working with this API — and any other.