Skip to main content

About

The Spike SDK provides a convenient interface for the Nutrition AI API, allowing you to analyze food images directly from your React Native application. The SDK handles image encoding, API communication, and response parsing, making it easy to integrate nutritional analysis into your app.
All Spike SDK async methods return Promises. Use try-catch blocks or .catch() handlers for error handling. See Error Handling for details.

Key Features

  • AI-Powered Analysis — advanced computer vision for food identification and nutritional calculations
  • Flexible Processing — choose between synchronous (wait for results) or asynchronous (background) processing
  • Base64 Support — submit images as base64-encoded strings
  • Complete Record Management — retrieve, update, and delete nutrition records

Available Methods

Analyzing Food Images

Synchronous Processing

Use synchronous analysis when you want to wait for the complete nutritional analysis before proceeding. This is ideal for scenarios where you need immediate results and can display a loading indicator.
You can also call with minimal parameters (config is optional):
Processing Time: Synchronous processing takes some time depending on image complexity. Consider showing a loading indicator to users. If you see that the analysis is taking too long, the recommendation is to use asynchronous processing instead.

Asynchronous Processing

Use asynchronous processing when you want an immediate response without waiting for the analysis to complete. Record ID is returned. The image is processed in the background, and you can retrieve results later by requesting nutrition analysis using the record ID or receive them via webhook.

Retrieving Results Asynchronously

After submitting an image for asynchronous processing, you can retrieve the results using the record ID. Check the processing status for completion success.
For real-time notifications, configure webhooks in your admin console. Your backend will receive a webhook notification when the analysis completes. See Asynchronous Processing for webhook implementation details.

Configuration Options

Customize the analysis using NutritionalAnalysisConfig:

NutritionalAnalysisConfig

Analysis Modes

Default Nutritional Fields

If includeNutritionFields is not specified, only these basic fields are included:
  • energyKcal
  • proteinG
  • fatTotalG
  • carbohydrateG
See Nutritional Fields Reference for all available fields.

Managing Nutrition Records

List Records by Date Range

Retrieve all nutrition records within a specified date range:

Get a Specific Record

Retrieve a single nutrition record by its ID:

Update Serving Size

Adjust the serving size of an existing record. All nutritional values are automatically recalculated proportionally:

Delete a Record

Permanently remove a nutrition record (success status is returned regardless record is found or not):

Response Data

NutritionRecord

The NutritionRecord interface contains the analysis results:

NutritionRecordStatus

NutritionalUnit

NutritionRecordIngredient

NutritionalField

Use this enum to specify which nutritional fields to include in the analysis:

Error Handling

All nutrition methods return Promises that can reject with errors. Always use try-catch blocks or .catch() handlers:

Common Error Scenarios

Image Guidelines

For optimal analysis results, guide your users to capture images that:
  1. Center the food — capture the plate contents as the main subject
  2. Fill the frame — ensure the meal occupies most of the image
  3. Use proper lighting — natural or bright lighting works best
  4. Avoid obstructions — remove packaging and minimize utensils in frame
  5. Skip filters — avoid filters that alter the food’s appearance
See Image Guidelines for complete recommendations.

Best Practices

1. Request Only What You Need

Each additional field, ingredient breakdown, or optional data increases processing time. Only request what your app actually uses:

2. Consider your actual UI requirements:

  • Do you display ingredients? If not, skip includeIngredients.
  • Do you show Nutri-Score? If not, skip includeNutriScore.
  • Which nutritional values do you actually display? Request only those.

3. Choose the Right Processing Mode

  • Synchronous (analyzeNutrition): Use when you need immediate results and can show a loading state
  • Asynchronous (submitNutritionForAnalysis): Use for better UX when you don’t need immediate results, or when processing multiple images

4. Handle All Status Values

When using asynchronous processing, always check the record status before accessing results:

5. Implement Webhook Handling

For production apps using asynchronous processing, implement webhook handling on your backend to receive real-time notifications when analysis completes.

6. Create Reusable Configuration

If you’re using the same settings across your app, create a shared configuration helper:

7. Use React State for Loading UI