Need to calculate daily calorie needs in your nutrition or fitness application? This guide covers everything you need to know about calorie calculation via API, including weight goals, activity levels, and implementation examples in multiple languages.
Understanding Calorie Needs
Daily calorie needs are determined by your Total Daily Energy Expenditure (TDEE), which combines your Basal Metabolic Rate (BMR) with calories burned through activity. To change your weight, you need to create a calorie surplus or deficit.
A deficit of 500 calories per day typically results in about 0.5 kg (1 lb) of weight loss per week, while a surplus of 500 calories leads to similar weight gain.
Calorie Goals Explained
Different goals require different calorie targets:
Weight Loss
Eat below your TDEE. Mild deficit (250 cal) for slow loss, moderate (500 cal) for steady loss, aggressive (750-1000 cal) for rapid loss.
Maintenance
Eat at your TDEE to maintain current weight. Ideal for those happy with their body composition.
Weight Gain / Bulking
Eat above your TDEE. Lean bulk (250-500 cal surplus) minimizes fat gain while building muscle.
Using the Calorie Calculator API
TinyFn provides a simple endpoint to calculate daily calorie needs:
GET https://api.tinyfn.io/v1/health/calories?weight=70&height=175&age=30&gender=male&activity=moderate&goal=lose
Headers: X-API-Key: your-api-key
{
"daily_calories": 2104,
"tdee": 2604,
"bmr": 1680,
"deficit": 500,
"goal": "lose",
"weekly_change_kg": -0.45,
"targets": {
"mild_loss": 2354,
"moderate_loss": 2104,
"aggressive_loss": 1854,
"maintenance": 2604,
"mild_gain": 2854
}
}
Parameters
| Parameter | Type | Description |
|---|---|---|
weight |
number | Weight in kilograms |
height |
number | Height in centimeters |
age |
integer | Age in years |
gender |
string | Gender: male or female |
activity |
string | Activity: sedentary, light, moderate, very_active, extreme |
goal |
string | Goal: lose, maintain, or gain |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/health/calories?weight=70&height=175&age=30&gender=male&activity=moderate&goal=lose',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(`Daily calories: ${data.daily_calories}`); // Daily calories: 2104
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/health/calories',
params={
'weight': 70, 'height': 175, 'age': 30,
'gender': 'male', 'activity': 'moderate', 'goal': 'lose'
},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(f"Daily calories: {data['daily_calories']}, Weekly change: {data['weekly_change_kg']} kg")
cURL
curl "https://api.tinyfn.io/v1/health/calories?weight=70&height=175&age=30&gender=male&activity=moderate&goal=lose" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Diet Apps: Set daily calorie budgets for users
- Meal Planning Services: Generate meal plans within calorie limits
- Fitness Coaching: Create nutrition plans for clients
- Health Tracking: Monitor calorie intake vs. needs
- Weight Loss Programs: Calculate sustainable deficits
Best Practices
- Start conservative: Begin with mild deficits and adjust based on results
- Recalculate regularly: Update as weight changes significantly
- Set minimum floors: Never go below 1200 (women) or 1500 (men) calories
- Track progress: Compare predictions with actual weight changes
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-health": {
"url": "https://api.tinyfn.io/mcp/health/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all health tools available via MCP in our Health MCP Tools for AI Agents guide.
Try the Calorie Calculator API
Get your free API key and start calculating calories in seconds.
Get Free API Key