How a Small Fitness App Team Used LLMs for Dynamic Workout Plan Generation
My friend runs a small team building a fitness app—three backend engineers, one product manager, no algorithm engineers. Their earliest version of "personalized training plans" was hard-coded: a dozen or so templates roughly categorized by user goal (fat loss / muscle gain / body shaping). After filling out a questionnaire, users were matched with one template. It was internally inconsistent, and worse, week-two churn was very high. They later decided to use large language models to dynamically generate plans, hit quite a few pitfalls in the first month, and I helped with the architecture adjustments. I've put together the cost breakdown and solution here for indie developers who want to ship quickly.
1. The Business Pain Point: The Cost of Manual Plans Doesn't Add Up
First, their real operational data (anonymized internal estimates, not customer data):
- Coaches writing plans manually: A decent four-week plan takes a coach an average of 40-60 minutes. With monthly labor costs, they could only cover about 8% of paying users;
- Template matching solution: Took 3 weeks to build, but matching accuracy was poor—constraints from the questionnaire like "old knee injury, can only train 3 times a week, only has dumbbells at home" simply couldn't be handled;
- User-side experience: Plans don't fit → low adherence → low renewal rates, a vicious cycle.
The core contradiction: you can't have both personalization and low marginal cost. LLMs happen to break this trade-off—the marginal cost of personalized content approaches zero, but only if you get three things right in engineering: structured input, stable output, and controllable cost.
2. Architecture Design
The overall architecture has four layers, with the key point being to consolidate "model calls" into one place:
User questionnaire / body measurement data / training feedback
│
▼
┌─────────────────────┐
│ Intent & Constraint Parsing Layer │ ← Extract: goals/injury history/equipment/time/level
└─────────────────────┘
│ Structured JSON
▼
┌─────────────────────┐
│ Plan Generation Orchestration Layer │ ← Prompt templates + RAG (exercise library/safety rules)
└─────────────────────┘
│
▼
┌─────────────────────┐
│ Unified AI API Gateway │ ← Multi-model routing/fallback/retry/usage tracking
└─────────────────────┘
│
▼
┌─────────────────────┐
│ Validation & Persistence Layer │ ← Schema validation/safety rule filtering/save to DB
└─────────────────────┘Why the Emphasis on a Unified AI API Gateway
They initially called a single vendor's model SDK directly from various business code modules. A month later, problems erupted all at once: one model upgrade changed the output format, forcing changes across three modules; switching to a cheaper model for overnight batch jobs meant another round of refactoring. That's where a unified gateway delivers value:
- Upgrade in one place, effective everywhere: Model switching, parameter tuning, and prompt version management all happen at the gateway layer. Business code only faces one stable interface, reducing N maintenance points to 1;
- Automatic retry and fallback: If the primary model times out, it automatically switches to a backup model—users never notice, and nobody has to get up at 3 a.m. to swap API keys;
- Transparent usage and costs: Every call's tokens, latency, and cost are tagged by feature module, so cost optimization is data-driven instead of being ambushed by the month-end bill;
- Centralized key management: Avoids keys scattered across code and configs, making security and rotation much easier.
For a small team, this effectively replaces middleware code that would have taken days to write with a bit of configuration.
3. Key Implementation Steps and Before/After Comparison
1. Structured Input
Don't throw raw questionnaire text at the model. Parse it into a fixed schema first:
{
"goal": "fat_loss",
"experience": "beginner",
"weekly_sessions": 3,
"session_minutes": 45,
"equipment": ["dumbbell", "yoga_mat"],
"injuries": ["left_knee"],
"constraints": ["no_running"]
}2. Prompt Templates + Exercise Library RAG
The prompt has three sections: role setting (professional coach + sports rehabilitation knowledge), the user's structured data, and a set of matching exercises retrieved from the exercise library (with equipment tags and contraindication tags). The model is forbidden from inventing exercise names out of thin air, preventing it from generating workouts that don't exist.
3. Enforced JSON Output + Validation
Use JSON Schema to constrain output, and run two layers of validation before persisting: format validation (all fields present, sets and reps within reasonable ranges) + safety validation (conflict detection between injury history and exercise contraindications). Failed outputs are automatically retried, with a fallback to template-based plans after a maximum of 3 attempts.
4. Tiered Cost Routing
- First generation for new users: high-capability model, to guarantee the experience;
- Plan fine-tuning and post-feedback revisions: lightweight model, at roughly 1/10 the cost;
- Overnight batch pre-generation: cheapest channel.
Results Comparison (before vs. after launch, internal team statistics)
| Metric | Before | After |
|---|---|---|
| Time to generate one plan | 40-60 min manual | Auto-generated within 8 seconds |
| Personalization coverage | 8% (manually capped) | 100% |
| Response to model changes | Code changes in 3 places | 1 config change in the gateway |
| Average cost per call | — | ~60% reduction with tiered routing |
The most striking calculation: coaches shifted from "writing plans" to "spot-check review," expanding coverage roughly 10x with the same headcount, while user plans went from "one-size-fits-all" to genuinely tailored to individual conditions.
4. Three Tips for Indie Developers
- Constraints first, intelligence second: The "boring stuff"—schemas, validation, safety rules—determines whether your product can ship at all; how smart the model is comes second;
- Treat fallback paths as first-class citizens: Falling back to templates when AI generation fails beats a blank screen with an error by a thousandfold;
- Connect a unified gateway from day one: Don't wait until calls are scattered across five or six modules—the cost of refactoring later is a multiple of the initial integration cost.
If your project is also moving from "getting one API call to work" to "reliably serving a batch of users," check out a unified AI API gateway solution—you can register here: https://api.thistoken.ai/register
---
Ready to try it yourself? Sign up at https://api.thistoken.ai/register to get your API key and start building.
Bạn muốn thử Token.AI?
Tạo API Key cấp dự án, bật kênh trong bảng điều khiển và định cấu hình định tuyến, ngân sách và nhật ký kiểm tra.
注册 ThisToken.AI 并获取 API Key