# Vhealth Client Builder Guide (Agent-Ready Specification)

> Generated from `web/config/*.json` (2026-11-27, build d243d7b04efa). Hand this single file to your AI coding agent to build a Web, Android, iOS, or CLI frontend on top of Vhealth.

## 1. Endpoints & Auth
- **API Base URL:** `https://vhealth-api.sumflowcloud.com/api/v1`
- **Swagger / OpenAPI:** `https://vhealth-api.sumflowcloud.com/docs` / `https://vhealth-api.sumflowcloud.com/openapi.json`
- **MCP Endpoint (Streamable HTTP):** `https://vhealth-api.sumflowcloud.com/mcp`
- **Auth Header:** `Authorization: Bearer <jwt_or_vhl_pat>`
- **Idempotency Header:** Send `Idempotency-Key: <uuid>` on `POST` writes to prevent duplicate logs on retries.
- **Error Envelope:** `{ "error": { "code": "...", "message": "...", "details": {} } }`

## 2. Tier Quotas (Build-Time Verified)
- **Free:** 200 meal + exercise logs (25 MB platform storage), 2,000 API requests / day, 1,500 MCP tool calls / month, 0 server LLM parses.
- **Capacity / MCP Pro:** ₹119/mo ($2.39/mo) — 5,000 meal + exercise logs, 25,000 MCP tool calls / month, 0 server LLM parses.
- **Premium:** ₹799/mo ($15.20/mo) — 20,000 meal + exercise logs, 2,000 server NL parses / month, AI plans & white-label.

## 3. REST Endpoint Reference

### Auth & Personal Access Tokens

- `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

- `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)

- `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)

- `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

- `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

- `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

## 4. Standard Error Codes

- `401` `unauthorized`: Missing, expired, or revoked JWT / PAT token
- `403` `premium_required`: Endpoint requires Premium plan_tier (e.g., log-text, AI plans, white-label)
- `403` `capacity_exceeded`: Platform storage or log count cap reached — upgrade or switch storage mode
- `429` `mcp_quota_exceeded`: Monthly MCP tool call allowance reached — upgrade to Capacity / MCP Pro
- `429` `rate_limited`: Short-window anti-abuse burst limit hit; retry after Retry-After header

## 5. MCP Server Tools (`/mcp`)

- `get_profile` → `GET /api/v1/profile` (**Free+**): Read calorie/macro targets, diet_type, allergies, and current weight
- `update_profile` → `PATCH /api/v1/profile` (**Free+**): Update weight goals, dietary constraints, or macro targets
- `log_meal_structured` → `POST /api/v1/meals` (**Free+**): Log itemized foods with agent-calculated macros (zero server LLM)
- `log_meal_nutrients` → `POST /api/v1/meals/nutrients` (**Free+**): Log exact nutrient totals directly from labels or agent estimates
- `update_meal_item` → `PATCH /api/v1/meals/{id}/items/{item_id}` (**Free+**): Adjust portion grams or macros on a previously logged item
- `list_meals` → `GET /api/v1/meals` (**Free+**): Inspect logged meals by date range, category, or search term
- `log_exercise` → `POST /api/v1/exercises` (**Free+**): Log workout activity, duration, and agent-estimated calories burned
- `list_exercises` → `GET /api/v1/exercises` (**Free+**): Inspect exercise outflow history
- `log_body_metric` → `POST /api/v1/body-metrics` (**Free+**): Record weight_kg, body_fat_pct, or waist_cm check-in
- `list_body_metrics` → `GET /api/v1/body-metrics` (**Free+**): Read longitudinal body weight trend
- `log_habit` → `POST /api/v1/habits` (**Free+**): Log hydration, sleep, steps, or custom habit check-ins
- `list_habits` → `GET /api/v1/habits` (**Free+**): Inspect habit history
- `get_daily_summary` → `GET /api/v1/meals/daily-summary` (**Free+**): Check today's intake, outflow, net calories, and remaining targets
- `get_dashboard` → `GET /api/v1/dashboard` (**Free+**): Read day/week/month time series so your agent can summarize trends & advise

## 6. Agent Implementation Rules
1. Use `POST /api/v1/meals`, `POST /api/v1/meals/nutrients`, and `POST /api/v1/exercises` for Free and MCP-powered workflows (never assume server LLM access on Free).
2. Handle `403 premium_required` gracefully on `/log-text` and `/plans/*` by prompting upgrade or falling back to structured forms.
3. Use `GET /api/v1/dashboard` for charts (month-to-date default in user timezone, `month`, `year`, or `start_date`/`end_date`).
4. Automatically refresh expired JWT `access_token` (`401`) once via `POST /api/v1/auth/refresh`.

## 7. Support & Docs
- Website & docs: https://vhealth.sumflowcloud.com/
- Developer support: hello@sumflowcloud.com
