SDK
sdk.tag()
Classify images and generate tags using AI
sdk.tag()
Classify images with a custom prompt, optionally constraining to a list of options. Supports both cloud API and local in-browser processing via transformers.js.
Interactive Demo
Try it out ↓
Signature
sdk.tag(image: string, options: TagOptions): Promise<TagResponse>Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
image | string | Yes | Image URL or base64 data URI |
options.prompt | string | Yes | The classification question or context |
options.options | string[] | No | Constrained list of valid tags to choose from |
options.multiple | boolean | No | Allow multiple tags (default: true) |
options.mode | string | No | "api" (default) or "local" (in-browser via transformers.js) |
Returns
Promise<TagResponse>:
{
tags: string[]; // selected tags
raw: unknown; // raw model response
}Examples
import { CoreViz } from '@coreviz/sdk';
const sdk = new CoreViz({ apiKey: process.env.COREVIZ_API_KEY });
// Open-ended tagging
const { tags } = await sdk.tag('https://example.com/product.jpg', {
prompt: 'What objects are visible in this image?',
});
console.log(tags); // ["red sneaker", "white background", "shoelace"]
// Single-choice classification
const { tags: [category] } = await sdk.tag('https://example.com/doc.jpg', {
prompt: 'What type of document is this?',
options: ['receipt', 'invoice', 'contract', 'other'],
multiple: false,
});
console.log(category); // "receipt"
// Local processing (no API key needed, runs in browser)
const { tags: localTags } = await sdk.tag(imageBase64, {
prompt: 'Describe the scene',
mode: 'local',
});Use Cases
- Document classification — classify receipts, invoices, contracts
- Content moderation — flag inappropriate content
- Product categorization — auto-tag e-commerce products
- Auto-organization — tag images on upload for searchability
Local mode
mode: 'local' runs entirely in the browser or Node.js using transformers.js — no API call is made. Results may differ from the cloud model. Not supported on React Native / Expo.
Raw API Endpoint
This method calls POST /api/ai/tag. See the Vision API Reference for raw HTTP details.