API Reference

Authentication

API Key Authentication

All requests require your API key in the Authorization header as a Bearer token.

Header Format:
Authorization: Bearer YOUR_API_KEY
Base URL: https://tastyapi.com

API Endpoints

POST

/analyze-image

Analyze food images for nutrition data

Image Upload AI Analysis
POST

/analyze-food

Get nutrition data by food name

Text Input Quick Analysis
GET

/api/usage

Check your subscription usage

Usage Stats Real-time
POST

/api/subscription/cancel

Cancel your subscription

Account Management
POST /analyze-image

Analyze a food image and get detailed nutritional information using AI.

Headers

Authorization string required

Bearer token: Bearer YOUR_API_KEY

Body (multipart/form-data)

image file required

JPEG or PNG image file of food

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" }
    },
    "dietaryInfo": {
      "isVegetarian": false,
      "isVegan": false,
      "isGlutenFree": true
    }
  }
}

Error Responses

400 No image file provided
401 Invalid or expired API key

cURL

curl -X POST https://tastyapi.com/analyze-image 
									 -H "Authorization: Bearer YOUR_API_KEY" 
									 -F "image=@path/to/food.jpg"
									

JavaScript

const formData = new FormData();
formData.append('image', fileInput.files[0]);

const response = await fetch('/analyze-image', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
  body: formData
});

const data = await response.json();
POST /analyze-food

Get nutritional information for food items by name.

Headers

Authorization string required

Bearer token: Bearer YOUR_API_KEY

Content-Type string required

Must be application/json

Body (JSON)

foodName string required

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" }
    },
    "dietaryInfo": {
      "isVegetarian": false,
      "isVegan": false,
      "isGlutenFree": false
    }
  }
}

cURL

curl -X POST https://tastyapi.com/analyze-food   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"foodName": "grilled chicken salad"}'

JavaScript

const response = await fetch('/analyze-food', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    foodName: 'grilled chicken salad'
  })
});

const data = await response.json();
GET /api/usage

Check your subscription usage statistics and remaining API calls.

Headers

Authorization string required

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}`);
POST /api/subscription/cancel

Cancel your active subscription. Takes effect at the end of your current billing period.

Headers

Authorization string required

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

foodName string Detected food name
servingSize object Serving size info
nutrients object Nutritional data
dietaryInfo object Diet compatibility

Usage Response

Structure returned by /api/usage

status string Account status
plan string Subscription plan
usage object Usage statistics
subscription object Subscription details

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);
?>