Food API

Food API

Search foods by name or barcode and get their nutrition facts, from FatSecret and OpenFoodFacts data. v2 answers from our own food catalog, with typo-tolerant search and typed values, and is recommended for new integrations. v1 remains supported for existing apps.

Base URL https://api.studio93.io

Two ways to use it

HTTPS onlyEvery request goes to the base URL over HTTPS.
API key requiredSend Authorization: Bearer <key> on every endpoint.
JSON responsesErrors share one shape: {"message": "…", "data": {}}.
Compressedv2 responses are compressed by default; HTTP clients handle it for you.

Authentication

Send your API key in the Authorization header. A missing or invalid key gets 401 Unauthorized; admin endpoints answer 403 Forbidden to keys other than the ADMIN key.

Each key is for one API version: a v2 key calls /v2/… (and the SDKs), a v1 key calls /food/…. Using a key on the other version gets 403 Forbidden. A v2 key can also have regional ranking, which puts one country's foods first among equally good search matches: the user's country, found from the IP address of each request, or one country set on the key.

Calling from a server. When your server calls the API for its users, send each user's IP address in the X-Client-IP header, so search ranks for the user's country instead of your server's. It works on every v2 endpoint and only chooses the country: rate limits still count the address requests come from. An address that isn't IPv4 or IPv6 gets 400. Apps that call the API directly don't need it.

X-Client-IP: 81.2.69.160
Authorization: Bearer <api-key>

Keys are issued per app by a Studio93 admin in the dashboard, where each key's usage is visible and keys can be revoked. There is no sign-up. A revoked key gets 401 right away.

Try requests from this page

Kept only in this browser tab, and sent only to this API.

SDKs

The Flutter and Go SDKs call v2 for you, with a v2 API key (see Authentication). Load the key from your app's configuration and don't commit it. Each endpoint below shows its SDK call next to the REST request. Source, guides and changes: github.com/Studio93-Org/food-api-sdk.

Flutter

Flutter 3.38+ (iOS 15+, macOS 12+, Android minSdk 24, web). It uses the platform's own HTTP stack (URLSession on iOS and macOS, Cronet on Android). Add it to pubspec.yaml:

dependencies:
  studio93_food_api:
    git:
      url: https://github.com/Studio93-Org/food-api-sdk.git
      path: dart
      ref: dart-v0.3.0
import 'package:studio93_food_api/studio93_food_api.dart';

final foodApi = FoodApiClient(apiKey: apiKey); // One client for the whole app

final page = await foodApi.search('greek yogurt'); // Typos are fine: 'chiken brest' works
for (final food in page.foods) {
  print('${food.name}: ${food.servings.first.nutrients.calories} kcal');
}

// Search as the user types: one session per screen; a new search cancels the one in flight
final session = foodApi.session();
final results = await session.search(text);

Go

Go 1.23+, no dependencies. For servers and tools:

go get github.com/Studio93-Org/food-api-sdk/go@v0.3.0
import foodapi "github.com/Studio93-Org/food-api-sdk/go"

client := foodapi.New(apiKey) // One client for the whole service

page, err := client.Search(ctx, "greek yogurt", nil)
if err != nil {
	return err
}
for _, food := range page.Foods {
	kcal, _ := food.Servings[0].Nutrients.Get(foodapi.Calories)
	fmt.Println(food.Name, kcal)
}

// Calling for one of your users: search ranks for their country, not your server's
ctx = foodapi.WithClientIP(ctx, userIP) // Sent as X-Client-IP

What the SDKs take care of

  • One shared client keeps connections open, so only the first request pays for connecting.
  • A newer search cancels the one still in flight (Flutter: FoodSearchSession; Go: cancel the context).
  • Network errors, timeouts and 429, 502, 503 and 504 answers are retried twice, waiting as long as Retry-After asks.
  • Typed errors: "not found" is an answer, apart from "rate limited", "unavailable" and "offline". Invalid arguments fail before a request.
  • Nutrients are numbers (null when unknown), with flags for values that aren't plain measurements.

The SDKs are for v2 only. v1 is available over REST for existing apps.

Endpoints

Operations & admin

Health checks, the stats page and maintenance. Admin endpoints need the ADMIN key.

Errors

Errors use the same shape as successful v1 responses, with the reason in message.

StatusMeaning
400 Bad RequestA parameter is missing or invalid.
401 UnauthorizedThe API key is missing or invalid.
403 ForbiddenThe API key is for the other API version (v1 or v2), or isn't allowed to use an admin endpoint.
404 Not FoundNo provider has data for the requested food.
502 Bad GatewayA food data provider (FatSecret or OpenFoodFacts) failed; retrying later may succeed.
503 Service Unavailablev2 only: the food catalog isn't available, or search is busy. Retry after the number of seconds in the Retry-After header.
429 Too Many RequestsMore than 50 requests per second (bursts up to 200) from one app and IP address (the address requests come from, whatever X-Client-IP says). Slow down and retry.
500 Internal Server ErrorAn unexpected server error.