Skip to content

Quickstart ​

This page takes you from no account to a working scan. You need a terminal, and Python 3 with requests or Node 18 or newer if you want to follow along in code.

1. Get a test key ​

Go to platform.nutriscan.app and sign in with your email. We email you a 6-digit code and your account is made on the spot. A new account gets test keys at no cost.

Copy the test key (it starts with ns_test_) and put it in an environment variable:

bash
export NUTRISCAN_KEY="ns_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

A test key returns a fixed sample result and uses no credits. The sample is a plate of grilled chicken with rice and salad, NutriScore B, 515 kcal. It has the same JSON shape as a live scan, so everything you build with it works unchanged later.

2. Send a scan ​

Send a meal photo by URL. The image must be on a public https URL; we fetch it once.

bash
curl https://platform-api.nutriscan.app/v1/scans \
  -H "Authorization: Bearer $NUTRISCAN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "type": "meal", "image_url": "https://example.com/lunch.jpg", "language": "en" }'
python
import os
import requests

resp = requests.post(
    "https://platform-api.nutriscan.app/v1/scans",
    headers={"Authorization": f"Bearer {os.environ['NUTRISCAN_KEY']}"},
    json={"type": "meal", "image_url": "https://example.com/lunch.jpg", "language": "en"},
    timeout=100,  # a scan can take up to 95 seconds
)
scan = resp.json()
if resp.status_code != 200:
    raise RuntimeError(f"{resp.status_code} {scan['error']['code']}: {scan['error']['message']}")
print(scan["meal"]["name"], scan["meal"]["nutri_score"], scan["meal"]["totals"]["calories"])
js
// Node 18 or newer: fetch is built in
const resp = await fetch("https://platform-api.nutriscan.app/v1/scans", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NUTRISCAN_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ type: "meal", image_url: "https://example.com/lunch.jpg", language: "en" }),
  signal: AbortSignal.timeout(100_000), // a scan can take up to 95 seconds
});
const scan = await resp.json();
if (!resp.ok) throw new Error(`${resp.status} ${scan.error.code}: ${scan.error.message}`);
console.log(scan.meal.name, scan.meal.nutri_score, scan.meal.totals.calories);

With a test key this prints Grilled chicken with rice and salad B 515.

Upload the file instead of a URL ​

If the photo is on your server and not public, send it as base64 in image_base64 instead of image_url. Send one or the other, not both.

python
import base64

with open("lunch.jpg", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

resp = requests.post(
    "https://platform-api.nutriscan.app/v1/scans",
    headers={"Authorization": f"Bearer {os.environ['NUTRISCAN_KEY']}"},
    json={"type": "meal", "image_base64": image_b64},
    timeout=100,
)
js
import { readFile } from "node:fs/promises";

const image_base64 = (await readFile("lunch.jpg")).toString("base64");
const resp = await fetch("https://platform-api.nutriscan.app/v1/scans", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NUTRISCAN_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ type: "meal", image_base64 }),
  signal: AbortSignal.timeout(100_000),
});

JPEG, PNG and WebP work up to 10 MB. HEIC is not supported yet, so convert iPhone photos on the device before you send them.

3. Read the result ​

The fields most apps show first:

  • meal.name and meal.nutri_score, with meal.nutri_score_reason as a one-line explanation.
  • meal.totals.calories, protein_g, carbs_g and fat_g.
  • items[], each with name, portion.display (for example "1 cup (158 g)") and calories.

The result documents every field.

4. Go live ​

When your integration works with the test key:

  1. Buy a credit pack in the console (see pricing).
  2. Create a live key. It starts with ns_live_.
  3. Replace the test key in your server's environment. No code changes.

A live result adds credits_used and ends with usage.credits_left, so you can watch your balance as you go.

Next steps ​

  • Long plates take time. Use streaming to show detected items after about 10 to 15 seconds.
  • Retries happen. Add an Idempotency-Key header as described in create a scan so a retry with the same body uses credits once.
  • Handle 402, 422 and 429 before launch. The errors page says what to do for each.

Related pages: the API docs overview, authentication for test and live keys, Nutrition API pricing for credit costs and the Nutrition API overview.