Getting Started
Making your first API request
This page walks you through making your first successful request to the athlete-nutrition-ai API. By the end, you will have authenticated with the service, created an athlete profile, and retrieved a personalized meal plan — confirming that your integration is working end to end. Getting this foundation right matters because every other workflow in the API, from connecting training calendars to generating shopping lists, builds on the authentication and profile setup you complete here.
Before you begin, make sure you have the following in place:
- An athlete-nutrition-ai developer account. Sign up at the developer portal to obtain your API credentials.
- A valid API key. Generated from your account dashboard after registration.
- An HTTP client. Examples in this guide use
curl. Any client that can send HTTP requests works — Postman, Insomnia, or your language's HTTP library. - curl 7.68+ (if following the shell examples directly). Run
curl --versionto confirm. - Basic familiarity with JSON and REST conventions. You should be comfortable reading JSON request and response bodies.
- Your target environment URL. All requests go to
https://api.athlete-nutrition-ai.com/v1(production). A sandbox base URL will be noted where relevant.
The shortest path to a working response has four steps:
- Export your API key as an environment variable so you do not have to paste it into every command.
- Create an athlete profile by
POSTing your dietary preferences and training goals. - Send a meal-plan request referencing that profile.
- Inspect the response to confirm you received a personalized meal plan.
If you already have a profile ID from a previous session, you can skip step 2 and go straight to step 3.
# Step 1 — store your key
export ANAI_API_KEY="your_api_key_here"
# Step 2 — create a profile
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/profiles \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Alex", "sport": "cycling", "dietary_preferences": ["gluten-free"], "goal": "endurance"}'
# Step 3 — request a meal plan (replace <profile_id> with the id from step 2)
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/meal-plans \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"profile_id": "<profile_id>", "days": 3}'
A 200 OK response containing a meal_plan object means your setup is complete.
Follow these steps in order. Each step describes what you are doing, the exact command, and what a successful outcome looks like.
Step 1 — Authenticate: set your API key
All requests to athlete-nutrition-ai require a bearer token. Export your key as an environment variable to keep subsequent commands clean and to avoid accidentally committing credentials to source control.
export ANAI_API_KEY="your_api_key_here"
✅ Success: The variable is set. Confirm with echo $ANAI_API_KEY — your key should print to the terminal.
Step 2 — Verify connectivity: call the health endpoint
Before doing real work, confirm that you can reach the API and that your key is valid.
curl -s -o /dev/null -w "%{http_code}" \
https://api.athlete-nutrition-ai.com/v1/health \
-H "Authorization: Bearer $ANAI_API_KEY"
✅ Success: The command prints 200. Any other code means there is a connectivity or authentication problem — see the Troubleshooting section.
Step 3 — Create an athlete profile
The profile stores the information the AI uses to personalize every meal plan: the athlete's sport, dietary restrictions, and nutritional goal. You create a profile once and reference it by ID in later requests.
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/profiles \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Alex",
"sport": "cycling",
"dietary_preferences": ["gluten-free"],
"goal": "endurance"
}'
✅ Success: The API returns a 201 Created response containing a JSON object with an id field. Copy this id — you will use it in the next step.
Step 4 — Request a personalized meal plan
With a profile in place, you can ask the AI to generate a meal plan. The days field controls how many days the plan covers. The AI factors in the profile's sport, dietary preferences, and goal when selecting meals.
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/meal-plans \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"profile_id": "<your_profile_id>",
"days": 3
}'
✅ Success: The API returns a 200 OK response with a meal_plan object that contains daily meal entries. You have made your first complete, personalized API request.
Step 5 — (Optional) Generate a shopping list
Once you have a meal plan ID, you can derive a shopping list from it in a single additional call. This confirms that downstream endpoints are reachable from your environment.
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/shopping-lists \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"meal_plan_id": "<your_meal_plan_id>"}'
✅ Success: A 200 OK response containing a shopping_list array of ingredients.
The following examples are self-contained and runnable. Replace placeholder values (shown in angle brackets) with your real data.
Example 1 — Create an athlete profile and capture the profile ID
This example pipes the response through jq to extract the ID cleanly. If you do not have jq, remove the pipe and read the id field from the raw JSON.
PROFILE_ID=$(
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/profiles \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Alex",
"sport": "cycling",
"dietary_preferences": ["gluten-free"],
"goal": "endurance"
}' | jq -r '.id'
)
echo "Profile created: $PROFILE_ID"
Expected output:
Profile created: prof_a1b2c3d4e5f6
Example 2 — Generate a 3-day meal plan
Uses the PROFILE_ID variable captured above.
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/meal-plans \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"profile_id\": \"$PROFILE_ID\",
\"days\": 3
}"
Expected response (abbreviated):
{
"id": "mp_9z8y7x6w",
"profile_id": "prof_a1b2c3d4e5f6",
"days": 3,
"meal_plan": [
{
"day": 1,
"meals": [
{ "type": "breakfast", "name": "Oat and banana smoothie bowl", "calories": 480 },
{ "type": "lunch", "name": "Quinoa and roasted vegetable salad", "calories": 610 },
{ "type": "dinner", "name": "Grilled salmon with sweet potato", "calories": 720 }
]
}
]
}
Example 3 — Generate a shopping list from the meal plan
curl -s -X POST https://api.athlete-nutrition-ai.com/v1/shopping-lists \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"meal_plan_id": "mp_9z8y7x6w"}'
Expected response (abbreviated):
{
"id": "sl_1a2b3c4d",
"meal_plan_id": "mp_9z8y7x6w",
"shopping_list": [
{ "item": "rolled oats", "quantity": "500g" },
{ "item": "banana", "quantity": "6" },
{ "item": "quinoa", "quantity": "400g" },
{ "item": "salmon fillet", "quantity": "3 × 180g" },
{ "item": "sweet potato", "quantity": "3 medium" }
]
}
Use the table below to diagnose the most common problems you might encounter during your first requests.
Problem: 401 Unauthorized on every request
- Symptom: Every API call returns
{"error": "Unauthorized"}or HTTP status401. - Likely cause: The
Authorizationheader is missing, malformed, or the API key has not been activated yet. - Fix: Confirm your environment variable is set (
echo $ANAI_API_KEY). Verify the header format is exactlyAuthorization: Bearer <key>with no extra spaces. If the key was just created, wait a minute for activation to propagate, then retry.
Problem: 403 Forbidden on specific endpoints
- Symptom: Authentication succeeds on
/healthbut returns403on/meal-plansor/shopping-lists. - Likely cause: Your API key belongs to a plan that does not include access to that endpoint, or your subscription has lapsed.
- Fix: Check your subscription tier in the developer dashboard and confirm the endpoint is included. Upgrade your plan if necessary.
Problem: 422 Unprocessable Entity when creating a profile
- Symptom: The
/profilesendpoint returns422with a validation error message. - Likely cause: A required field is missing from the request body, or a field value is not one of the accepted options (for example, an unrecognized
sportorgoalvalue). - Fix: Re-read the error response body — it usually identifies the offending field. Ensure your
Content-Typeheader is set toapplication/jsonand your request body is valid JSON. Check the API reference for accepted enum values forsport,dietary_preferences, andgoal.
Problem: curl: (6) Could not resolve host
- Symptom: curl cannot connect at all and reports a DNS resolution failure.
- Likely cause: A typo in the base URL, or a network/firewall restriction in your environment.
- Fix: Double-check the base URL (
https://api.athlete-nutrition-ai.com/v1). If you are behind a corporate firewall or proxy, configure curl with--proxyor contact your network administrator to whitelist the domain.
Problem: Meal plan returns generic meals that ignore dietary preferences
- Symptom: The generated meal plan contains foods that contradict the dietary restrictions set on the profile.
- Likely cause: The meal plan request is referencing a different
profile_idthan intended, or the profile was created without the correctdietary_preferencesvalues. - Fix: Fetch the profile directly (
GET /v1/profiles/<profile_id>) to confirm the preferences are recorded correctly. If the profile is wrong, create a new one with the correct values and use its ID when generating the meal plan.
Problem: 429 Too Many Requests
- Symptom: Requests that worked previously now return HTTP
429. - Likely cause: You have exceeded the rate limit for your subscription tier.
- Fix: Slow down your request cadence. Check the
Retry-Afterheader in the429response for the number of seconds to wait before retrying. Consider batching requests or upgrading your subscription tier if you consistently hit this limit.