/>
← Workout Stats
Your token

Workout Stats API

Reading the log, every week against the WHO guideline, intensity, habits, trend, run pace, warning signs and every download run free in the browser and need no API. The API is for the one metered step: send the summary numbers the page works out from a log, and get back, as JSON, one suggestion for each of frequency, intensity, type, time and recovery, with the fact ids each rests on, and a 7-day plan. The page builds this input for you and checks every number before showing it.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "suggest".

taskWhat it doesReply
suggestChooses one suggestion per category (frequency, intensity, type, time, recovery) from a workout log's summary numbers and lays out next week.One JSON object

Input fields

Every field is a string; facts and limits hold JSON text. task and facts are required.

FieldMeaning
task"suggest"
factsJSON object of fact ids: recent_weeks, avg_active_min_recent (moderate minutes plus vigorous minutes counted twice, a week), avg_days_recent, avg_strength_days_recent, weeks_met, vigorous_share, moderate_share, light_share, top_time, longest_gap_days, trend, warnings (ids hard_streak, effort_high, hr_over_95, resting_hr_high), types_done, and for runs runs_per_week_recent, run_dist_per_week_recent, longest_run, unit; goal when given.
limits{active_min_low, active_min_high}: the range next week's plan must add up to.
goalOptional, up to 200 characters, the visitor's own words.

The reply

job.output.output is text holding one JSON object: suggestions, five {category, action, target, type?, time?, because} in the order frequency, intensity, type, time, recovery, and plan, seven {day, type, minutes, intensity} ({day, type: "rest"} for a rest day). Actions: frequency add_day, keep_days, fewer_days; intensity more_minutes, add_vigorous, ease_off, keep_mix; type add_strength, add_type, keep_types; time keep_time, pick_time; recovery rest_day, easy_after_hard, see_doctor. Before using it, check it as the page does: each action fits the facts (for example see_doctor exactly when there is a heart-rate warning), and the plan's active minutes fall inside limits with the suggested number of active and rest days. If the balance ran low, truncated is true and the object may stop early; the page keeps what arrived whole.

Worked example

Input (input.json), from the page's "Strava export" example:

{
  "task": "suggest",
  "facts": "{\"recent_weeks\":4,\"avg_active_min_recent\":449,\"avg_days_recent\":6,\"avg_strength_days_recent\":2,\"weeks_met\":\"10 of 10\",\"vigorous_share\":100,\"moderate_share\":0,\"light_share\":0,\"top_time\":\"morning\",\"longest_gap_days\":1,\"trend\":\"up\",\"warnings\":[],\"types_done\":[\"run\",\"cycle\",\"strength\"],\"runs_per_week_recent\":3,\"run_dist_per_week_recent\":22.4,\"longest_run\":10.5,\"unit\":\"km\",\"goal\":\"Run a half marathon in March\"}",
  "limits": "{\"active_min_low\":150,\"active_min_high\":561}",
  "goal": "Run a half marathon in March"
}

Reply:

{"suggestions":[{"category":"frequency","action":"keep_days","target":6,"because":["avg_days_recent"]},{"category":"intensity","action":"ease_off","target":3,"because":["vigorous_share"]},{"category":"type","action":"keep_types","target":null,"because":["types_done","avg_strength_days_recent"]},{"category":"time","action":"keep_time","target":null,"time":"morning","because":["top_time"]},{"category":"recovery","action":"rest_day","target":1,"because":["avg_days_recent","longest_gap_days"]}],"plan":[{"day":"mon","type":"run","minutes":60,"intensity":"vigorous"},{"day":"tue","type":"strength","minutes":45,"intensity":"moderate"},{"day":"wed","type":"cycle","minutes":90,"intensity":"moderate"},{"day":"thu","type":"run","minutes":50,"intensity":"vigorous"},{"day":"fri","type":"strength","minutes":45,"intensity":"moderate"},{"day":"sat","type":"run","minutes":70,"intensity":"vigorous"},{"day":"sun","type":"rest"}]}

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above, or a required field is missing or empty.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://workout-stats.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"workout-stats"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "suggest", "facts": "{\"recent_weeks\":4,\"avg_active_min_recent\":449,\"avg_days_recent\":6,\"avg_strength_days_recent\":2,\"weeks_met\":\"10 of 10\",\"vigorous_share\":100,\"moderate_share\":0,\"light_share\":0,\"top_time\":\"morning\",\"longest_gap_days\":1,\"trend\":\"up\",\"warnings\":[],\"types_done\":[\"run\",\"cycle\",\"strength\"],\"runs_per_week_recent\":3,\"run_dist_per_week_recent\":22.4,\"longest_run\":10.5,\"unit\":\"km\",\"goal\":\"Run a half marathon in March\"}", "limits": "{\"active_min_low\":150,\"active_min_high\":561}", "goal": "Run a half marathon in March"}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="workout-stats:suggest:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: suggestions, plan
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: workout-stats:suggest:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json