ailabtools
v0.5.4
Published
Official Node.js and TypeScript SDK for AILabTools AI image APIs: background removal, image upscaling, hairstyle changer, face retouching, object removal, and more.
Downloads
863
Maintainers
Readme
AILabTools SDK - AI Image API for Node.js and TypeScript
Official Node.js and TypeScript SDK for AILabTools AI Image APIs.
Build AI-powered photo editing features with simple API calls: background removal, image upscaling, object removal, face retouching, hairstyle changer, age and gender swap, cartoon avatar generation, skin analysis, virtual try-on, and more.
- Install the AILabTools Node.js SDK from npm:
npm install ailabtools - 87 current APIs plus 6 legacy-compatible endpoints
- Supports file and in-memory uploads, async tasks, and temporary result URLs
- Get started with the AILabTools Developer Console
Requirements
- Node.js 18 or later
Installation
npm install ailabtoolsQuick Start
1. Get your API key
Create or copy your API key from the AILabTools Developer Console.
export AILAB_API_KEY="your_api_key_here"2. Remove an image background
import { readFileSync } from "node:fs";
import { AILabClient } from "ailabtools";
const client = new AILabClient({
apiKey: process.env.AILAB_API_KEY!,
});
const result = await client.background.remove({
image: readFileSync("./photo.jpg"),
returnForm: "whiteBK",
});
console.log(result.data?.image_url);The SDK uses camelCase parameters and maps them automatically to API field names. For example, upscaleFactor maps to upscale-factor, and returnForm maps to return_form.
Popular Use Cases
| Popular API | Typical use case | SDK method | Try online |
| --- | --- | --- | --- |
| Cartoon Yourself API | Create cartoon portraits and avatars from photos. | client.portrait.portraitCartoonYourself() | Try Cartoon Yourself online |
| Change Facial Expressions API | Edit smiles, grins, sadness, and other facial expressions. | client.portrait.portraitExpressionEditing() | Try Change Facial Expressions online |
| Hairstyle Changer Premium API | Preview preset hairstyles or transfer a hairstyle from a reference image. | client.portrait.portraitHairstyleEditingPremium() | Try Hairstyle Changer online |
| Try on Clothes Premium API | Generate high-quality virtual clothing try-on results. | client.portrait.portraitTryOnClothesPremium() | Try Virtual Clothes Try-On online |
| Skin Analyze Pro API | Analyze skin condition, texture, tone, acne, pores, and wrinkles. | client.portrait.portraitSkinAnalysisProfessional() | Try AI Skin Analyzer online |
| Face Beauty Pro API | Apply advanced portrait beautification and face shaping. | client.portrait.portraitFacialBeautificationPro() | Try Retouch Portraits online |
| AI Face Swap API | Swap a face into a target portrait while preserving the scene. | client.portrait.portraitAIFaceSwap() | Try AI Face Swap online |
| AI Breast Expansion API | Apply a controlled bust-area adjustment to a portrait. | client.portrait.portraitAIBreastExpansion() | Try AI Breast Expansion online |
Browse more demos in AILabTools AI Portrait Tools and AILabTools AI Image Tools.
View the complete AILabTools SDK API index.
Common Developer-Friendly Aliases
Both full API method names and short aliases are supported. For example, client.background.remove() calls the same Universal Background Removal API as client.cutout.cutoutUniversalBackgroundRemoval().
| API | Full method | Alias |
| --- | --- | --- |
| Universal Background Removal | client.cutout.cutoutUniversalBackgroundRemoval() | client.background.remove() |
| Image Upscaler | client.image.imageLosslessEnlargement() | client.image.upscale() |
| Remove Objects | client.image.imageRemoveObjects() | client.image.removeObjects() |
| Hairstyle Changer Pro | client.portrait.portraitHairstyleEditingPro() | client.portrait.changeHairstyle() |
| Smart Beauty | client.portrait.portraitIntelligentBeautification() | client.portrait.retouch() |
View the complete method and alias reference.
File Uploads
FileInput supports Buffer | ArrayBuffer | Uint8Array.
Async Task Example
Some APIs return task_id for long-running image generation or enhancement jobs. Use waitForTask to poll until the task succeeds, fails, or times out.
const task = await client.portrait.changeHairstyle({
taskType: "async",
image: readFileSync("./portrait.jpg"),
hairStyle: "BuzzCut",
color: "blonde",
});
const taskId = task.task_id || task.data?.task_id;
const result = await client.waitForTask(taskId!, {
intervalMs: 5000,
timeoutMs: 300000,
throwOnFailed: true,
});
console.log(result.data);API Reference
- AILabTools API Documentation
- Get your AILabTools API key
- AILabTools SDK Documentation
- Python SDK on PyPI
- AILabTools SDK on GitHub
- SDK examples
Error Handling
API errors throw AILabApiError, which includes troubleshooting fields such as requestId and logId.
try {
const result = await client.background.remove({
image: readFileSync("./photo.jpg"),
returnForm: "whiteBK",
});
console.log(result.data?.image_url);
} catch (error) {
console.error("AILabTools API Error:", error);
// Send request_id and log_id to support if you need help.
}Testing
AILAB_API_KEY=xxx npm testLicense
MIT
