JS

JavaScript SDK

Official JavaScript/TypeScript client for AI Body Scan API. Works in Node.js and browsers.

Installation

npm install @aiscan/sdk
yarn add @aiscan/sdk

Quick Start

// JavaScript example
import { AIScan } from '@aiscan/sdk';

// Initialize with your API key
const client = new AIScan('sk_live_your_api_key');

// Extract measurements
const result = await client.measurements.extract({
    front: 'front.jpg',
    side: 'side.jpg',
    height: 175,
    gender: 'male'
});

console.log(result.measurements.Shoulder);  // 46.4
console.log(result.accuracy);              // "±1-3cm"

TypeScript Support

import { AIScan, MeasurementResult } from '@aiscan/sdk';

const client = new AIScan('sk_live_key');

// Full type inference
const result: MeasurementResult = await client.measurements.extract({
    front: 'front.jpg',
    side: 'side.jpg',
    height: 175,
    gender: 'male'
});

// TypeScript knows the exact shape!
result.measurements.Shoulder  // number

API Reference

Constructor

new AIScan(apiKey, options?)

Creates a new client instance.

const client = new AIScan('sk_live_key', {
    baseUrl: 'https://api.aiscan.io',  // default
    timeout: 30000,                      // 30s
    retries: 3                               // default
});

Methods

extract()

Extract measurements from photos.

await client.measurements.extract({
    front: File | string,
    side: File | string,
    height: number,
    gender: 'male' | 'female'
})
estimate()

Estimate from height only.

await client.measurements.estimate({
    height: number,
    gender: 'male' | 'female'
})

Error Handling

try {
    const result = await client.measurements.extract({...});
} catch (error) {
    if (error.code === 'AUTHENTICATION_ERROR') {
        console.log('Invalid API key');
    } else if (error.code === 'RATE_LIMITED') {
        console.log('Retry after', error.retryAfter);
    } else if (error.code === 'INVALID_IMAGE') {
        console.log('Image error:', error.message);
    }
}

Browser Usage

// HTML example
 type="module">
  import { AIScan } from 'https://cdn.aiscan.io/sdk/v2.js';
  
  const client = new AIScan('sk_live_key');
  
  const fileInput = document.querySelector('#photo');
  const result = await client.measurements.extract({
    front: fileInput.files[0],
    side: fileInput.files[1],
    height: 175
  });