API Documentation

To use the CalorieNinjas API, you need to sign up for a free account and get an API key.

While there is currently no hard limit on API requests, applications sending large number of requests per day will be throttled. If you need larger API request volumes or want to inquire about other commercial options, please contact us.

/v1/nutrition

HTTP GET

Get a detailed list of nutrition information for each item from an input text query.

Parameters

query (required) - a string containing food or drink items. If you wish to calculate a specific quantity, you may prefix a quantity before an item. For example, 3 tomatoes or 1lb beef brisket. If no quantity is specified, the default quantity is 100 grams. Queries cannot exceed 1500 characters.

Headers

X-Api-Key (required) - API Key associated with your account.

Sample Request URL

Live Demo!

https://api.calorieninjas.com/v1/nutrition?query=   
Sample Response
{
  "items": [
    {
      "sugar_g": 13.3,
      "fiber_g": 4,
      "serving_size_g": 283.495,
      "sodium_mg": 8,
      "name": "onion",
      "potassium_mg": 99,
      "fat_saturated_g": 0.1,
      "fat_total_g": 0.5,
      "calories": 126.7,
      "cholesterol_mg": 0,
      "protein_g": 3.9,
      "carbohydrates_total_g": 28.6
    },
    {
      "sugar_g": 2.6,
      "fiber_g": 1.2,
      "serving_size_g": 100,
      "sodium_mg": 4,
      "name": "tomato",
      "potassium_mg": 23,
      "fat_saturated_g": 0,
      "fat_total_g": 0.2,
      "calories": 18.2,
      "cholesterol_mg": 0,
      "protein_g": 0.9,
      "carbohydrates_total_g": 3.9
    }
  ]
}
import requests

api_url = 'https://api.calorieninjas.com/v1/nutrition?query='
query = '3lb carrots and a chicken sandwich'
response = requests.get(api_url + query, 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)
var query = '3lb carrots and a chicken sandwich'
$.ajax({
    method: 'GET',
    url: 'https://api.calorieninjas.com/v1/nutrition?query=' + query,
    headers: { 'X-Api-Key': 'YOUR_API_KEY'},
    contentType: 'application/json',
    success: function(result) {
        console.log(result);
    },
    error: function ajaxError(jqXHR) {
        console.error('Error: ', jqXHR.responseText);
    }
});
const request = require('request');
var query = '3lb carrots and a chicken sandwich';
request.get({
  url: 'https://api.calorieninjas.com/v1/nutrition?query='+query,
  headers: {
    'X-Api-Key': 'YOUR_API_KEY'
  },
}, function(error, response, body) {
  if(error) return console.error('Request failed:', error);
  else if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
  else console.log(body)
});
String query = '3lb carrots and a chicken sandwich';
Response response = Request.Get("https://api.calorieninjas.com/v1/nutrition?query="+query)
.addHeader("X-Api-Key", "YOUR_API_KEY")
.execute();
let query = "3lb carrots and a chicken sandwich".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: "https://api.calorieninjas.com/v1/nutrition?query="+query!)!
var request = URLRequest(url: url)
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-Api-Key")
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
    guard let data = data else { return }
    print(String(data: data, encoding: .utf8)!)
}
task.resume()
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *query = @"https://api.calorieninjas.com/v1/nutrition?query=3lb carrots and a chicken sandwich";
NSString* encodedQuery = [query stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:encodedQuery]];
[request setValue:@"YOUR_API_KEY" forHTTPHeaderField:@"X-Api-Key"];
NSError *error = nil;
NSHTTPURLResponse *responseCode = nil;

NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
NSLog([[NSString alloc] initWithData:oResponseData encoding:NSUTF8StringEncoding]);
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.

/v1/imagetextnutrition

HTTP POST

Get a detailed list of nutrition information scanned from an image containing food/beverage text. Example use cases include menus, recipes, and food journal entries.

Headers

X-Api-Key (required) - API Key associated with your account.

Sample Request URL

Live Demo!

https://calorieninjas.com/v1/imagetextnutrition
Sample Response
Code Example
import requests

api_url = 'https://api.calorieninjas.com/v1/imagetextnutrition'
image_file_descriptor = open('yourimage.jpeg', 'rb')
files = {'media': image_file_descriptor}
r = requests.post(api_url, files=files)
print r.json()
var formData = new FormData();
formData.append('file', $('#imagefile')[0].files[0]);
$.ajax({
    method: 'POST',
    url: 'https://api.calorieninjas.com/v1/imagetextnutrition',
    data: formData,
    enctype: 'multipart/form-data',
    processData: false,
    contentType: false, 
    success: function(result) {
        console.log(result);
    },
    error: function ajaxError(jqXHR, textStatus, errorThrown) {
        alert(jqXHR.responseText);
    }
});
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.