Getting Started

Code Examples

curl, Python, and JavaScript examples for common operations.

Replace $ENDPOINT and $TOKEN with the credentials provided during onboarding.

curl — basic analysis

Due to the nested JSON structure (settings and data are stringified JSON inside the outer object), we recommend using Python or JavaScript for requests. If you prefer curl, pipe the payload from a file:

curl -X POST $ENDPOINT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d @request.json

Where request.json is built by your application with properly stringified settings and data fields.

Python — full analysis with stats

import json import requests ENDPOINT = "$ENDPOINT" # provided during onboarding TOKEN = "$TOKEN" settings = { "fixedSpeed": False, "fit": True, "returnPrediction": True, "returnStats": True, "weight": 75, "height": 178, "age": 32, "gender": "male", "sport": "running" } # Your HR + speed data (one dict per sample) data = [ {"time": t, "hr": hr, "speed": spd} for t, hr, spd in zip( range(300), [80 + 60*(1 - 2.718**(-t/60)) for t in range(300)], [3.0] * 300 ) ] payload = { "settings": json.dumps(settings), "data": json.dumps(data) } response = requests.post( ENDPOINT, json=payload, headers={"Authorization": f"Bearer {TOKEN}"}, timeout=300 ) result = response.json()["result"] # Always use the Bayesian-refined parameters (trueE, trueVmax, trueP) print(f"E={result['trueE']:.2f} Vmax={result['trueVmax']:.2f} m/s P={result['trueP']:.0f} bpm") print(f"Confidence: {result.get('trueConfidence', result['confidence']):.2f}") # Derived stats (computed from the fitted parameters) stats = result["stats"] print(f"VO2max: {stats['vo2max']:.1f}") print(f"MFI: {stats['mfi']:.2f}") print(f"RMR: {stats['energy']['rmr_kcal_day']:.0f} kcal/day") print(f"Session calories: {stats['energy']['session_calories']:.0f} kcal")

Python — multi-session with Bayesian memory

memory = None for session_data in all_sessions: payload = { "settings": json.dumps({"fixedSpeed": False, "fit": True}), "data": json.dumps(session_data) } if memory: payload["memory"] = json.dumps(memory) response = requests.post(ENDPOINT, json=payload, headers={"Authorization": f"Bearer {TOKEN}"}) result = response.json() # Update memory for next session memory = result.get("memory") # Use the Bayesian-refined parameters true_e = result["result"].get("trueE", result["result"]["E"]) true_vmax = result["result"].get("trueVmax", result["result"]["Vmax"]) print(f"Session: E={true_e:.2f} Vmax={true_vmax:.2f} m/s conf={memory['confidence']:.1f}")

JavaScript — WASM SDK (runs locally)

import { analyse } from '@driftline/sdk'; const settings = { fixedSpeed: false, fit: true, returnStats: true, weight: 75, height: 178, age: 32, gender: "male", sport: "running" }; const data = hrSamples.map((hr, i) => ({ time: i, hr: hr, speed: speedSamples[i] })); const input = { settings: JSON.stringify(settings), data: JSON.stringify(data) }; // Runs locally, no network call, no auth needed const result = await analyse(JSON.stringify(input)); const output = JSON.parse(result); console.log("E:", output.result.trueE); console.log("Vmax:", output.result.trueVmax, "m/s"); console.log("VO2max:", output.result.stats?.vo2max);

JavaScript — REST API

const response = await fetch(ENDPOINT, { method: "POST", headers: { "Authorization": `Bearer ${token}`, "Content-Type": "application/json" }, body: JSON.stringify({ settings: JSON.stringify({ fixedSpeed: false, fit: true }), data: JSON.stringify(sessionData) }) }); const { result } = await response.json();

Team sports — squad analysis

# Analyze each player's session, accumulate squad averages squad_results = [] for player in squad: payload = { "settings": json.dumps({ "fixedSpeed": False, "fit": True, "returnStats": True, "sport": "team_sports" }), "data": json.dumps(player.session_data) } if player.memory: payload["memory"] = json.dumps(player.memory) resp = requests.post(ENDPOINT, json=payload, headers={"Authorization": f"Bearer {TOKEN}"}) result = resp.json()["result"] squad_results.append(result) # Compute squad averages from Bayesian estimates mean_e = sum(r["trueE"] for r in squad_results) / len(squad_results) mean_vmax = sum(r["trueVmax"] for r in squad_results) / len(squad_results) # Re-analyze with squad context for archetype classification for player, result in zip(squad, squad_results): payload = { "settings": json.dumps({ "fixedSpeed": False, "fit": True, "returnStats": True, "sport": "team_sports", "squadMeanE": mean_e, "squadMeanVmax": mean_vmax }), "data": json.dumps(player.session_data) } resp = requests.post(ENDPOINT, json=payload, headers={"Authorization": f"Bearer {TOKEN}"}) archetype = resp.json()["result"]["stats"]["team_sports"]["archetype"] print(f"{player.name}: {archetype}")