Code Examples

Ready-to-run code examples for Python, JavaScript, cURL, Dart, and Next.js — copy, paste, and replace YOUR_API_KEY to get started.

All examples use height + weight anchors, European adult male, full body profile. Replace YOUR_API_KEY with your key from the RapidAPI dashboard.

Important: body_height is in millimetres1780 means 178 cm. The most common mistake is sending centimetres.


Python

Requires requests: pip install requests

import requests

URL = "https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict"
HEADERS = {
    "X-RapidAPI-Key": "YOUR_API_KEY",
    "X-RapidAPI-Host": "dimensionspot-bodysize-engine.p.rapidapi.com",
    "Content-Type": "application/json",
}

payload = {
    "input_data": {
        "input_unit_system": "metric",
        "subject": {
            "gender": "male",
            "exact_age": 35.0,
            "age_category": "ADULT",
            "input_origin_region": "EUROPE",
        },
        "anchors": {
            "body_height": 1780,  # millimeters — NOT centimeters (178 cm × 10)
            "body_mass": 82.0,    # kilograms
        },
    },
    "output_settings": {
        "calculation": {
            "calculation_model": "AUTO",
            "target_region": "EUROPE",
            "body_build_type": "CIVILIAN",
        },
        "requested_dimensions": {"bundle": "FULL_BODY"},
        "output_format": {
            "unit_system": "metric",
            "confidence_score_threshold": 0,
            "include_range_95": True,
            "include_iso_codes": True,
        },
    },
}

response = requests.post(URL, json=payload, headers=HEADERS)
response.raise_for_status()
data = response.json()

dimensions = data["body_dimensions"]
print(f"Engine used: {data['header']['calculation_model_used']}")
print(f"Dimensions returned: {len(dimensions)}\n")

for key in ["shoulder_height", "chest_circumference", "waist_circumference_omphalion", "hip_circumference"]:
    if key in dimensions:
        dim = dimensions[key]
        print(
            f"{dim['label']}: {dim['value']} {dim['unit']} "
            f"(confidence: {dim['confidence_score']}, "
            f"range_95: {dim['range_95']})"
        )

Python — Regional Calibration

Cross-regional request: Asian customer shopping a European brand’s size chart.

import requests

URL = "https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict"
HEADERS = {
    "X-RapidAPI-Key": "YOUR_API_KEY",
    "X-RapidAPI-Host": "dimensionspot-bodysize-engine.p.rapidapi.com",
    "Content-Type": "application/json",
}

# input_origin_region: the population your customer belongs to (normalizes anchor values)
# target_region: the population your size chart was built for (calibrates output proportions)

payload = {
    "input_data": {
        "input_unit_system": "metric",
        "subject": {
            "gender": "female",
            "exact_age": 28.0,
            "age_category": "ADULT",
            "input_origin_region": "ASIA_PACIFIC",  # customer's origin
        },
        "anchors": {
            "body_height": 1620,  # mm
            "body_mass": 55.0,    # kg
        },
    },
    "output_settings": {
        "calculation": {
            "calculation_model": "AUTO",
            "target_region": "EUROPE",  # brand's size chart origin
            "body_build_type": "CIVILIAN",
        },
        "requested_dimensions": {
            "bundle": "TORSO",  # clothing-relevant: chest, waist, hip, shoulder, sitting heights
        },
        "output_format": {
            "unit_system": "metric",
            "confidence_score_threshold": 75,
            "include_range_95": True,
            "include_iso_codes": False,
        },
    },
}

response = requests.post(URL, json=payload, headers=HEADERS)
response.raise_for_status()
data = response.json()

print(f"Modifiers applied: {data['header']['modifiers_applied']}")
print(f"Warnings: {data['header']['meta_warnings'] or 'none'}\n")

dimensions = data["body_dimensions"]
for key in ["chest_circumference", "waist_circumference_omphalion", "hip_circumference"]:
    if key in dimensions:
        dim = dimensions[key]
        print(f"{dim['label']}: {dim['value']} {dim['unit']} (confidence: {dim['confidence_score']})")

Python — Pediatric Engine

LMS Box-Cox method, calibrated to CDC/WHO growth standards. No anchors required.

import requests

URL = "https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict"
HEADERS = {
    "X-RapidAPI-Key": "YOUR_API_KEY",
    "X-RapidAPI-Host": "dimensionspot-bodysize-engine.p.rapidapi.com",
    "Content-Type": "application/json",
}

# Pediatric engine activates automatically when exact_age <= 20.
# body_height and body_mass are OUTPUTS in pediatric mode (derived from CDC LMS tables).

payload = {
    "input_data": {
        "input_unit_system": "metric",
        "subject": {
            "gender": "female",
            "exact_age": 8.0,       # strongly recommended for pediatric — growth rates are high
            "age_category": "CHILD",
            "input_origin_region": "GLOBAL",
        },
        "anchors": {},  # no anchors needed — CDC LMS derives height and mass from age + sex
    },
    "output_settings": {
        "calculation": {
            "calculation_model": "AUTO",  # routes to PEDIATRIC because exact_age <= 20
            "target_region": "GLOBAL",
            "body_build_type": "CIVILIAN",
        },
        "requested_dimensions": {"bundle": "FULL_BODY"},
        "output_format": {
            "unit_system": "metric",
            "confidence_score_threshold": 0,
            "include_range_95": True,
            "include_iso_codes": False,
        },
    },
}

response = requests.post(URL, json=payload, headers=HEADERS)
response.raise_for_status()
data = response.json()

header = data["header"]
print(f"Engine used: {header['calculation_model_used']}")  # PEDIATRIC
print(f"Warnings: {header['meta_warnings'] or 'none'}\n")

dimensions = data["body_dimensions"]
# LMS-derived dimensions: body_height, body_mass, head_circumference — confidence 99
# Ridge-derived dimensions: all others — capped at confidence 80
for key in ["body_height", "body_mass", "head_circumference", "shoulder_height", "foot_length"]:
    if key in dimensions:
        dim = dimensions[key]
        print(
            f"{dim['label']}: {dim['value']} {dim['unit']} "
            f"(confidence: {dim['confidence_score']}, type: {dim['type']})"
        )

JavaScript

Requires Node.js 18+ (native fetch) or npm install node-fetch.

const URL = "https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict";
const API_KEY = "YOUR_API_KEY";

const payload = {
  input_data: {
    input_unit_system: "metric",
    subject: {
      gender: "male",
      exact_age: 35.0,
      age_category: "ADULT",
      input_origin_region: "EUROPE",
    },
    anchors: {
      body_height: 1780, // millimeters — NOT centimeters (178 cm × 10)
      body_mass: 82.0,   // kilograms
    },
  },
  output_settings: {
    calculation: {
      calculation_model: "AUTO",
      target_region: "EUROPE",
      body_build_type: "CIVILIAN",
    },
    requested_dimensions: { bundle: "FULL_BODY" },
    output_format: {
      unit_system: "metric",
      confidence_score_threshold: 0,
      include_range_95: true,
      include_iso_codes: true,
    },
  },
};

async function predict() {
  const response = await fetch(URL, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-RapidAPI-Key": API_KEY,
      "X-RapidAPI-Host": "dimensionspot-bodysize-engine.p.rapidapi.com",
    },
    body: JSON.stringify(payload),
  });

  if (!response.ok) {
    const error = await response.json();
    throw new Error(`API error ${response.status}: ${JSON.stringify(error)}`);
  }

  const data = await response.json();
  const dimensions = data.body_dimensions;

  console.log(`Engine used: ${data.header.calculation_model_used}`);
  console.log(`Dimensions returned: ${Object.keys(dimensions).length}\n`);

  for (const key of ["shoulder_height", "chest_circumference", "hip_circumference"]) {
    if (dimensions[key]) {
      const dim = dimensions[key];
      console.log(
        `${dim.label}: ${dim.value} ${dim.unit} (confidence: ${dim.confidence_score})`
      );
    }
  }
}

predict().catch(console.error);

Next.js API Route

Server-side only — keeps your API key out of the browser bundle. Store your key in .env.local as RAPIDAPI_KEY=YOUR_API_KEY.

// pages/api/body-dimensions.js (Pages Router)
// app/api/body-dimensions/route.js (App Router — see comment at bottom)

const RAPIDAPI_URL = "https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict";

// Pages Router handler
export default async function handler(req, res) {
  if (req.method !== "POST") {
    return res.status(405).json({ error: "Method not allowed" });
  }

  const { gender, height_cm, weight_kg, age, region = "GLOBAL" } = req.body;

  if (!gender || !height_cm || !weight_kg) {
    return res.status(400).json({ error: "gender, height_cm, and weight_kg are required" });
  }

  const payload = {
    input_data: {
      input_unit_system: "metric",
      subject: {
        gender,
        exact_age: age ?? null,
        age_category: "ADULT",
        input_origin_region: region,
      },
      anchors: {
        body_height: Math.round(height_cm * 10), // convert cm → mm
        body_mass: weight_kg,
      },
    },
    output_settings: {
      calculation: {
        calculation_model: "AUTO",
        target_region: region,
        body_build_type: "CIVILIAN",
      },
      requested_dimensions: { bundle: "TORSO" }, // clothing-relevant dimensions
      output_format: {
        unit_system: "metric",
        confidence_score_threshold: 75,
        include_range_95: false,
        include_iso_codes: false,
      },
    },
  };

  try {
    const upstream = await fetch(RAPIDAPI_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-RapidAPI-Key": process.env.RAPIDAPI_KEY,
        "X-RapidAPI-Host": "dimensionspot-bodysize-engine.p.rapidapi.com",
      },
      body: JSON.stringify(payload),
    });

    if (!upstream.ok) {
      const error = await upstream.json();
      return res.status(upstream.status).json({ error });
    }

    const data = await upstream.json();
    return res.status(200).json(data);
  } catch (err) {
    return res.status(500).json({ error: "Upstream request failed", detail: err.message });
  }
}

// --- App Router variant ---
// File: app/api/body-dimensions/route.js
//
// import { NextResponse } from "next/server";
//
// export async function POST(request) {
//   const body = await request.json();
//   // ... same payload construction as above ...
//   const upstream = await fetch(RAPIDAPI_URL, { ... });
//   const data = await upstream.json();
//   return NextResponse.json(data);
// }

cURL

#!/usr/bin/env bash
API_KEY="YOUR_API_KEY"

# Full body profile — height + weight, European adult male
# Note: body_height is in millimeters (1780 mm = 178 cm)

curl -s -X POST "https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict" \
  -H "Content-Type: application/json" \
  -H "X-RapidAPI-Key: $API_KEY" \
  -H "X-RapidAPI-Host: dimensionspot-bodysize-engine.p.rapidapi.com" \
  -d '{
    "input_data": {
      "input_unit_system": "metric",
      "subject": {
        "gender": "male",
        "exact_age": 35.0,
        "age_category": "ADULT",
        "input_origin_region": "EUROPE"
      },
      "anchors": {
        "body_height": 1780,
        "body_mass": 82.0
      }
    },
    "output_settings": {
      "calculation": {
        "calculation_model": "AUTO",
        "target_region": "EUROPE",
        "body_build_type": "CIVILIAN"
      },
      "requested_dimensions": {
        "bundle": "FULL_BODY"
      },
      "output_format": {
        "unit_system": "metric",
        "confidence_score_threshold": 0,
        "include_range_95": true,
        "include_iso_codes": true
      }
    }
  }' | python3 -m json.tool

# --- Minimal request (all output_settings are optional) ---
# curl -s -X POST "https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict" \
#   -H "Content-Type: application/json" \
#   -H "X-RapidAPI-Key: $API_KEY" \
#   -H "X-RapidAPI-Host: dimensionspot-bodysize-engine.p.rapidapi.com" \
#   -d '{"input_data": {"subject": {"gender": "male"}, "anchors": {"body_height": 1780}}}'

# --- Liveness check ---
# curl -s "https://dimensionspot-bodysize-engine.p.rapidapi.com/health" \
#   -H "X-RapidAPI-Key: $API_KEY" \
#   -H "X-RapidAPI-Host: dimensionspot-bodysize-engine.p.rapidapi.com"

Dart

Add to pubspec.yaml: http: ^1.0.0 then run dart pub get.

import 'dart:convert';
import 'package:http/http.dart' as http;

const String _apiUrl =
    'https://dimensionspot-bodysize-engine.p.rapidapi.com/v1/predict';
const String _apiKey = 'YOUR_API_KEY';

Future<Map<String, dynamic>> predictBodyDimensions({
  required String gender,
  required double heightCm, // accepts cm, converts to mm internally
  required double weightKg,
  double? exactAge,
  String region = 'GLOBAL',
  String bundle = 'FULL_BODY',
}) async {
  final payload = {
    'input_data': {
      'input_unit_system': 'metric',
      'subject': {
        'gender': gender,
        if (exactAge != null) 'exact_age': exactAge,
        'age_category': 'ADULT',
        'input_origin_region': region,
      },
      'anchors': {
        'body_height': (heightCm * 10).round(), // cm → mm
        'body_mass': weightKg,
      },
    },
    'output_settings': {
      'calculation': {
        'calculation_model': 'AUTO',
        'target_region': region,
        'body_build_type': 'CIVILIAN',
      },
      'requested_dimensions': {'bundle': bundle},
      'output_format': {
        'unit_system': 'metric',
        'confidence_score_threshold': 0,
        'include_range_95': true,
        'include_iso_codes': false,
      },
    },
  };

  final response = await http.post(
    Uri.parse(_apiUrl),
    headers: {
      'Content-Type': 'application/json',
      'X-RapidAPI-Key': _apiKey,
      'X-RapidAPI-Host': 'dimensionspot-bodysize-engine.p.rapidapi.com',
    },
    body: jsonEncode(payload),
  );

  if (response.statusCode != 200) {
    throw Exception('API error ${response.statusCode}: ${response.body}');
  }

  return jsonDecode(response.body) as Map<String, dynamic>;
}

void main() async {
  final data = await predictBodyDimensions(
    gender: 'male',
    heightCm: 178.0,
    weightKg: 82.0,
    exactAge: 35.0,
    region: 'EUROPE',
    bundle: 'TORSO',
  );

  final header = data['header'] as Map<String, dynamic>;
  final dimensions = data['body_dimensions'] as Map<String, dynamic>;

  print('Engine: ${header['calculation_model_used']}');
  print('Dimensions returned: ${dimensions.length}\n');

  for (final key in ['chest_circumference', 'waist_circumference_omphalion', 'hip_circumference']) {
    if (dimensions.containsKey(key)) {
      final dim = dimensions[key] as Map<String, dynamic>;
      print('${dim['label']}: ${dim['value']} ${dim['unit']} '
          '(confidence: ${dim['confidence_score']})');
    }
  }
}