Skip to content

TDEE and Macro Calculator API: Add Calorie Needs to Any Fitness App

Published June 14, 2026

A TDEE calculator API (Total Daily Energy Expenditure) takes a user's age, weight, height, activity level, and goal and returns their daily calorie needs plus protein, carbohydrate, and fat targets, with no formula to implement on your side. Instead of embedding the Mifflin-St Jeor equation into every app you ship, you call one endpoint and render the result.

This guide shows how the macro calculator API works, what the response structure looks like, and how to integrate it into a React, Swift, or Python app.

Why Use an API Instead of Implementing the Formula Yourself

The Mifflin-St Jeor BMR formula is simple on its own:

BMR (male)   = (10 × weight_kg) + (6.25 × height_cm) − (5 × age) + 5
BMR (female) = (10 × weight_kg) + (6.25 × height_cm) − (5 × age) − 161
TDEE         = BMR × activity_multiplier

But production apps add goal-adjusted targets, macro splits, unit conversions, edge-case validation, and versioning as nutrition science evolves. Offloading calorie needs calculation to an API keeps that logic centralised and consistent across your web, iOS, and Android clients.

The Endpoint

GET /api/v1/public/calc/macros

Parameters:

ParameterTypeExampleNotes
ageinteger281–120
genderstringmalemale or female
weight_kgfloat80Body weight in kilograms
height_cmfloat178Height in centimetres
activitystringmoderately_activeSee activity levels below
goalstringloselose, maintain, or gain

Activity levels:

ValueDescription
sedentaryDesk job, little or no exercise
lightly_active1–3 light workouts per week
moderately_active3–5 moderate workouts per week
very_active6–7 hard workouts per week
extra_activePhysical job or twice-daily training

Quick Start

curl "https://api.calorieapi.com/api/v1/public/calc/macros\
?age=28&gender=male&weight_kg=80&height_cm=178\
&activity=moderately_active&goal=lose"

Response:

{
  "bmr": 1778,
  "tdee": 2756,
  "activity_multiplier": 1.55,
  "daily_targets": {
    "calories": 2204,
    "protein_g": 144.0,
    "carbohydrates_g": 220.5,
    "fat_g": 61.2
  },
  "formula": "Mifflin-St Jeor"
}

The daily_targets.calories field is tdee × 0.80 for goal=lose, tdee for maintain, and tdee × 1.10 for gain. Protein is set at 1.8 g/kg for cut and bulk phases (muscle-sparing) and 1.6 g/kg for maintenance. Fat fills 25 % of goal calories; carbohydrates fill the remainder.

Integrating in JavaScript / React

async function getCalorieTargets({ age, gender, weightKg, heightCm, activity, goal }) {
  const params = new URLSearchParams({ age, gender, weight_kg: weightKg,
    height_cm: heightCm, activity, goal });
  const res = await fetch(
    `https://api.calorieapi.com/api/v1/public/calc/macros?${params}`
  );
  if (!res.ok) throw new Error(`Calc failed: ${res.status}`);
  return res.json();
}

// Display in a React component
const targets = await getCalorieTargets({
  age: 28, gender: 'male', weightKg: 80, heightCm: 178,
  activity: 'moderately_active', goal: 'lose'
});

console.log(`Daily calories: ${targets.daily_targets.calories}`);
console.log(`Protein: ${targets.daily_targets.protein_g}g`);

Integrating in Swift (iOS)

struct MacroTargets: Codable {
  let bmr: Int
  let tdee: Int
  let dailyTargets: DailyTargets

  struct DailyTargets: Codable {
    let calories: Int
    let proteinG: Double
    let carbohydratesG: Double
    let fatG: Double
  }
}

func fetchCalorieTargets(age: Int, gender: String, weightKg: Double,
                          heightCm: Double, activity: String, goal: String) async throws -> MacroTargets {
  var components = URLComponents(string: "https://api.calorieapi.com/api/v1/public/calc/macros")!
  components.queryItems = [
    .init(name: "age", value: "\(age)"),
    .init(name: "gender", value: gender),
    .init(name: "weight_kg", value: "\(weightKg)"),
    .init(name: "height_cm", value: "\(heightCm)"),
    .init(name: "activity", value: activity),
    .init(name: "goal", value: goal),
  ]
  let (data, _) = try await URLSession.shared.data(from: components.url!)
  return try JSONDecoder().decode(MacroTargets.self, from: data)
}

Displaying Results in Your UI

Map the response fields to progress bars or ring charts:

API fieldUI element
daily_targets.caloriesTotal calorie goal badge
daily_targets.protein_gProtein progress bar (fill from food log)
daily_targets.carbohydrates_gCarb progress bar
daily_targets.fat_gFat progress bar
tdee"Your maintenance calories" tooltip
bmr"Calories burned at rest" info line

Recalculating as the User Updates Their Profile

Call the endpoint whenever the user saves a profile change. Store the returned daily_targets in your local state or database so the rest of the app can reference it without another API call.

import httpx

def get_macro_targets(profile: dict) -> dict:
    r = httpx.get("https://api.calorieapi.com/api/v1/public/calc/macros", params={
        "age": profile["age"],
        "gender": profile["gender"],
        "weight_kg": profile["weight_kg"],
        "height_cm": profile["height_cm"],
        "activity": profile["activity_level"],
        "goal": profile["goal"],
    })
    r.raise_for_status()
    return r.json()

Try It Live

The API Playground lets you enter your stats and see the full JSON response before writing a line of code.

Get your free API key | Read the full docs

Frequently Asked Questions

What is a TDEE calculator API?

A TDEE calculator API takes body stats (age, weight, height, activity level, goal) and returns the user's Total Daily Energy Expenditure and daily macro targets using the Mifflin-St Jeor formula.

How do I add macro targets to my fitness app?

Call GET /api/v1/public/calc/macros with the user's profile. The response includes daily calories, protein, carbohydrates, and fat targets. Display them as progress bars filled by the food log.

Which BMR formula does the API use?

The API uses the Mifflin-St Jeor equation, the most widely validated formula for healthy adults. The formula field in the response confirms this.

How are macro targets calculated?

Protein is set at 1.8 g/kg for lose and gain goals (muscle-sparing), 1.6 g/kg for maintenance. Fat is 25% of goal calories. Carbohydrates fill the remaining calories.

Does the API support metric and imperial units?

The endpoint accepts metric units (kg, cm). Convert pounds to kilograms by dividing by 2.205, and inches to centimetres by multiplying by 2.54 before calling the endpoint.

← Back to all articles

Start building with the Calorie API

Get a free API key and access 4M+ foods with search, barcode lookup, and full macro data.