๐ง nutrition-ai (Rust)
Analyze food images using Google Gemini AI with full nutritional breakdown โ written in pure Rust.
๐ Node.js developer? Use the official nutrition-ai npm package.
๐ฝ๏ธ Overview
This crate replicates the functionality of nutrition-ai in Rust.
- ๐ธ Upload food images as base64 (
image/pngorimage/jpeg) - ๐ค Google Gemini AI generates:
- Calorie + macro breakdown per food item
- Total calorie estimation
- Nutritional balance and dietary tips
- ๐ก๏ธ Input validation and error handling
- ๐ Auto-retries on 503 model overloads
๐ Quick Example
use STANDARD;
use Engine;
use ;
async
๐ฅ API Parameters
| Field | Type | Description |
|---|---|---|
file_base64 |
String |
Base64-encoded food image |
file_mime_type |
MimeType enum |
MimeType::ImagePng or MimeType::ImageJpeg |
google_key |
String |
Your Google Gemini API key (get it from makersuite) |
model |
Option<String> |
Optional Gemini model (e.g. "Gemini2_0Flash") |
๐ ๏ธ Supported Models
Gemini1_0ProGemini1_5ProGemini1_5Flash(default)Gemini1_5Flash8BGemini2_0Flash
Default fallback model if none is provided: Gemini1_5Flash
๐งช Error Handling
- โ Empty or invalid base64 input
- โ Unsupported MIME type
- โ Missing Google API key
- ๐ Retries up to 3 times on Gemini API 503 (model overload)
- โ Missing or empty Gemini response content
๐งโ๐ป Author
๐ License
MIT ยฉ 2025