About
This guide provides complete implementation details and best practices for integrating the Nutrition API into your applications. For detailed API specifications and data types, refer to the API Reference.Authentication: The code examples in this guide focus on the nutrition analysis functionality. For authentication implementation details, see the Authentication documentation. You’ll need to add Bearer token into the Authorization header to all API requests.
API Endpoints
The Nutrition API provides these endpoints for managing nutrition records:POST /nutrition_records— upload food images for AI-powered nutritional analysisGET /nutrition_records— retrieve a list of nutrition records by the time rangeGET /nutrition_records/{id}— retrieve a specific nutrition record by IDPATCH /nutrition_records/{id}— change the portion size for a nutrition record by IDDELETE /nutrition_records/{id}— delete a specific nutrition record by ID
Image Preparation
For optimal image capture guidelines, see the Image Guidelines in the API overview.POST Request Body
Processing Modes
The processing mode is controlled by thewait_on_process parameter. The API supports two processing modes, each suited for a different use case:
Asynchronous Processing
Returns immediately and processes the image in the background. Ideal for user-facing applications where immediate feedback is important. See the Asynchronous Processing Guide for complete implementation details, webhook configuration, and code examples.Synchronous Processing
Waits for complete analysis before responding. Best for batch processing, server-to-server integrations, or when you can handle longer response times: Request:Analysis Modes
precise(default): Uses advanced AI models for the highest accuracy and detailed analysisfast: Uses optimized models for quicker processing with good accuracy
Localization
Providecountry_code and language_code for region-specific analysis:
- Region-specific food recognition
- Usage of local nutritional databases
- Translated ingredient names and descriptions
Including Optional Data
Control what data is included in the analysis:Selection of Nutritional Fields
You can control which nutritional fields are included in the analysis:include_nutrition_fields is omitted or empty, only four basic fields are included by default:
carbohydrate_genergy_kcalfat_total_gprotein_g
Response Body
Processing Status
Analysis of the nutrition record progresses through these states:- pending — Analysis has been queued
- processing — an AI model is actively analyzing the image
- completed — Analysis finished successfully with results
- failed — Processing failed due to unidentifiable content or technical issues
status field.
status field with values completed or failed only. Always handle different response statuses in your application logic.
Error Scenarios
Processing Failures
These occur when the API successfully receives your request but the AI analysis fails. The response will have HTTP 200 status with"status": "failed".
When status is failed, check the failure_reason field for specific details:
-
Unidentifiable food items — image contains non-food objects or unclear food items
-
Poor image quality — blurry, dark, or low-resolution images
-
AI processing timeouts — the processing by AI providers sometimes might take longer than expected due to reasons that cannot be foreseen. To control it, the upload process flow will result in a timeout error.
Once timeout occurs, the API will return HTTP status 200 and the body message with the
statusfield set tofailed:
Request Errors
These occur when there’s an issue with the request itself, returning non-200 HTTP status codes before analysis begins.-
Decoding Image Error — if the image is corrupted or improperly encoded, and therefore cannot be decoded, then HTTP 400 will be returned.
-
Invalid Image Format — nutrition AI supports JPEG, PNG, and WebP formats. When an image format is not supported, HTTP status code 400 will be returned.
-
Exceeding Image Size Limits — images larger than 10MB are not accepted, and API will return HTTP 413 status code.
Images larger than 11MB will be rejected by the gateway with HTTP 413 status code and the following error message.
-
Invalid Image URLs — when image is provided with the
body_urlparameter and the URL path is not found at the host, HTTP status code 422 will be returned.If thebody_urlparameter value is not a proper HTTP(S) URL, the following error will be given.
Nutrition Fields and Units
The names of nutrition fields are always lowercase and include units as suffix. Nutrition fields are not translated.Retrieving Results
Getting Results
For asynchronous processing, use webhooks for real-time notifications. See the Asynchronous Processing Guide for complete webhook implementation details. If webhooks are not yet available, you can check status using theGET /nutrition_records/{id} endpoint.
Retrospectively, a list of all analyzed nutrition records can be retrieved using the GET /nutrition_records endpoint by providing the time range.
Deleting Results
A result can be deleted usingDETELE /nutrition_records/{id} endpoint by providing the record ID.
An HTTP 204 status code will be returned if successful, regardless if the record existed or not.
Updating Results
You can update the serving size of any analyzed nutrition record. When the serving size is changed, all ingredients and their respective nutritional fields will be automatically recalculated proportionally to maintain the same nutritional ratios. This allows you to easily adjust portion sizes while maintaining accurate nutritional information. A result can be updated by callingPATCH /nutrition_records/{id} endpoint.
Best Practices
1. Choose the Right Processing Mode
- Asynchronous: For user-facing applications, mobile apps, and when you want immediate feedback
- Synchronous: For batch processing, server-to-server integrations, and when you can handle longer response times
2. Implement Proper Error Handling
- Handle network errors gracefully
- Provide meaningful error messages to users
- Implement retry logic for transient failures
Code Examples
Here are complete implementation examples in multiple programming languages:POST /nutrition_records API Reference.
