Authentication
Every request carries an API key as a bearer token. You create and revoke keys in the console at platform.nutriscan.app.
The header
Authorization: Bearer ns_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxIn code:
curl https://platform-api.nutriscan.app/v1/usage \
-H "Authorization: Bearer $NUTRISCAN_KEY"import os
import requests
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['NUTRISCAN_KEY']}"
print(session.get("https://platform-api.nutriscan.app/v1/usage", timeout=10).json())const headers = { Authorization: `Bearer ${process.env.NUTRISCAN_KEY}` };
const usage = await fetch("https://platform-api.nutriscan.app/v1/usage", { headers });
console.log(await usage.json());A missing key, a mistyped key or a key without the Bearer prefix returns 401 invalid_api_key. A key you revoked returns 403 key_revoked.
Test keys and live keys
| Test key | Live key | |
|---|---|---|
| Prefix | ns_test_ | ns_live_ |
| How you get it | Comes with every new account, at no cost | Create it in the console |
| What a scan returns | A fixed sample result | A real scan of your photo or text |
| Credits | Uses none, "credits_used": 0 | Uses credits from your balance |
| Marker in the result | "test_mode": true | none |
The test key's sample result is a plate of grilled chicken with rice and salad. It has the same JSON shape as a live scan, so you can build your parser, your screens and your error handling against it, then switch keys.
Use test keys in CI and on staging. They never touch your balance, so a loop in a test suite cannot cost money.
A live scan needs at least 20 credits in your balance to start. Below that, live scans return 402 insufficient_credits until you buy a pack.
Can you call the API from a mobile app?
No. Call the API from your backend, never from a mobile app or a web page. A key inside a mobile app can be pulled out of the binary and used by anyone, and a key in browser JavaScript is visible to every visitor. Whoever holds a live key spends your credits.
The usual setup:
- Your app uploads the photo to your server.
- Your server calls
POST /v1/scanswith the key from an environment variable or a secrets manager. - Your server returns the result, or the parts you need, to the app.
This also lets you add your own per-user limits before a request reaches us.
Managing keys
- An account can have up to 10 active keys. Use one per environment or per service, so you can revoke one without touching the others.
- All keys on an account share one balance and one rate limit of 60 scans a minute, test scans included.
- If a key leaks, revoke it in the console and create a new one. Requests with the old key return
403 key_revokedfrom then on. 403 account_suspendedmeans the whole account is blocked. Email support@nutriscan.app.
Idempotency keys are separate
The Idempotency-Key header has nothing to do with authentication. It makes retries safe and is explained in create a scan. One detail matters here: an idempotency key used with a test key cannot be reused with a live key, and the reverse. That returns 409 idempotency_mode_conflict.
Related pages: the quickstart for a first scan, create a scan for every request field, Nutrition API pricing for credit costs and the Nutrition API overview.