Food Nutrition API · REST + MCP

Send a food photo.
Get calories & macros.

One request returns detected foods, estimated edible grams, calories, protein, carbs, fat, and USDA FoodData Central provenance in typed JSON. Start with $5 for 500 prepaid scans by card, or pay 0.01 USDC per call over x402. No subscription.

From $5 / 500 scansVolume packs up to 38% off · never expire · tax included
REST + MCPBearer API key, or 0.01 USDC per call over x402
USDA + AI fallbackBundled local USDA matcher v8 · JPEG, PNG, or WebP
Saved examples · no key or payment

A photo in. Structured food data out.

Every response separates items, estimated grams, macros, and USDA FoodData Central IDs (or marks AI fallback when USDA has no match). Below are saved benchmark outputs alongside measured-reference calories so you can judge both structure and real-world limits before buying.

Nutrition5k reference photo: Potatoes and grain.

Potatoes and grain

298 kcal estimated (345 kcal ref · 235 g vs 244 g)

P 5.9 g · C 48.8 g · F 9.1 g · 3 items · USDA #2709402 + AI fallback

Caveat: the model called the quinoa couscous. Review food identity as well as the total.

Inspect saved JSON →
Nutrition5k reference photo: Breakfast plate.

Breakfast plate

354 kcal estimated (292 kcal ref · 300 g vs 292 g)

P 15.0 g · C 33.4 g · F 18.5 g · 3/3 USDA (#172187, #2709402, #2709883)

Caveat: reference includes sweet potato and oil. Photos can miss preparation details.

Inspect saved JSON →
Nutrition5k reference photo: Small steak plate.

Small steak plate

212 kcal estimated (153 kcal ref · 65 g vs 65 g)

P 11.9 g · C 0.0 g · F 17.9 g · 1/1 USDA (#2705852)

Caveat: matched a fattier beef cut than the reference. Review matched food and grams before logging.

Inspect saved JSON →

Nutrition5k, Thames et al., CC BY 4.0. Images unchanged. Machine-readable example catalog · Full benchmark and limits.

Start in 60 seconds with card credits

Buy prepaid scan credits through Stripe (tax included, no subscription, unused credits never expire). One credit pays for one successful analysis across REST or MCP; failed scans and no-food photos (422) return the reserved credit automatically.

PackPrice (USD, tax incl.)ScansPer scanSavings
pack_500$5500$0.0100Base rate
pack_3000$253,000$0.008317% off
pack_7000$507,000$0.007129% off
pack_16000$10016,000$0.006338% off
Publishes a complete Idempotency-Key atomically before sending and streams JSON over stdin so large photos never hit argv limits
# Atomically publish one request ID per intended scan (reuse on retry; delete only for a fresh paid scan).
TMP=$(mktemp lunch.jpg.reqid.XXXXXX)
uuidgen > "$TMP" && ln "$TMP" lunch.jpg.reqid 2>/dev/null || true
rm -f "$TMP"
REQ_ID=$(cat lunch.jpg.reqid)

(printf '{"image_base64":"'; base64 < lunch.jpg | tr -d '\r\n'; printf '","mime_type":"image/jpeg"}') \
  | curl -i https://kcalsnap.com/api/v1/analyze \
      -H "Authorization: Bearer $KCALSNAP_API_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: $REQ_ID" \
      --data-binary @-

Example response

{
  "request_id": "a6f0c1d2-...",
  "api_version": "v1",
  "dish_name": "Cooked rice",
  "items": [{
    "name": "Cooked rice",
    "query": "cooked white rice",
    "estimated_grams": 100,
    "model_confidence": 0.92,
    "nutrition_source": "usda",
    "fdc_id": "2708408",
    "matched_name": "Rice, white, cooked, no added fat",
    "per_100g": { "kcal": 129, "protein_g": 2.67, "carbs_g": 28, "fat_g": 0.28 },
    "nutrition": { "kcal": 129, "protein_g": 2.67, "carbs_g": 28, "fat_g": 0.28 }
  }],
  "totals": { "kcal": 129, "protein_g": 2.67, "carbs_g": 28, "fat_g": 0.28 },
  "estimated_total_grams": 100,
  "model": "kcalsnap-vision-1",
  "matcher_version": "v8",
  "estimate": true,
  "processing_ms": 1840
}

Illustrative response excerpt. Credit-funded REST responses also include an X-Credits-Remaining header; MCP calls return _meta["kcalsnap/credits_remaining"]. Full schema in openapi.json.

Want a dependency-free CLI that manages key files, retries, local caching, and checkout links? Use the runnable Node 22+ quickstart. Agents can also generate their own checkout link with POST /api/v1/credits/checkout, a Bearer key (kcs_live_ + 64 lowercase hex chars), {"order_id":"UUID_V4","pack_id":"pack_500"} (pack_id optional, defaults to pack_500; also accepts pack_3000, pack_7000, pack_16000), then hand the returned Stripe checkout_url to the cardholder to complete. Check credits anytime with GET /api/v1/credits/balance or the free MCP check_balance tool.

What comes back

  • Dish name and distinct detected food components (up to 20).
  • Estimated edible weight in grams, per food and whole meal.
  • Calories, protein, carbs, and fat per 100 g and per portion.
  • Nutrition source: bundled local USDA FoodData Central match (fdc_id + matched_name) or AI fallback.
  • Input formats: JPEG, PNG, or static WebP up to 2 MB and 2048 px per side (raw base64 or data:image/...;base64, data URL).
  • Output languages: English (en) and Lithuanian (lt).

MCP server

Connect any Streamable HTTP MCP client to:

https://kcalsnap.com/mcp
  • analyze_food – accepts image_base64, mime_type, optional language, optional known_total_grams, optional note (up to 280 chars of meal context), and idempotency_key. Uses 1 prepaid credit with a Bearer key, or 0.01 USDC via @x402/mcp.
  • check_balance – free tool that reconciles expired reservations and returns credits_remaining, blocked, and test_mode for the configured Bearer key.

Tool discovery and check_balance are free.

Already know the weight or hidden ingredients? Pass known_total_grams or note

Measured total weight: pass optional known_total_grams (1 to 5000 g of edible food, excluding the plate and inedible parts, up to 2 decimals) in REST or MCP. KcalSnap preserves your exact total weight and allocates each detected food's share from the estimated relative proportions (informed by the photo, and by note when also provided), labeling portion_basis as supplied_total + photo_estimated_proportions. Omit when unknown or when only part of the pictured meal was weighed.

Meal context note: pass optional note (up to 280 Unicode characters, e.g. "fried in 1 tbsp olive oil, oat milk") when the user mentioned cooking fats, milk type, sauces, or hidden ingredients a photo cannot show. Both fields are part of the request fingerprint; use a new idempotency key if either changes.

Autonomous wallet payments: REST & MCP with x402

For agents with an authorized Base USDC wallet (EOA wallets, mainnet Base eip155:8453), skip checkout and API keys completely: an unpaid call returns HTTP 402 (or MCP JSON-RPC error -32042) with an x402 v2 payment challenge for 0.01 USDC. Resend with the signed authorization; settlement runs only after a validated food result is saved.

import { closeSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const url = "https://kcalsnap.com/api/v1/analyze";
const photo = "lunch.jpg";
const stateFile = `${photo}.x402.json`; // keep private (mode 0600)
const lockFile = `${stateFile}.lock`;
const body = JSON.stringify({
  image_base64: readFileSync(photo).toString("base64"),
  mime_type: "image/jpeg",
  language: "en",
});

// Serialize signing with an exclusive lock and publish state atomically so
// concurrent runs or retries after a lost response never sign twice.
const lockFd = openSync(lockFile, "wx", 0o600);
let saved;
try {
  try {
    saved = JSON.parse(readFileSync(stateFile, "utf8"));
  } catch (e) {
    if (e.code !== "ENOENT") throw e;
    const challengeRes = await fetch(url, { method: "POST" });
    if (challengeRes.status !== 402) throw Error(`Expected 402, got ${challengeRes.status}`);
    const challenge = await challengeRes.json();
    const signer = privateKeyToAccount(process.env.AGENT_WALLET_KEY);
    const client = new x402Client()
      .setSpendControls({ maxAmountPerPayment: "$0.01" })
      .register("eip155:8453", new ExactEvmScheme(signer));
    const payload = await client.createPaymentPayload(challenge);
    saved = {
      requestId: crypto.randomUUID(),
      paymentSignature: Buffer.from(JSON.stringify(payload)).toString("base64"),
    };
    const tmp = `${stateFile}.${process.pid}.tmp`;
    writeFileSync(tmp, JSON.stringify(saved), { mode: 0o600 });
    renameSync(tmp, stateFile);
  }
} finally {
  closeSync(lockFd);
  unlinkSync(lockFile);
}

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": saved.requestId,
    "PAYMENT-SIGNATURE": saved.paymentSignature,
  },
  body,
});
console.log(response.status, await response.json());

Configure your client's spending policy before enabling automatic payments. For recovery after a lost response, persist the original Idempotency-Key and signed PAYMENT-SIGNATURE. Do not sign a fresh payment for a pending request.

Useful estimates, with measured limits

A photo cannot reveal exact portion weight, cooking oil, or hidden ingredients. Use KcalSnap for food logging and meal summaries, not medical nutrition therapy or allergen safety.

Our September 2026 baseline benchmark used matcher v4 on 48 source groups from Nutrition5k (two passes, KcalSnap baseline model):

MeasureObserved result (historical v4 baseline)
Calories within 25% of reference50.0% of 96 outcomes
Median absolute calorie percentage error25.1%
Mean absolute calorie error103 kcal
Warm nutrition-pipeline median / p952.04 s / 3.36 s

Production now uses matcher v8 and a bundled local USDA FoodData Central table (removing external FDC network hops). The table above records the historical v4 baseline, not a new v8 accuracy claim. Read the separate DFood weighed-photo benchmark (matcher v7) and the Nutrition5k matcher audit. model_confidence is the model's own rating, not calibrated accuracy.

Capacity limits and retry rules

Keep the request_id from a result or analysis error when emailing hello@kcalsnap.com. Need higher throughput or custom volume? Email us.

ResponseClient / agent action
200Save the JSON result and read X-Credits-Remaining (or PAYMENT-RESPONSE for x402).
400 / 413 / 415Fix the input. No credit or payment is consumed.
402Out of credits (top up at /developers/credits/) or x402 payment challenge.
409If in_progress, retry unchanged. If idempotency_conflict, keep the original request parameters with that key.
410The 24-hour server result recovery window has expired.
422No food detected. No credit or payment is consumed.
429Capacity, repeated-failure, or spend limit reached. Respect Retry-After; no credit or payment is consumed.
503 payment_pendingx402 only: wait 60 seconds and retry the exact image, key, and signed authorization. Do not pay again.

Shared API capacity: 5,000 new analyses per rolling 24 hours globally, 600 per hour globally, 2,000 per API key or wallet per day, and 20 concurrent analyses (up to 10 per key). Within those totals, x402 has a shared allowance of 200 per rolling day, 30 per hour, and 3 concurrent jobs. After 25 unsuccessful analyses per key/wallet in a rolling day (excluding upstream provider rejections), new requests pause temporarily. Completed results can still be replayed free for 24 hours.

Privacy, images, and payments

KcalSnap does not store submitted images. Photos are sent to OpenRouter and its Gemini provider for recognition; food nutrition lookups run locally against a bundled copy of USDA FoodData Central. Completed result text is kept for 24 hours for safe retries, then purged on later API activity. Request fingerprints and payment records are kept for accounting and retry safety. See our privacy policy.

Card payments are processed by Stripe. KcalSnap stores only SHA-256 key fingerprints, credit balances, and order records – never raw API keys or card numbers. Refunds or disputes pause the affected key for support review. Crypto payments are facilitated by PayAI on Base mainnet. For billing or recovery help, email hello@kcalsnap.com with your request ID, Stripe receipt, or transaction hash – never your API key or private key.