AILabTools SDK for Dart and Flutter

Official Dart and Flutter SDK for the AILabTools AI image APIs. Add background removal, image upscaling, object removal, portrait retouching, hairstyle changes, virtual try-on, and other AI photo features to Flutter and Dart applications.

Features

  • Strongly typed parameters and responses for all 60 active APIs
  • Flutter Android, iOS, web, macOS, Windows, and Linux support
  • Dart server and command-line application support
  • Multipart image uploads using platform-independent byte data
  • Async task polling and structured API errors
  • Injectable HTTP client for tests and advanced networking

Installation

dart pub add ailabtools

For a Flutter project:

flutter pub add ailabtools

Quick Start

Create or copy an API key from the AILabTools Developer Console.

import 'dart:io';

import 'package:ailabtools/ailabtools.dart';

Future<void> main() async {
  final client = AILabClient(
    apiKey: Platform.environment['AILAB_API_KEY']!,
  );

  try {
    final bytes = await File('photo.jpg').readAsBytes();
    final result = await client.background.remove(
      CutoutUniversalBackgroundRemovalParams(
        image: AILabFile.fromBytes(
          bytes,
          filename: 'photo.jpg',
          contentType: 'image/jpeg',
        ),
        returnForm: 'whiteBK',
      ),
    );

    print(result.data?.imageUrl);
  } finally {
    client.close();
  }
}

Flutter File Upload

AILabFile.fromBytes works across every Flutter platform, including web. For example, with an XFile selected by image_picker:

final bytes = await pickedFile.readAsBytes();
final result = await client.image.upscale(
  ImageLosslessEnlargementParams(
    image: AILabFile.fromBytes(
      bytes,
      filename: pickedFile.name,
      contentType: pickedFile.mimeType,
    ),
    upscaleFactor: 4,
  ),
);

print(result.data?.url);

The SDK exposes camelCase Dart fields and maps them to API request names. For example, upscaleFactor maps to upscale_factor, while returnForm maps to return_form.

Use case Dart method
Remove image background client.background.remove()
Upscale an image client.image.upscale()
Remove objects client.image.removeObjects()
Change a hairstyle client.portrait.changeHairstyle()
Retouch a portrait client.portrait.retouch()
Query account credits client.common.commonQueryCredits()

Every API also has a full method name matching the AILabTools API documentation.

Async Tasks

Some APIs return a task_id. Poll the task until it succeeds, fails, or times out:

final task = await client.portrait.changeHairstyle(params);
final taskId = task.taskId ?? task.data?.taskId;

final result = await client.waitForTask(
  taskId!,
  interval: const Duration(seconds: 5),
  timeout: const Duration(minutes: 5),
);

Error Handling

try {
  final result = await client.background.remove(params);
  print(result.data?.imageUrl);
} on AILabApiException catch (error) {
  print(error.message);
  print(error.requestId);
  print(error.logId);
}

Client Lifecycle

Call client.close() when the SDK creates its own HTTP client. An http.Client supplied through httpClient remains caller-owned and is not closed by the SDK.

License

MIT

Libraries

ailabtools