Authentication
API Key Authentication
All requests require your API key in the Authorization header as a Bearer token.
Authorization: Bearer YOUR_API_KEY
https://tastyapi.com
Multi-Language Support
Localized Responses
Get nutritional insights in your preferred language. All text content including food names, recommendations, tips, and descriptions can be returned in 8 supported languages.
Supported Languages
en- English (default)es- Spanishfr- Frenchde- Germanit- Italianpt- Portuguesear- Arabictr- Turkish
How to Request a Language
You can specify your preferred language using either method:
POST /analyze-image?lang=es
Accept-Language: ar
What Gets Translated
Translated:
- Food names
- Meal timing recommendations
- Satiety descriptions
- Blood sugar predictions
- Digestibility timelines
- Absorption tips
- Allergen names
- Ingredient lists
Kept in English:
- JSON field names/keys
- Units (kcal, g, mg, mcg)
- Grades (A+, A, B, C, D, F)
- Numeric values
- Boolean values
Example Response (Spanish)
{
"analysis": {
"foodName": "Ensalada de Pollo a la Parrilla",
"mealTiming": {
"recommendation": "Mejor consumir 2-3 horas antes del entrenamiento",
"optimalTime": "almuerzo"
},
"satietyScore": {
"score": 8,
"description": "Muy saciante debido al alto contenido de proteinas y fibra"
},
"absorptionTips": [
"Consumir con grasas saludables para mejorar la absorcion de vitaminas"
]
},
"language": "es"
}
API Endpoints
/analyze-image
Analyze food images for nutrition data
/analyze-food
Get nutrition data by food name
/api/usage
Check your subscription usage
/api/subscription/cancel
Cancel your subscription
Analyze a food image and get detailed nutritional information using AI.
Query Parameters
Language code for response text. Supported: en (default), es, fr, de, it, pt, ar, tr
Headers
Bearer token: Bearer YOUR_API_KEY
Alternative to lang query param. E.g., es-ES, fr
Body Option 1: multipart/form-data
JPEG or PNG image file of food
Body Option 2: application/json
Base64 encoded image. Supports data URI format (data:image/jpeg;base64,...) or raw base64 string.
Success Response (200 OK)
{
"analysis": {
"foodName": "Grilled Chicken Salad",
"servingSize": {
"amount": 250,
"unit": "g"
},
"nutrients": {
"calories": { "amount": 350, "unit": "kcal" },
"protein": { "amount": 30, "unit": "g" },
"carbohydrates": { "amount": 15, "unit": "g" },
"fat": { "amount": 20, "unit": "g" }
},
"allergens": {
"contains": ["milk"],
"mayContain": ["wheat"]
},
"celiacCrossContaminationRisk": "Low when prepared on dedicated surfaces...",
"histamineIntoleranceRisk": "Moderate due to leafy greens and aged cheese...",
"dietaryInfo": {
"isVegetarian": false,
"isVegan": false,
"isGlutenFree": true
}
},
"language": "en"
}
Multi-Language Example (Spanish)
{
"analysis": {
"foodName": "Ensalada de Pollo a la Parrilla",
"mealTiming": {
"recommendation": "Mejor consumir 2-3 horas antes del entrenamiento",
"optimalTime": "almuerzo"
},
"absorptionTips": [
"Consumir con grasas saludables para mejorar la absorcion de vitaminas"
]
},
"language": "es"
}
Error Responses
cURL (English - default)
curl -X POST https://tastyapi.com/analyze-image \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@path/to/food.jpg"
cURL (Spanish via query param)
curl -X POST "https://tastyapi.com/analyze-image?lang=es" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@path/to/food.jpg"
cURL (Arabic via header)
curl -X POST https://tastyapi.com/analyze-image \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Accept-Language: ar" \
-F "image=@path/to/food.jpg"
JavaScript (FormData)
const formData = new FormData();
formData.append('image', fileInput.files[0]);
// With language parameter
const response = await fetch('/analyze-image?lang=es', {
method: 'POST',
headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
body: formData
});
const data = await response.json();
console.log(data.language); // "es"
cURL (Base64)
curl -X POST https://tastyapi.com/analyze-image \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"image": "data:image/jpeg;base64,/9j/4AAQ..."}'
JavaScript (Base64)
// From canvas element
const base64 = canvas.toDataURL('image/jpeg');
const response = await fetch('/analyze-image', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ image: base64 })
});
const data = await response.json();
Get nutritional information for food items by name.
Query Parameters
Language code for response text. Supported: en (default), es, fr, de, it, pt, ar, tr
Headers
Bearer token: Bearer YOUR_API_KEY
Must be application/json
Alternative to lang query param. E.g., es-ES, fr
Body (JSON)
Name of the food to analyze (e.g., "cheeseburger")
Success Response (200 OK)
{
"analysis": {
"foodName": "Cheeseburger",
"servingSize": {
"amount": 200,
"unit": "g"
},
"nutrients": {
"calories": { "amount": 540, "unit": "kcal" },
"protein": { "amount": 25, "unit": "g" },
"carbohydrates": { "amount": 40, "unit": "g" },
"fat": { "amount": 31, "unit": "g" }
},
"allergens": {
"contains": ["wheat", "milk", "soy"],
"mayContain": ["sesame"]
},
"celiacCrossContaminationRisk": "High unless buns and cooking surfaces are certified...",
"histamineIntoleranceRisk": "High because of aged cheese and processed meats...",
"dietaryInfo": {
"isVegetarian": false,
"isVegan": false,
"isGlutenFree": false
}
},
"language": "en"
}
cURL (English - default)
curl -X POST https://tastyapi.com/analyze-food \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: text/plain" \
-d 'grilled chicken salad'
cURL (French via query param)
curl -X POST "https://tastyapi.com/analyze-food?lang=fr" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: text/plain" \
-d 'grilled chicken salad'
JavaScript
// With language parameter for German response
const response = await fetch('/analyze-food?lang=de', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'text/plain'
},
body: 'grilled chicken salad'
});
const data = await response.json();
console.log(data.language); // "de"
Check your subscription usage statistics and remaining API calls.
Headers
Bearer token: Bearer YOUR_API_KEY
Success Response (200 OK)
{
"status": "active",
"plan": "Professional",
"usage": {
"total": 15000,
"used": 1247,
"remaining": 13753,
"percentUsed": 8.31
},
"subscription": {
"created": "2024-01-15T10:30:00Z",
"expires": "2024-02-15T10:30:00Z",
"daysRemaining": 18
}
}
cURL
curl -X GET https://tastyapi.com/api/usage -H "Authorization: Bearer YOUR_API_KEY"
JavaScript
const response = await fetch('/api/usage', {
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
});
const usage = await response.json();
console.log(`Used: ${usage.usage.used}/${usage.usage.total}`);
Cancel your active subscription. Takes effect at the end of your current billing period.
Headers
Bearer token: Bearer YOUR_API_KEY
Success Response (200 OK)
{
"success": true,
"message": "Subscription cancelled successfully.",
"cancellationEffective": "2024-02-15T10:30:00Z"
}
cURL
curl -X POST https://tastyapi.com/api/subscription/cancel -H "Authorization: Bearer YOUR_API_KEY"
JavaScript
const response = await fetch('/api/subscription/cancel', {
method: 'POST',
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
});
const result = await response.json();
console.log(result.message);
Response Format
Analysis Response
Structure returned by both /analyze-image and /analyze-food
Usage Response
Structure returned by /api/usage
SDK & Code Examples
// TastyAPI JavaScript Client
class TastyAPI {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseURL = 'https://tastyapi.com';
}
async analyzeImage(imageFile) {
const formData = new FormData();
formData.append('image', imageFile);
const response = await fetch(`${this.baseURL}/analyze-image`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${this.apiKey}` },
body: formData
});
return response.json();
}
async analyzeFood(foodName) {
const response = await fetch(`${this.baseURL}/analyze-food`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ foodName })
});
return response.json();
}
async getUsage() {
const response = await fetch(`${this.baseURL}/api/usage`, {
headers: { 'Authorization': `Bearer ${this.apiKey}` }
});
return response.json();
}
}
// Usage
const api = new TastyAPI('your-api-key');
const result = await api.analyzeFood('grilled chicken salad');
console.log(result);
# TastyAPI Python Client
import requests
import json
class TastyAPI:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'https://tastyapi.com'
self.headers = {'Authorization': f'Bearer {api_key}'}
def analyze_image(self, image_path):
with open(image_path, 'rb') as f:
files = {'image': f}
response = requests.post(
f'{self.base_url}/analyze-image',
headers=self.headers,
files=files
)
return response.json()
def analyze_food(self, food_name):
data = {'foodName': food_name}
response = requests.post(
f'{self.base_url}/analyze-food',
headers={**self.headers, 'Content-Type': 'application/json'},
json=data
)
return response.json()
def get_usage(self):
response = requests.get(
f'{self.base_url}/api/usage',
headers=self.headers
)
return response.json()
# Usage
api = TastyAPI('your-api-key')
result = api.analyze_food('grilled chicken salad')
print(result)
# Analyze Image
curl -X POST https://tastyapi.com/analyze-image -H "Authorization: Bearer YOUR_API_KEY" -F "image=@path/to/food.jpg"
# Analyze Food by Name
curl -X POST https://tastyapi.com/analyze-food -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"foodName": "grilled chicken salad"}'
# Check Usage
curl -X GET https://tastyapi.com/api/usage -H "Authorization: Bearer YOUR_API_KEY"
# Cancel Subscription
curl -X POST https://tastyapi.com/api/subscription/cancel -H "Authorization: Bearer YOUR_API_KEY"
apiKey = $apiKey;
}
private function getHeaders() {
return [
'Authorization: Bearer ' . $this->apiKey
];
}
public function analyzeImage($imagePath) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseURL . '/analyze-image');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders());
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'image' => new CURLFile($imagePath)
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
public function analyzeFood($foodName) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseURL . '/analyze-food');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge(
$this->getHeaders(),
['Content-Type: application/json']
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'foodName' => $foodName
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
}
// Usage
$api = new TastyAPI('your-api-key');
$result = $api->analyzeFood('grilled chicken salad');
print_r($result);
?>