Skip to main content

Using the Node SDK

The Dragoneye Node.js SDK simplifies integrating with our APIs in your JavaScript projects. This guide will walk you through installing the SDK and interacting with the Dragoneye classification API, providing detailed type definitions and example usage.

Installation

To get started, install the Dragoneye Node SDK via npm:

npm install dragoneye-node

Quick Start

Once the SDK is installed, you can call the classifier using your desired model name.

const file = <FILE BLOB>
const dragoneyeClient = new Dragoneye({
apiKey: "<YOUR_ACCESS_TOKEN>",
});

const results = await dragoneyeClient.classification.predict({
image: {
blob: file,
},
modelName: "dragoneye/fashion",
});

Types and Endpoints

Types

TaxonID

A TaxonID is a unique numeric identifier for each taxon (e.g., category or trait) used in the classification process.

export type TaxonID = number & { readonly brand: unique symbol };

To create a TaxonID, use the createTaxonID helper function:

export function createTaxonID(taxonId: number): TaxonID;

TaxonType

TaxonType defines the type of the taxon, either a "category" or a "trait":

NormalizedBbox

A normalized bounding box (NormalizedBbox) represents the location of an object in an image. It is an array of four numbers: [x_min, y_min, x_max, y_max].

TaxonPrediction

TaxonPrediction describes a taxon prediction returned by the API. Each prediction contains a unique identifier, the taxon type, its name, display name, and a score indicating confidence. Taxon predictions may have children representing hierarchical relationships (e.g., categories and subcategories).

export type TaxonPrediction = {
id: TaxonID;
type: TaxonType;
name: string;
displayName: string;
score?: number;
children: TaxonPrediction[];
};

ClassificationTraitRootPrediction

A ClassificationTraitRootPrediction contains the predictions for traits related to a specific object in an image.

export interface ClassificationTraitRootPrediction {
id: TaxonID;
name: string;
displayName: string;
taxons: TaxonPrediction[];
}

ClassificationObjectPrediction

An object prediction contains the normalized bounding box of the object, the predicted category, and related traits.

export interface ClassificationObjectPrediction {
normalizedBbox: NormalizedBbox;
category: TaxonPrediction;
traits: ClassificationTraitRootPrediction[];
}

ClassificationPredictImageResponse

This type represents the response structure when calling the predict method. It contains a list of predictions for each object detected in the image.

export interface ClassificationPredictImageResponse {
predictions: ClassificationObjectPrediction[];
}

ClassificationPredictImageRequest

The ClassificationPredictImageRequest defines the payload for making prediction requests. It includes the image and the model name used for classification.

export interface ClassificationPredictImageRequest {
image: Image;
modelName: string;
}

Endpoints

predict (Image Classification)

The predict method sends an image and model name to the Dragoneye API for classification and returns the results.

Arguments:
  • image: The image to be classified, provided as a file blob or URL.
  • modelName: The name of the classification model to use.
Response

The method returns a ClassificationPredictImageResponse, which contains predictions for each object detected in the image.