Nutrition API

The Nutrition API extracts nutrition information from text using natural language processing. From food blogs to menus to recipes, it can read any text and calculate the corresponding nutrition data.

An intelligent feature of this API is custom portioning: if your text specifies quantities of individual food items or ingredients, the algorithm will automatically scale the nutrition data in the result accordingly.

/v1/nutrition GET

https://api.api-ninjas.com/v1/nutrition

Returns a list of nutrition information extracted from given text. Nutrition data for each food item is scaled to 100g unless a quantity is specified within the query parameter.


Parameters

  • query  required

    Query text to extract nutrition information.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Returns

  • calories premium

    Nutritional energy in calories.

  • serving_size_g premium

    Serving size in grams.

  • fat_total_g

    Total combined fat (including saturated and trans fats) in grams.

  • fat_saturated_g

    Saturated fat in grams.

  • protein_g premium

    Protein in grams.

  • sodium_mg

    Sodium in milligrams.

  • potassium_mg

    Potassium in milligrams.

  • cholesterol_mg

    Cholesterol in milligrams.

  • carbohydrates_total_g

    Total carbohydrates (including fiber and sugar) in grams.

  • fiber_g

    Fiber in grams.

  • sugar_g

    Sugar in grams.

Sample Request Live Demo!

query
https://api.api-ninjas.com/v1/nutrition?query=1lb brisket and fries

Sample Response

JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [ { "name": "brisket", "calories": 1312.3, "serving_size_g": 453.592, "fat_total_g": 82.9, "fat_saturated_g": 33.2, "protein_g": 132, "sodium_mg": 217, "potassium_mg": 781, "cholesterol_mg": 487, "carbohydrates_total_g": 0, "fiber_g": 0, "sugar_g": 0 }, { "name": "fries", "calories": 317.7, "serving_size_g": 100, "fat_total_g": 14.8, "fat_saturated_g": 2.3, "protein_g": 3.4, "sodium_mg": 212, "potassium_mg": 124, "cholesterol_mg": 0, "carbohydrates_total_g": 41.1, "fiber_g": 3.8, "sugar_g": 0.3 } ]

Code Examples

1 2 3 4 5 6 7 8 import requests query = '1lb brisket and fries' api_url = 'https://api.api-ninjas.com/v1/nutrition?query={}'.format(query) response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'}) if response.status_code == requests.codes.ok: print(response.text) else: print("Error:", response.status_code, response.text)

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.