Skip to documentation

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.

Public calculator · No API keyOpenAPI specification ↗

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.

Terminal · cURL
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
      }
    }
  ]
}
JSON
Bring your own nutrition data. This endpoint performs calculations on the values you provide. It does not include a food database, recognize food from images, or infer nutrition from ingredient names.

02 / Input

Request reference

POST/api/v1/nutrition/calculate

Send a JSON object with Content-Type: application/json. Numeric values must be finite numbers, not numeric strings. Unrecognized fields are rejected.

Request body fields and validation
FieldTypeConstraints
servingsintegerRequired. 1–1,000. The number of equal servings.
ingredientsarrayRequired. 1–50 ingredient objects. Each object describes one ingredient and its supplied nutrition data.
ingredients[].namestringRequired. 1–120 characters after trimming whitespace. A descriptive ingredient name; it is not used to look up nutrition values.
ingredients[].amount_gnumberRequired. Greater than 0 and at most 100,000. The ingredient’s weight in grams.
ingredients[].nutrients_per_100gobjectRequired. 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.

Nutrition field names, units per 100 grams, and requirements
FieldUnit per 100 gRequirement
calories_kcalEnergykcalRequired
protein_gProteingRequired
carbohydrates_gCarbohydratesgRequired
fat_gFatgRequired
fiber_gFibergOptional
sugar_gSugargOptional
sodium_mgSodiummgOptional

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.

Response · application/json
{
  "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.

POST/api/v1/nutrition/guidance

Use 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.

Guidance request · application/json
{
  "intake": {
    "calories_kcal": 1450,
    "protein_g": 64,
    "fiber_g": 17
  },
  "targets": {
    "calories_kcal": 2000,
    "protein_g": 100,
    "fiber_g": 28
  },
  "diet": "vegetarian"
}
Required guidance request fields
FieldRequirements
intakeAn object with calories_kcal, protein_g, and fiber_g. Each must be a finite, nonnegative number.
targets.calories_kcalA finite number from 1,000 to 5,000 kcal.
targets.protein_gA finite number from 20 to 300 g.
targets.fiber_gA finite number from 10 to 60 g.
dietOne 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 workspace

07 / 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.

400

Invalid 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.

413

Payload too large

The request body exceeds 32 KiB. Reduce the body size before trying again.

415

Unsupported media type

Send the request with the Content-Type: application/json header.

405

Method 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