### Getting Started Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/analysis/index.html Information on how to get started with the API, including obtaining an API key. ```APIDOC ## Get Started [Request an API Key](https://buy.stripe.com/eVa02xepj4Tyfh65kF) ``` -------------------------------- ### Analysis API Sample Requests Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/analysis/index.html Examples of how to perform GET and PUT requests to the Analysis API. ```bash curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis?key=YOUR_API_KEY&description=YOUR_DESCRIPTION&image_url=YOUR_IMAGE_URL' ``` ```python import requests response = requests.put( 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis', json={ 'key': api_key, 'image': b64image_data }) ``` -------------------------------- ### Usage API Request Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/usage/index.html Retrieves API usage information using a GET request with an API key. ```bash curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/usage?key=YOUR_API_KEY' ``` -------------------------------- ### Example Successful Usage API Response Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt A successful response from the Usage API, showing the current usage against the defined limit. ```json { "code": 200, "data": { "limit": 100, "usage": 5 } } ``` -------------------------------- ### Nutrition Label API Request Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/nutrition-label/index.html Example cURL request to the nutrition label endpoint using an API key and image URLs. ```bash curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition-label?key=YOUR_API_KEY&image_url=https://www.fda.gov/files/nfl-howtounderstand-honey.png&product_image_url=http://tiny.cc/fphszz' ``` -------------------------------- ### Example Food Not Found Response Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt This JSON object indicates that a requested food item could not be found by the API. ```json { "code": 200, "success": false, "data": null } ``` -------------------------------- ### Example Successful Food Analysis Response Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt This JSON object represents a successful response from the food analysis endpoint, including detailed nutritional information. ```json { "code": 200, "success": true, "data": { "name": "Pure Honey", "alt_units": [ {"unit": "serving", "weight_in_grams": 21} ], "selected_portion": {"quantity": 1, "unit": "serving"}, "selected_portion_nutrition": { "mass_g": 21, "calories_kcal": 60, "carb_g": 17, "fat_g": 0, "protein_g": 0, "sugar_g": 17, "fiber_g": 0, "sodium_mg": 0, "vitamin_c_mg": 0, "vitamin_d_iu": 0, "calcium_mg": 0, "iron_mg": 0, "potassium_mg": 0, "cholesterol_mg": 0, "saturated_fats_g": 0, "trans_fats_g": 0 }, "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 285.7143, "carb_g": 80.9524, "fat_g": 0, "protein_g": 0, "sugar_g": 80.9524 } }, "product_image_uri": "http://example.com/honey-front.jpg" } ``` -------------------------------- ### GET /nutrition Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/nutrition/index.html Retrieves detailed nutritional information for a specified food item. ```APIDOC ## GET /nutrition ### Description Retrieves nutritional data for a food item. The API returns macro and micronutrients, portion information, and alternative units. ### Method GET ### Response #### Success Response (200) - **code** (integer) - Status code - **success** (boolean) - Indicates if the request was successful - **data** (object) - Contains nutritional details including mass, calories, carbs, fats, proteins, vitamins, minerals, and portion data. #### Response Example { "code": 200, "success": true, "data": { "name": "apple", "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 61, "carb_g": 14.8, "fat_g": 0.15, "protein_g": 0.17 }, "alt_units": [ {"unit": "cup", "weight_in_grams": 125}, {"unit": "whole", "weight_in_grams": 200} ], "default_portion": { "quantity": 1, "unit": "whole" } } } ``` -------------------------------- ### Example Successful Food Lookup Response Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt This JSON object represents a successful lookup for a food item, including its nutritional data per 100g and alternative units. ```json { "code": 200, "success": true, "data": { "name": "apple", "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 61, "carb_g": 14.8, "fat_g": 0.15, "protein_g": 0.17, "fiber_g": 2.1, "sugar_g": 12.1, "vitamin_a_mcg": 3, "vitamin_c_mg": 4.6, "calcium_mg": 5, "iron_mg": 0.03, "potassium_mg": 104, "sodium_mg": 0, "saturated_fats_g": 0, "cholesterol_mg": 0, "omega_3_fatty_acids_g": 0.051, "percent_fruit": 1, "percent_vegetable": 0, "healthy_fats": false, "lean_protein": false, "ultra_processed": false, "is_beverage": false, "added_sugars_g": 0, "source_urls": ["https://fdc.nal.usda.gov/fdc-app.html#/food-details/2344711/nutrients"] }, "alt_units": [ {"unit": "cup", "weight_in_grams": 125}, {"unit": "g", "weight_in_grams": 1}, {"unit": "whole", "weight_in_grams": 200}, {"unit": "serving", "weight_in_grams": 200} ], "default_portion": {"quantity": 1, "unit": "whole"}, "selected_portion": {"quantity": 1, "unit": "whole"}, "selected_portion_nutrition": { "mass_g": 200, "calories_kcal": 122, "carb_g": 29.6, "fat_g": 0.3, "protein_g": 0.34 } } } ``` -------------------------------- ### Example Unparseable Label Response Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt This JSON object indicates that the API was unable to parse the provided food label. ```json { "code": 200, "success": false, "text": "Unable to Parse Label" } ``` -------------------------------- ### GET /upc Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/upc/index.html Retrieves nutritional data for a specific food item identified by its UPC barcode. ```APIDOC ## GET /upc ### Description The UPC API allows users to look up nutritional data from a UPC. ### Method GET ### Endpoint https://us-central1-snapcalorieb2bapi.cloudfunctions.net/upc ### Parameters #### Query Parameters - **key** (string) - Required - The API key for authentication. - **upc** (string) - Required - The barcode number. ### Request Example curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/upc?key=YOUR_API_KEY&upc=123456789' ### Response #### Success Response (200) - **code** (integer) - Status code. - **success** (boolean) - Indicates if the request was successful. - **data** (object) - Contains nutritional information, alternative units, and portion details. #### Response Example { "code": 200, "success": true, "data": { "name": "Packaged Apple Slices", "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 61, "carb_g": 14.8, "fat_g": 0.15, "protein_g": 0.17 } } } ``` -------------------------------- ### Nutrition API - GET /nutrition Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/nutrition/index.html Retrieve specific nutritional information for a single food item. ```APIDOC ## GET /nutrition ### Description The Nutrition API allows you to retrieve direct specific nutritional information for a single food item. It accepts a mandatory `name` parameter, an optional `brand` parameter, and optional `quantity` and `unit` parameters. If `quantity` and `unit` are not provided, the API intelligently infers the most likely defaults. The API's accuracy is grounded in our research, which has been validated in top peer-reviewed academic publications. ### Method GET ### Endpoint https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition ### Parameters #### Query Parameters - **key** (string) - Required - The API key for authentication. - **name** (string) - Required - The name of the food item. - **brand** (string) - Optional - The brand name of the food item. - **quantity** (number) - Optional - The quantity of the food item. - **unit** (string) - Optional - The unit of the food item. ### Request Example ```json curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition?key=YOUR_API_KEY&name=apple&quantity=1&unit=whole' ``` ### Response #### Success Response (200) - **calories** (number) - The total calories of the food item. - **serving_size** (string) - The serving size of the food item. - **nutrients** (object) - An object containing detailed nutrient information. - **protein** (number) - Protein content in grams. - **fat** (number) - Fat content in grams. - **carbohydrates** (number) - Carbohydrate content in grams. #### Response Example ```json { "calories": 95, "serving_size": "1 medium (182g)", "nutrients": { "protein": 0.5, "fat": 0.3, "carbohydrates": 25 } } ``` ``` -------------------------------- ### Example Successful UPC Lookup Response Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt This JSON response shows successful retrieval of nutritional data for a packaged food item identified by its UPC. ```json { "code": 200, "success": true, "data": { "name": "Packaged Apple Slices", "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 61, "carb_g": 14.8, "fat_g": 0.15, "protein_g": 0.17, "fiber_g": 2.1, "sugar_g": 12.1, "vitamin_a_mcg": 3, "vitamin_c_mg": 4.6, "calcium_mg": 5, "iron_mg": 0.03, "potassium_mg": 104, "sodium_mg": 0, "saturated_fats_g": 0, "cholesterol_mg": 0, "percent_fruit": 1, "percent_vegetable": 0, "is_beverage": false, "source_urls": ["https://fdc.nal.usda.gov/fdc-app.html#/food-details/2344711/nutrients"] }, "alt_units": [ {"unit": "package", "weight_in_grams": 100}, {"unit": "g", "weight_in_grams": 1}, {"unit": "serving", "weight_in_grams": 100} ], "default_portion": {"quantity": 1, "unit": "serving"}, "selected_portion": {"quantity": 100, "unit": "g"}, "selected_portion_nutrition": { "mass_g": 100, "calories_kcal": 61, "carb_g": 14.8, "fat_g": 0.15, "protein_g": 0.17 } } } ``` -------------------------------- ### Food Analysis API Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Analyze food items using either a description or an image URL to get detailed nutritional information. ```APIDOC ## GET /analysis ### Description Analyzes food items based on a provided description or image URL and returns nutritional information. ### Method GET ### Endpoint https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis ### Parameters #### Query Parameters - **key** (string) - Required - Your API key for authentication. - **description** (string) - Optional - A text description of the food item. - **image_url** (string) - Optional - The URL of an image of the food item. ### Request Example ```bash curl -X GET "https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis?key=YOUR_API_KEY&description=Pure%20Honey" ``` ### Response #### Success Response (200) - **code** (integer) - The status code of the response. - **success** (boolean) - Indicates if the analysis was successful. - **data** (object) - Contains detailed nutritional information if successful. - **name** (string) - The name of the food item. - **alt_units** (array) - Alternative units for the food item. - **selected_portion** (object) - The selected portion of the food item. - **selected_portion_nutrition** (object) - Nutritional information for the selected portion. - **nutrition_per_100g** (object) - Nutritional information per 100g. - **product_image_uri** (string) - URI of the product image. #### Error Response (200 with success: false) - **code** (integer) - The status code of the response. - **success** (boolean) - Indicates if the analysis was successful. - **text** (string) - A message indicating the reason for failure (e.g., "Unable to Parse Label"). #### Response Example (Success) { "code": 200, "success": true, "data": { "name": "Pure Honey", "alt_units": [ {"unit": "serving", "weight_in_grams": 21} ], "selected_portion": {"quantity": 1, "unit": "serving"}, "selected_portion_nutrition": { "mass_g": 21, "calories_kcal": 60, "carb_g": 17, "fat_g": 0, "protein_g": 0, "sugar_g": 17, "fiber_g": 0, "sodium_mg": 0, "vitamin_c_mg": 0, "vitamin_d_iu": 0, "calcium_mg": 0, "iron_mg": 0, "potassium_mg": 0, "cholesterol_mg": 0, "saturated_fats_g": 0, "trans_fats_g": 0 }, "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 285.7143, "carb_g": 80.9524, "fat_g": 0, "protein_g": 0, "sugar_g": 80.9524 } }, "product_image_uri": "http://example.com/honey-front.jpg" } #### Response Example (Unable to parse) { "code": 200, "success": false, "text": "Unable to Parse Label" } ``` -------------------------------- ### Initialize Theme Script Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/tags/index.html Sets the document theme based on local storage or defaults to light mode. ```javascript !function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}() ``` -------------------------------- ### Nutrition API Sample Request Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/nutrition/index.html A cURL command demonstrating how to query the Nutrition API with authentication and food item parameters. ```bash curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition?key=YOUR_API_KEY&name=apple&quantity=1&unit=whole' ``` -------------------------------- ### Usage API - Check API Usage and Limits Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Monitor your API consumption and rate limits using the Usage API. ```APIDOC ## GET /usage ### Description Provides information about current API usage and rate limits for a given API key. ### Method GET ### Endpoint https://us-central1-snapcalorieb2bapi.cloudfunctions.net/usage ### Parameters #### Query Parameters - **key** (string) - Required - Your API key for authentication. ### Request Example ```bash curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/usage?key=YOUR_API_KEY' ``` ### Response #### Success Response (200) - **code** (integer) - The status code of the response. - **data** (object) - Contains usage and limit information. - **limit** (integer) - The maximum allowed usage. - **usage** (integer) - The current usage count. #### Error Response (401 Unauthorized) - **code** (integer) - The status code of the response. - **text** (string) - A message indicating the reason for failure (e.g., "Unauthorized"). #### Response Example (Success) { "code": 200, "data": { "limit": 100, "usage": 5 } } #### Response Example (Unauthorized) { "code": 401, "text": "Unauthorized" } ``` -------------------------------- ### UPC API Sample Request Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/upc/index.html Use this cURL command to request nutritional data for a product using its UPC. Replace YOUR_API_KEY and the UPC value with your actual credentials and the barcode number. ```bash curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/upc?key=YOUR_API_KEY&upc=123456789' ``` -------------------------------- ### Check API Usage with Curl Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Use this curl command to check your current API usage and rate limits. Replace YOUR_API_KEY with your actual API key. ```bash # Check current usage curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/usage?key=YOUR_API_KEY' ``` -------------------------------- ### Lookup Nutrition by Name Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Retrieve nutritional data for specific food items, optionally specifying brand, quantity, and unit. ```bash # Basic nutrition lookup curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition?key=YOUR_API_KEY&name=apple&quantity=1&unit=whole' ``` ```bash # Lookup with brand specification curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition?key=YOUR_API_KEY&name=cola&brand=coca-cola&quantity=12&unit=oz' ``` -------------------------------- ### Parse Nutrition Labels from Base64 Images using Python Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt This Python script demonstrates how to send nutrition label and product front images encoded in Base64 to the Nutrition Label API using a PUT request. ```python import requests import base64 with open("nutrition_label.jpg", "rb") as f: label_b64 = base64.b64encode(f.read()).decode() with open("product_front.jpg", "rb") as f: product_b64 = base64.b64encode(f.read()).decode() response = requests.put( 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition-label', json={ 'key': 'YOUR_API_KEY', 'image': label_b64, 'product_image': product_b64 } ) ``` -------------------------------- ### GET/PUT /analysis Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/analysis/index.html Endpoint to perform nutritional analysis of food items using either a text description or an image. ```APIDOC ## GET/PUT /analysis ### Description The Analysis API performs an analysis of food items from a provided description and/or an image or image URL. It returns a JSON representation of identified foods and their quantities with corresponding nutrition. ### Method GET, PUT ### Endpoint https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis ### Parameters #### Query/Request Parameters - **key** (string) - Required - The API key for authentication. - **description** (string) - Optional - Free text description of food items. - **image_url** (string) - Optional - URL of an image containing food items. - **image** (binary/base64) - Optional - Attached image data. *Note: At least one of description or image must be present.* ### Request Example ```curl curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis?key=YOUR_API_KEY&description=YOUR_DESCRIPTION&image_url=YOUR_IMAGE_URL' ``` ```python import requests response = requests.put('https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis', json={'key': api_key, 'image': b64image_data}) ``` ``` -------------------------------- ### Sample Success Response JSON Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/analysis/index.html This JSON object represents a successful API response, detailing the nutritional information for a food item. It includes per-100g data, alternative units, and selected portion details. Note that detailed nutrient fields may be absent if not available. ```json { "code": 200, "success": true, "data": [ { "name": "big mac", "brand": "McDonald's", "nutrition_per_100g": { // Guaranteed fields "mass_g": 100, "calories_kcal": 225, "carb_g": 18.75, "fat_g": 11.6667, "protein_g": 10.4167, // Detailed Nutrients, if available // All possible fields are shown here, but if a nutrient is not availble, // it will not be present in the response. // Vitamins "b1_mg": , "b2_mg": , "b3_mg": , "b5_mg": , "b6_mg": , "b12_mcg": , "folate_mcg": , "vitamin_a_mcg": , "vitamin_c_mg": , "vitamin_d_iu": 0, "vitamin_e_mg": , "vitamin_k_mcg": , // Minerals "calcium_mg": 0, "copper_mg": , "iron_mg": 1.8, "magnesium_mg": , "manganese_mg": , "phosphorus_mg": , "potassium_mg": 150, "selenium_mcg": , "sodium_mg": 420, "zinc_mg": , // Carbohydrates "fiber_g": 1.2, "starch_g": , "sugar_g": 3.5, // Lipids aka Fats "monounsaturated_g": , "polyunsaturated_g": , "omega_3_fatty_acids_g": , "omega_6_fatty_acids_g": , "saturated_fats_g": 3, "trans_fats_g": 0.4, "cholesterol_mg": 35, // Proteins "cystine_g": , "histidine_g": , "isoleucine_g": , "leucine_g": , "lysine_g": , "methionine_g": , "phenylalanine_g": , "threonine_g": , "tryptophan_g": , "tyrosine_g": , "valine_g": , // Other Details "percent_fruit": 0, "percent_vegetable": 0.05, "percent_non_starchy_vegetable": 0.05, "percent_whole_grain": 0, "percent_legume_or_nuts": 0, "healthy_fats": false, "lean_protein": true, "ultra_processed": true, "is_beverage": false, "added_sugars_g": 9, "source_urls": ["https://www.mcdonalds.com/us/en-us/product/big-mac.html"] }, "alt_units": [ { "unit": "serving", "weight_in_grams": 240 }, { "unit": "g", "weight_in_grams": 1 }, { "unit": "sandwich", "weight_in_grams": 240 }, { "unit": "calorie", "weight_in_grams": 0.4444 } ], "default_portion": { "quantity": 1, "unit": "sandwich" }, "selected_portion": { "quantity": 1, "unit": "sandwich" }, "selected_portion_nutrition": { "mass_g": 240, "calories_kcal": 540, "carb_g": 45, "fat_g": 28.0001, "protein_g": 25.0001 } } ] } ``` -------------------------------- ### Analyze Food via Analysis API Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Perform food recognition using image URLs or base64 encoded images with optional text descriptions. ```bash # GET request with image URL and description curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis?key=YOUR_API_KEY&description=big%20mac&image_url=https://example.com/food.jpg' ``` ```python # PUT request with base64 encoded image (Python) import requests import base64 with open("food_image.jpg", "rb") as f: b64image = base64.b64encode(f.read()).decode() response = requests.put( 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis', json={ 'key': 'YOUR_API_KEY', 'image': b64image, 'description': 'grilled chicken salad' } ) ``` ```json # Example successful response { "code": 200, "success": true, "data": [ { "name": "big mac", "brand": "McDonald's", "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 225, "carb_g": 18.75, "fat_g": 11.6667, "protein_g": 10.4167, "fiber_g": 1.2, "sugar_g": 3.5, "sodium_mg": 420, "saturated_fats_g": 3, "trans_fats_g": 0.4, "cholesterol_mg": 35, "iron_mg": 1.8, "potassium_mg": 150, "percent_fruit": 0, "percent_vegetable": 0.05, "lean_protein": true, "ultra_processed": true, "is_beverage": false, "added_sugars_g": 9, "source_urls": ["https://www.mcdonalds.com/us/en-us/product/big-mac.html"] }, "alt_units": [ {"unit": "serving", "weight_in_grams": 240}, {"unit": "g", "weight_in_grams": 1}, {"unit": "sandwich", "weight_in_grams": 240} ], "default_portion": {"quantity": 1, "unit": "sandwich"}, "selected_portion": {"quantity": 1, "unit": "sandwich"}, "selected_portion_nutrition": { "mass_g": 240, "calories_kcal": 540, "carb_g": 45, "fat_g": 28.0001, "protein_g": 25.0001 } } ] } ``` -------------------------------- ### Sample Success Response Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/analysis/index.html This is a sample of a successful response from the API, detailing a food item's nutritional information. ```APIDOC ## Sample Success Response This response provides detailed nutritional information for a food item. ### Response Body - **code** (integer) - The status code of the response. - **success** (boolean) - Indicates if the request was successful. - **data** (array) - An array of food items. - **name** (string) - The name of the food item. - **brand** (string) - The brand of the food item (optional). - **nutrition_per_100g** (object) - Nutritional information per 100 grams. - **mass_g** (number) - Mass in grams. - **calories_kcal** (number) - Calories in kcal. - **carb_g** (number) - Carbohydrates in grams. - **fat_g** (number) - Fat in grams. - **protein_g** (number) - Protein in grams. - ... (other detailed nutrients like vitamins, minerals, etc. - fields are present only if available) - **percent_fruit** (number) - Portion of item that is fruit (0-1). - **percent_vegetable** (number) - Portion of item that is vegetable (0-1). - **percent_non_starchy_vegetable** (number) - Portion of item that is non-starchy vegetables (0-1). - **percent_whole_grain** (number) - Portion of item that is whole grain (0-1). - **percent_legume_or_nuts** (number) - Portion of item that is legume or nuts (0-1). - **healthy_fats** (boolean) - Whether the item qualifies as a healthy fat source. - **lean_protein** (boolean) - Whether the item qualifies as a lean protein source. - **ultra_processed** (boolean) - Whether the item is ultra processed. - **is_beverage** (boolean) - Whether the item is primarily a beverage. - **added_sugars_g** (number) - Estimated added sugars in grams. - **source_urls** (array of strings) - URLs where the information was sourced. - **alt_units** (array of objects) - Alternative units for the food item. - **unit** (string) - The name of the unit. - **weight_in_grams** (number) - The weight of the unit in grams. - **default_portion** (object) - The default portion of the food item. - **quantity** (number) - The quantity of the default portion. - **unit** (string) - The unit of the default portion. - **selected_portion** (object) - The selected portion of the food item. - **quantity** (number) - The quantity of the selected portion. - **unit** (string) - The unit of the selected portion. - **selected_portion_nutrition** (object) - Nutritional information for the selected portion. - **mass_g** (number) - Mass in grams. - **calories_kcal** (number) - Calories in kcal. - **carb_g** (number) - Carbohydrates in grams. - **fat_g** (number) - Fat in grams. - **protein_g** (number) - Protein in grams. - ... (other detailed nutrients similar to nutrition_per_100g) ### Response Example ```json { "code": 200, "success": true, "data": [ { "name": "big mac", "brand": "McDonald's", "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 225, "carb_g": 18.75, "fat_g": 11.6667, "protein_g": 10.4167, "b1_mg": null, "b2_mg": null, "b3_mg": null, "b5_mg": null, "b6_mg": null, "b12_mcg": null, "folate_mcg": null, "vitamin_a_mcg": null, "vitamin_c_mg": null, "vitamin_d_iu": 0, "vitamin_e_mg": null, "vitamin_k_mcg": null, "calcium_mg": 0, "copper_mg": null, "iron_mg": 1.8, "magnesium_mg": null, "manganese_mg": null, "phosphorus_mg": null, "potassium_mg": 150, "selenium_mcg": null, "sodium_mg": 420, "zinc_mg": null, "fiber_g": 1.2, "starch_g": null, "sugar_g": 3.5, "monounsaturated_g": null, "polyunsaturated_g": null, "omega_3_fatty_acids_g": null, "omega_6_fatty_acids_g": null, "saturated_fats_g": 3, "trans_fats_g": 0.4, "cholesterol_mg": 35, "cystine_g": null, "histidine_g": null, "isoleucine_g": null, "leucine_g": null, "lysine_g": null, "methionine_g": null, "phenylalanine_g": null, "threonine_g": null, "tryptophan_g": null, "tyrosine_g": null, "valine_g": null, "percent_fruit": 0, "percent_vegetable": 0.05, "percent_non_starchy_vegetable": 0.05, "percent_whole_grain": 0, "percent_legume_or_nuts": 0, "healthy_fats": false, "lean_protein": true, "ultra_processed": true, "is_beverage": false, "added_sugars_g": 9, "source_urls": [ "https://www.mcdonalds.com/us/en-us/product/big-mac.html" ] }, "alt_units": [ { "unit": "serving", "weight_in_grams": 240 }, { "unit": "g", "weight_in_grams": 1 }, { "unit": "sandwich", "weight_in_grams": 240 }, { "unit": "calorie", "weight_in_grams": 0.4444 } ], "default_portion": { "quantity": 1, "unit": "sandwich" }, "selected_portion": { "quantity": 1, "unit": "sandwich" }, "selected_portion_nutrition": { "mass_g": 240, "calories_kcal": 540, "carb_g": 45, "fat_g": 28.0001, "protein_g": 25.0001 } } ] } ``` ``` -------------------------------- ### Lookup Nutrition by Barcode using cURL Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Use this cURL command to query the UPC API for nutritional data using a product's barcode. Replace YOUR_API_KEY with your actual key. ```bash # Lookup by UPC barcode curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/upc?key=YOUR_API_KEY&upc=049000006346' ``` -------------------------------- ### Analysis API - Analyze Food from Images and Text Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Performs intelligent food recognition from images and/or text descriptions using SnapCalorie's proprietary AI model. It returns identified food items with complete nutritional data. ```APIDOC ## GET /analysis ### Description Analyzes food from an image URL and/or text description. ### Method GET ### Endpoint `https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis` ### Query Parameters - **key** (string) - Required - Your API key. - **description** (string) - Optional - A text description of the food. - **image_url** (string) - Optional - The URL of the food image. ### Request Example ```bash curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis?key=YOUR_API_KEY&description=big%20mac&image_url=https://example.com/food.jpg' ``` ## Analysis API - Analyze Food from Images and Text (Base64) ### Description Analyzes food from a base64 encoded image and/or text description. ### Method PUT ### Endpoint `https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis` ### Request Body - **key** (string) - Required - Your API key. - **image** (string) - Required - Base64 encoded image data. - **description** (string) - Optional - A text description of the food. ### Request Example ```python import requests import base64 with open("food_image.jpg", "rb") as f: b64image = base64.b64encode(f.read()).decode() response = requests.put( 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/analysis', json={ 'key': 'YOUR_API_KEY', 'image': b64image, 'description': 'grilled chicken salad' } ) ``` ### Response #### Success Response (200) - **code** (integer) - Status code. - **success** (boolean) - Indicates if the request was successful. - **data** (array) - An array of identified food items. - **name** (string) - The name of the food item. - **brand** (string) - The brand of the food item. - **nutrition_per_100g** (object) - Nutritional information per 100g. - **mass_g** (number) - Mass in grams. - **calories_kcal** (number) - Calories in kcal. - **carb_g** (number) - Carbohydrates in grams. - **fat_g** (number) - Fat in grams. - **protein_g** (number) - Protein in grams. - **fiber_g** (number) - Fiber in grams. - **sugar_g** (number) - Sugar in grams. - **sodium_mg** (number) - Sodium in mg. - **saturated_fats_g** (number) - Saturated fats in grams. - **trans_fats_g** (number) - Trans fats in grams. - **cholesterol_mg** (number) - Cholesterol in mg. - **iron_mg** (number) - Iron in mg. - **potassium_mg** (number) - Potassium in mg. - **percent_fruit** (number) - Percentage of fruit. - **percent_vegetable** (number) - Percentage of vegetable. - **lean_protein** (boolean) - Indicates if it's lean protein. - **ultra_processed** (boolean) - Indicates if it's ultra-processed. - **is_beverage** (boolean) - Indicates if it's a beverage. - **added_sugars_g** (number) - Added sugars in grams. - **source_urls** (array) - URLs for the source of information. - **alt_units** (array) - Alternative units for the food item. - **unit** (string) - The unit of measurement. - **weight_in_grams** (number) - Weight in grams. - **default_portion** (object) - The default portion size. - **quantity** (number) - The quantity. - **unit** (string) - The unit. - **selected_portion** (object) - The selected portion size. - **quantity** (number) - The quantity. - **unit** (string) - The unit. - **selected_portion_nutrition** (object) - Nutritional information for the selected portion. - **mass_g** (number) - Mass in grams. - **calories_kcal** (number) - Calories in kcal. - **carb_g** (number) - Carbohydrates in grams. - **fat_g** (number) - Fat in grams. - **protein_g** (number) - Protein in grams. #### Response Example ```json { "code": 200, "success": true, "data": [ { "name": "big mac", "brand": "McDonald's", "nutrition_per_100g": { "mass_g": 100, "calories_kcal": 225, "carb_g": 18.75, "fat_g": 11.6667, "protein_g": 10.4167, "fiber_g": 1.2, "sugar_g": 3.5, "sodium_mg": 420, "saturated_fats_g": 3, "trans_fats_g": 0.4, "cholesterol_mg": 35, "iron_mg": 1.8, "potassium_mg": 150, "percent_fruit": 0, "percent_vegetable": 0.05, "lean_protein": true, "ultra_processed": true, "is_beverage": false, "added_sugars_g": 9, "source_urls": ["https://www.mcdonalds.com/us/en-us/product/big-mac.html"] }, "alt_units": [ {"unit": "serving", "weight_in_grams": 240}, {"unit": "g", "weight_in_grams": 1}, {"unit": "sandwich", "weight_in_grams": 240} ], "default_portion": {"quantity": 1, "unit": "sandwich"}, "selected_portion": {"quantity": 1, "unit": "sandwich"}, "selected_portion_nutrition": { "mass_g": 240, "calories_kcal": 540, "carb_g": 45, "fat_g": 28.0001, "protein_g": 25.0001 } } ] } ``` ``` -------------------------------- ### General Usage Notes Source: https://github.com/snapcalorie/snapcalorie.github.io/blob/main/docs/analysis/index.html Important notes regarding API usage, including security and response format. ```APIDOC ## Notes * Replace `YOUR_API_KEY`, `YOUR_DESCRIPTION`, and `YOUR_IMAGE_URL` with your actual values. * Ensure that your requests are sent over HTTPS to maintain security. * The response format is JSON, providing a list of identified food items and their details. * `brand` is an optional field that is only set if relevant to the query. ``` -------------------------------- ### Parse Nutrition Labels from Images using cURL Source: https://context7.com/snapcalorie/snapcalorie.github.io/llms.txt Use this cURL command to send image URLs to the Nutrition Label API for processing. Ensure you replace YOUR_API_KEY with your valid key. ```bash # GET request with image URLs curl -X GET 'https://us-central1-snapcalorieb2bapi.cloudfunctions.net/nutrition-label?key=YOUR_API_KEY&image_url=https://www.fda.gov/files/nfl-howtounderstand-honey.png&product_image_url=http://example.com/honey-front.jpg' ```