Foods
Use user.foods to autocomplete, search, fetch a full food, look up barcodes, and suggest alternatives. To turn a typed or spoken meal description into foods, use user.foodAnalysis.analyzeDescription (Food analysis).
import ai.january.partner.foods.AutocompleteFoodsRequest
val suggestions = user.foods.autocomplete(AutocompleteFoodsRequest("ban"))Search and fetch the full food
Selecting a suggestion should fill the search field and run search. Search rows may not list every serving, so fetch the full food with get before opening a serving picker:
import ai.january.partner.foods.GetFoodRequest
import ai.january.partner.foods.SearchFoodsRequest
import ai.january.partner.foods.portion
val results = user.foods.search(SearchFoodsRequest("banana"))
val food = user.foods.get(GetFoodRequest(results.items.first().id))
val portion = food.portion() // One primary servingportion validates the serving and quantity and scales nutrients locally (Food discovery and servings). To use another amount, pass quantity in the serving's unit, not a number of servings (Quantity and servings).
Search returns up to limit results (1–50, default 10). To page, pass offset; a page shorter than limit is the last one. totalCount is the number of results in this page, not the total number of matches.
val secondPage = user.foods.search(SearchFoodsRequest("banana", limit = 10, offset = 10))Barcodes and alternatives
lookupBarcode returns one food. Fetch the full food with get before showing servings, as the native scanner does. A barcode with no match fails with ErrorCategory.NOT_FOUND. Barcode coverage is US-only: a code issued outside the United States (for example GS1 prefixes 73, 64, 54, or 93) isn't in the database. For those, analyze a photo of the label (Food analysis) or use food search.
Each alternative lists the servings its nutrition can be read against.
Last updated
Was this helpful?