Habit AIHabit AI
REST API

Habit AI API

Public REST API for the Habit AI platform. Track meals, nutrition, weight, steps, meditation, journaling, and chat with AI coaches.

Base URL: https://habitapp.ai

Authentication

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

Authorization: Bearer hab_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Getting an API Key

Bootstrap your first API key by clicking on 'Sign in' on this page. Then go to the Settings page and click on 'Get API Key'.

The API key is returned once and cannot be retrieved again. Store it securely. Max 5 active keys per user.

Profile

GET/api/v1/profile

Get your user profile.

PUT/api/v1/profile

Update profile fields.

{
  "displayName": "string",
  "timezone": "America/New_York",
  "heightInCm": 175,
  "weightInKg": 70,
  "gender": "male",
  "caloriesGoal": 2000,
  "proteinGoal": 150,
  "diet": "classic",
  "activityLevel": "moderatelyActive"
}

Meals

GET/api/v1/meals

List meal scans.

Query Parameters

  • date - YYYY-MM-DD (optional)
  • limit - max 100 (default 20)
  • offset - pagination offset
POST/api/v1/meals

Create a meal entry.

{
  "mealName": "Grilled Chicken Bowl",
  "calories": 500,
  "protein": 30,
  "carbs": 50,
  "fat": 15,
  "mealType": "lunch",
  "ingredients": [
    { "name": "Chicken", "amount": 200, "unit": "g", "calories": 330 }
  ]
}
GET/api/v1/meals/:id

Get a specific meal.

PUT/api/v1/meals/:id

Update a meal.

DELETE/api/v1/meals/:id

Delete a meal.

Nutrition

GET/api/v1/nutrition/daily

Get daily consumption summary.

Query Parameters

  • date - YYYY-MM-DD (defaults to today)
GET/api/v1/nutrition/weekly

Get 7-day nutrition summary.

Query Parameters

  • date - YYYY-MM-DD end date (defaults to today)

Water Tracking

POST/api/v1/water

Add water intake.

{ "amount": 250, "date": "2025-01-15" }

Steps

GET/api/v1/steps

Get steps history.

Query Parameters

  • days - number of days (default 7, max 90)
POST/api/v1/steps

Log steps for a date.

{ "steps": 8500, "date": "2025-01-15" }

Weight

GET/api/v1/weight

Get weight history.

Query Parameters

  • days - number of days (default 30, max 365)
POST/api/v1/weight

Log a weight entry.

{ "weightInKg": 72.5, "date": "2025-01-15" }
DELETE/api/v1/weight/:id

Delete a weight entry.

Journal

GET/api/v1/journal

List journal entries.

Query Parameters

  • limit - max 100 (default 20)
  • offset - pagination offset
POST/api/v1/journal

Create a journal entry.

{ "content": "Today I felt...", "mood": "happy" }
DELETE/api/v1/journal/:id

Delete a journal entry.

Meditation

GET/api/v1/meditation

List meditation sessions.

Query Parameters

  • limit - max 100 (default 20)
  • offset - pagination offset
POST/api/v1/meditation

Log a meditation session.

{ "durationInMinutes": 15, "type": "guided", "notes": "Breathing focus" }
DELETE/api/v1/meditation/:id

Delete a session.

Saved Meals

GET/api/v1/saved-meals

List saved meal templates.

Query Parameters

  • limit - max 100 (default 20)
  • offset - pagination offset
POST/api/v1/saved-meals

Save a meal as a template.

{
  "name": "Morning Oatmeal",
  "calories": 350,
  "protein": 12,
  "carbs": 55,
  "fat": 8
}
DELETE/api/v1/saved-meals/:id

Delete a saved meal.

AI Analysis

POST/api/v1/analyze/food-image

Analyze a food image with AI.

{ "imageBase64": "<base64_encoded_image>", "mealType": "lunch" }
POST/api/v1/analyze/meal-description

Analyze a text description of a meal.

{ "description": "Grilled chicken with rice and broccoli", "mealType": "dinner" }

AI Coaches

POST/api/v1/coaches/eating

Chat with the eating coach.

{
  "message": "What should I eat for dinner?",
  "conversationHistory": [
    { "role": "user", "content": "I had oatmeal for breakfast" },
    { "role": "assistant", "content": "Great start! ..." }
  ]
}
POST/api/v1/coaches/mindfulness

Chat with the mindfulness coach.

{ "message": "I'm feeling stressed today" }
POST/api/v1/coaches/meditation

Chat with the meditation coach.

{ "message": "Can you guide me through a 5-minute meditation?" }

API Key Management

POST/api/v1/keys

Create a new API key (accepts Firebase ID token or existing API key).

{ "name": "My App Key" }
GET/api/v1/keys

List your active API keys.

DELETE/api/v1/keys/:id

Revoke an API key.

Error Handling

All errors follow a consistent format:

{ "error": "Description of the error" }
400Bad request — missing or invalid parameters
401Unauthorized — missing or invalid API key
403Forbidden — not authorized to access this resource
404Not found — resource does not exist
500Internal server error
503Service unavailable — AI features not configured