# Vhealth API Documentation

Base URL: https://vhealth-api.sumflowcloud.com/api/v1

## Auth & Personal Access Tokens

JWT access tokens, rotating refresh tokens, user settings, and long-lived scoped PATs (vhl_...).

- `POST /api/v1/auth/register` (Public): Register user, create profile & storage settings, return tokens
- `POST /api/v1/auth/login` (Public): Authenticate and return access + refresh tokens
- `POST /api/v1/auth/refresh` (Public): Rotate refresh token and issue new access token
- `POST /api/v1/auth/logout` (Auth): Revoke submitted refresh token
- `GET / PATCH /api/v1/auth/me` (Auth): Read or update full_name, timezone, and unit_system
- `POST / GET / DELETE /api/v1/auth/tokens` (Auth): Create, list, or revoke scoped Personal Access Tokens (vhl_...)

## Profile & Storage Settings

Nutrition targets, dietary preferences/allergies, and data storage mode selection.

- `GET / PATCH /api/v1/profile` (Free+): Read or partial-merge age, weights, goal_type, diet_type, allergies, and macro targets
- `GET / PUT /api/v1/settings/storage` (Free+): Configure platform, local_sqlite, or encrypted remote_sql storage

## Meals (Intake)

Free structured food & nutrients-only endpoints plus Premium server-LLM plain-English logging.

- `POST /api/v1/meals` (Free+ / MCP): Log itemized structured foods with known or catalog macros (no server LLM)
- `POST /api/v1/meals/nutrients` (Free+ / MCP): Log exact calories, macros & micronutrients directly without food breakdowns (no server LLM)
- `POST /api/v1/meals/log-text` (Premium): Parse plain-English meal descriptions via server LLM (403 premium_required on Free)
- `GET /api/v1/meals` (Free+): List meals with from/to, meal_category, entry_source, search q, and pagination
- `GET / PATCH / DELETE /api/v1/meals/{meal_id}` (Free+): Read, update metadata, or delete owned meal
- `PATCH / DELETE /api/v1/meals/{meal_id}/items/{item_id}` (Free+): Edit portions/macros on one item without deleting the meal
- `GET /api/v1/meals/daily-summary` (Free+ / MCP): Single-day intake, outflow, net calories, targets & remaining in user timezone

## Exercises (Outflow)

Track energy expenditure from wearables, manual entries, MCP agents, or Premium NL parsing.

- `POST /api/v1/exercises` (Free+ / MCP): Log structured workout & exact calories burned (no server LLM)
- `POST /api/v1/exercises/log-text` (Premium): Parse plain-English workouts and estimate burn via server LLM
- `GET / PATCH / DELETE /api/v1/exercises` (Free+): Filter, update, or delete exercise logs by performed_at and activity_type

## Body Metrics, Habits & Dashboard

Longitudinal weight/habit tracking and chart-ready energy balance aggregations.

- `POST / GET / DELETE /api/v1/body-metrics` (Free+ / MCP): Record and query weight_kg, body_fat_pct, and waist_cm time series
- `POST / GET / DELETE /api/v1/habits` (Free+ / MCP): Track water_ml, steps, sleep_hours, or custom habit_key check-ins
- `GET /api/v1/dashboard` (Free+ / MCP): Range series (default month-to-date, month, year, or start/end) by day/week/month

## Usage, Account Export & Phase 2 Premium

Self-serve meters, GDPR/DPDP export/deletion, catalog search, and Premium intelligence.

- `GET /api/v1/usage` (Free+): Inspect plan_tier and current log, storage, MCP, and LLM meter balances
- `GET / DELETE /api/v1/account/export & /account` (Free+): Export all personal logs (JSON/CSV) or permanently delete account
- `GET /api/v1/catalog/foods` (Free+ (Phase 2)): Search verified canonical foods and aliases
- `GET / POST /api/v1/recommendations/daily & /plans/*/generate` (Premium (Phase 2)): Personalized AI diet & exercise recommendations and generated plans
- `PUT /api/v1/settings/branding` (Premium (Phase 2)): Configure white-label display name, primary color, and logo
