Skip to content

Create a scan ​

POST /v1/scans runs one scan and returns the result in the same response. It handles all three inputs: a meal photo, a photo of a pack's nutrition label, and text.

bash
curl https://platform-api.nutriscan.app/v1/scans \
  -H "Authorization: Bearer $NUTRISCAN_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 7b1c5e0a-order-4411" \
  -d '{
    "type": "meal",
    "image_url": "https://example.com/lunch.jpg",
    "language": "en",
    "context": { "meal_time": "lunch", "cooking_method": ["grilled"] }
  }'

A scan can take up to 95 seconds. Set your HTTP client timeout to at least 100 seconds, or use streaming.

Request fields ​

FieldTypeNotes
typestringmeal (default), label or text.
image_base64stringThe image file, base64 encoded. JPEG, PNG or WebP, up to 10 MB and 50 megapixels (PNG and WebP: 24). Send this or image_url, not both.
image_urlstringA public https URL, up to 2,048 characters. We fetch it once, with no redirects and a 5 second timeout.
textstringUp to 2,000 characters. Only with type: "text".
languagestringLanguage of the names and the NutriScore reason: en, de, fr, es, it, pt, nl, pl, ru, tr, hi, ar. Only the first two letters are read, and an unsupported value falls back to en. Default en.
contextobjectOptional hints that improve accuracy. See below.
streambooleantrue sends progress events as they happen. See streaming.

The three inputs ​

Meal photo ​

"type": "meal" is the default. Send a photo of a plate, a bowl or a takeaway box. The scan names the dish, lists each item and estimates its portion from the photo.

json
{ "type": "meal", "image_url": "https://example.com/schnitzel-plate.jpg", "language": "de" }

Pack label photo ​

"type": "label" reads the nutrition table printed on a pack. Photograph the table itself, flat and in focus. The result follows the table, per pack or per serving.

json
{ "type": "label", "image_base64": "/9j/4AAQSkZJRgABAQ...", "language": "fr" }

Text ​

"type": "text" takes a description in the text field. Use it for a typed meal log, voice input turned into text, or a single food lookup.

json
{ "type": "text", "text": "200 g low-fat quark with a handful of blueberries", "language": "en" }

There is no separate food search or barcode endpoint. To get nutrients for one food, send it as text with an amount, such as "150 g grilled chicken breast".

Images ​

  • Formats: JPEG, PNG and WebP. HEIC is not supported yet; convert it on the device.
  • Size: up to 10 MB for the image file and 14.5 MB for the whole request body. A larger body returns 413 request_too_large.
  • Resolution: up to 50 megapixels for JPEG, 24 for PNG and WebP.
  • image_url must be public and https. Redirects are not followed and the fetch times out after 5 seconds. If we cannot fetch it, you get 400 image_url_unreachable.
  • A photo with no food in it returns 422 no_food_detected and is charged for the work it used, at least 20 credits.

The context object ​

context carries hints you already know, so the scan does not have to guess them from the photo. Every field is optional free text; leave out what you do not know. Unknown keys inside context are ignored. Unknown keys at the top level of the body are rejected with 400 invalid_request.

FieldType, max lengthHint about
meal_timestring, 32When the meal is eaten, for example "lunch"
food_typestring, 48The kind of food. "packaged-food" makes a photo scan run as a label scan.
cooking_methodlist of up to 8 stringsMethods, for example ["grilled"]
oil_quantitystring, 32How much oil went into the dish
consumed_quantitystring, 64How much of the food was eaten, for example "half"
locationstring, 200Where the meal is from
goalstring, 64The user's goal
food_preferencesstring, 200The user's food preferences
json
{
  "type": "meal",
  "image_url": "https://example.com/dinner.jpg",
  "context": { "meal_time": "dinner", "cooking_method": ["grilled"] }
}

Idempotency ​

Networks drop requests. To retry without paying twice, send an Idempotency-Key header with a value you generate per scan, such as a UUID or your own order id.

  • The same key with the same body returns the first result and uses credits once.
  • If the first try failed (402 or 500), the same key runs a fresh scan.
  • The same key with a different body returns 409 idempotency_conflict. Use a new key for a new body.
  • A key first used with a test key cannot be reused with a live key, or the reverse: 409 idempotency_mode_conflict.
  • If the first request with that key is still running, you get 409 idempotency_in_progress. Retry shortly.
python
import os, uuid, requests

key = str(uuid.uuid4())  # store it with the job so a retry sends the same value
for attempt in range(3):
    try:
        resp = requests.post(
            "https://platform-api.nutriscan.app/v1/scans",
            headers={
                "Authorization": f"Bearer {os.environ['NUTRISCAN_KEY']}",
                "Idempotency-Key": key,
            },
            json={"type": "text", "text": "2 eggs and a slice of toast"},
            timeout=100,
        )
        break
    except requests.exceptions.ConnectionError:
        continue

Fetch a past scan ​

GET /v1/scans/{id} returns a scan made with your account by its id, in the same JSON as the original response. Use it when a streamed connection drops after scan.started: the scan still finishes and this call returns it.

bash
curl https://platform-api.nutriscan.app/v1/scans/scn_Q2mX8rT4vK1pLw9eZb3nYh6A \
  -H "Authorization: Bearer $NUTRISCAN_KEY"

The response format is on the result page.

Related pages: authentication for the bearer header, streaming for progress events, Nutrition API pricing for what each input costs and the Nutrition API overview.