Developer documentation · v1
Your data. Clear nutrition.
Send ingredient weights and nutrition values per 100 g. Get nutrition totals for the full recipe, each ingredient, and one serving.
01 / Get started
Make your first calculation
Run this command in your terminal. The example uses illustrative input values; replace them with values from your own nutrition labels or data source before using the result in your product.
curl --request POST 'https://nutriai.fria.ai/api/v1/nutrition/calculate' \
--header 'Content-Type: application/json' \
--data-binary @- <<'JSON'
{
"servings": 2,
"ingredients": [
{
"name": "Rolled oats",
"amount_g": 80,
"nutrients_per_100g": {
"calories_kcal": 379,
"protein_g": 13.15,
"carbohydrates_g": 67.7,
"fat_g": 6.52,
"fiber_g": 10.1,
"sugar_g": 0.99,
"sodium_mg": 6
}
},
{
"name": "Whole milk",
"amount_g": 200,
"nutrients_per_100g": {
"calories_kcal": 61,
"protein_g": 3.15,
"carbohydrates_g": 4.8,
"fat_g": 3.25,
"fiber_g": 0,
"sugar_g": 5.05,
"sodium_mg": 43
}
}
]
}
JSON02 / Input
Request reference
/api/v1/nutrition/calculateSend a JSON object with Content-Type: application/json. Numeric values must be finite numbers, not numeric strings. Unrecognized fields are rejected.
| Field | Type | Constraints |
|---|---|---|
| servings | integer | Required. 1–1,000. The number of equal servings. |
| ingredients | array | Required. 1–50 ingredient objects. Each object describes one ingredient and its supplied nutrition data. |
| ingredients[].name | string | Required. 1–120 characters after trimming whitespace. A descriptive ingredient name; it is not used to look up nutrition values. |
| ingredients[].amount_g | number | Required. Greater than 0 and at most 100,000. The ingredient’s weight in grams. |
| ingredients[].nutrients_per_100g | object | Required. The ingredient’s nutrition values per 100 grams, using the fields below. |
03 / Nutrition values
Explicit units. Honest missing values.
All fields below belong to nutrients_per_100g. Every supplied nutrient value must be nonnegative and finite. A supplied zero is a known zero.
| Field | Unit per 100 g | Requirement |
|---|---|---|
calories_kcalEnergy | kcal | Required |
protein_gProtein | g | Required |
carbohydrates_gCarbohydrates | g | Required |
fat_gFat | g | Required |
fiber_gFiber | g | Optional |
sugar_gSugar | g | Optional |
sodium_mgSodium | mg | Optional |
Omit an optional field when its value is unknown; sending null in the request is not accepted. Its value in that ingredient’s response is null. If any ingredient omits it, the corresponding value in both totals and per_serving is also null. Other nutrients are still calculated.
For example, if one ingredient supplies fiber_g and another does not, the recipe’s fiber total is null. Supply 0 only when the source actually reports zero.
ingredient nutrient = value per 100 g × amount_g / 100
total nutrient = sum of ingredient nutrients
per-serving nutrient = total nutrient / servings
Numeric calculation results are rounded to six decimal places.
04 / Output
One response, three useful views
A successful request returns 200 OK with JSON. The sample below corresponds to the quickstart input; its request identifier is illustrative.
{
"request_id": "example-request-id",
"servings": 2,
"ingredient_count": 2,
"total_weight_g": 280,
"totals": {
"calories_kcal": 425.2,
"protein_g": 16.82,
"carbohydrates_g": 63.76,
"fat_g": 11.716,
"fiber_g": 8.08,
"sugar_g": 10.892,
"sodium_mg": 90.8
},
"per_serving": {
"calories_kcal": 212.6,
"protein_g": 8.41,
"carbohydrates_g": 31.88,
"fat_g": 5.858,
"fiber_g": 4.04,
"sugar_g": 5.446,
"sodium_mg": 45.4
},
"ingredients": [
{
"name": "Rolled oats",
"amount_g": 80,
"nutrients": {
"calories_kcal": 303.2,
"protein_g": 10.52,
"carbohydrates_g": 54.16,
"fat_g": 5.216,
"fiber_g": 8.08,
"sugar_g": 0.792,
"sodium_mg": 4.8
}
},
{
"name": "Whole milk",
"amount_g": 200,
"nutrients": {
"calories_kcal": 122,
"protein_g": 6.3,
"carbohydrates_g": 9.6,
"fat_g": 6.5,
"fiber_g": 0,
"sugar_g": 10.1,
"sodium_mg": 86
}
}
]
}- request_id
- An identifier for the calculation response.
- servings
- The requested number of equal servings.
- ingredient_count
- The number of ingredients included in the calculation.
- total_weight_g
- The sum of the supplied ingredient weights, in grams.
- totals
- The seven nutrient fields for the complete recipe, using the units encoded in their names.
- per_serving
- The same seven fields divided by the number of servings. Unknown optional nutrients remain null.
- ingredients
- Each ingredient’s name, amount_g, and nutrients object. Its seven nutrient fields are scaled to the supplied ingredient weight.
05 / Dietary guidance
Suggestions based on your users’ targets
Submit daily calorie, protein, and fiber intake alongside user-selected targets and a dietary preference. The guidance endpoint returns the difference from each target and general food suggestions selected by deterministic rules.
/api/v1/nutrition/guidanceUse Content-Type: application/json. No API key is required. The request body limit is 32 KiB. This example uses illustrative targets, not recommended personal targets.
{
"intake": {
"calories_kcal": 1450,
"protein_g": 64,
"fiber_g": 17
},
"targets": {
"calories_kcal": 2000,
"protein_g": 100,
"fiber_g": 28
},
"diet": "vegetarian"
}| Field | Requirements |
|---|---|
| intake | An object with calories_kcal, protein_g, and fiber_g. Each must be a finite, nonnegative number. |
| targets.calories_kcal | A finite number from 1,000 to 5,000 kcal. |
| targets.protein_g | A finite number from 20 to 300 g. |
| targets.fiber_g | A finite number from 10 to 60 g. |
| diet | One of: balanced, vegetarian, vegan. |
The response includes request_id, a summary with calories_gap_kcal, protein_gap_g, and fiber_gap_g, and a recommendations array whose items have title and detail.
Each gap is target − intake. A negative number means the reported intake is above that target; it is not an instruction to reduce intake or skip a meal.
The response identifies its basis as user-supplied targets and dietary preference and its method as rule-based general guidance. This endpoint does not call an external AI model, set a user’s targets, or provide medical dietary advice. The target ranges above are input validation limits.
Invalid JSON or input returns 400, an oversized body returns 413, and an unsupported content type returns 415. The JSON error response contains request_id and an error object with code and message.
06 / Daily tracking
Try the daily workspace
The NutriAI workspace lets users record daily calories, protein, and fiber, choose their own targets and dietary preference, and request suggestions from the guidance API.
The diary uses this browser’s local storage. Entries and settings are saved on this device and do not sync to the cloud or across devices. Requesting guidance sends the daily totals, selected targets, and dietary preference to the guidance endpoint. Clearing browser storage removes the locally saved diary.
Open workspace07 / Troubleshooting
Handle invalid requests
Check the HTTP status before reading a successful calculation. Correct the request before retrying these client errors.
Error responses contain request_id and an error object with code, message, and an optional path identifying a field. Use the message and field path to diagnose validation failures.
400Invalid request
The body is not valid JSON, a field fails validation, or a calculation overflows. Check required fields, types, ranges, ingredient count, and unrecognized fields.
413Payload too large
The request body exceeds 32 KiB. Reduce the body size before trying again.
415Unsupported media type
Send the request with the Content-Type: application/json header.
405Method not allowed
Use POST to submit a calculation. Other calculation methods are not supported.
08 / Integration
Access & request limits
- The public calculator requires no API key or account.
- Browser requests are supported with
Access-Control-Allow-Origin: *. - Each request can contain up to 50 ingredients and a body of up to 32 KiB (32,768 bytes).
- Use 1–1,000 servings and no more than 100,000 g per ingredient.
- Submitted ingredient inputs are not written to a database by the calculator.
Use the OpenAPI specification as the machine-readable reference for your integration.
09 / Build with us
Planning a commercial integration?
Tell us about your product, expected request volume, and integration needs. Contact sales to agree on the integration and support arrangements for your business.
Contact sales