Installation
npm install @avala-ai/sdk
Quick Start
import Avala from "@avala-ai/sdk";
const avala = new Avala({ apiKey: "your-api-key" });
const datasets = await avala.datasets.list();
for (const dataset of datasets.items) {
console.log(dataset.name, dataset.uid);
}
Create an Account
The signup function creates a new Avala account and returns an API key. It does not require authentication.
import { signup } from "@avala-ai/sdk";
const result = await signup({
email: "dev@acme.com",
password: "SecurePass123!",
firstName: "Jane", // optional
lastName: "Doe", // optional
});
console.log(`User: ${result.user.email}`);
console.log(`API Key: ${result.apiKey}`);
Use the returned API key to initialize the client:
import Avala, { signup } from "@avala-ai/sdk";
const { apiKey } = await signup({ email: "dev@acme.com", password: "SecurePass123!" });
const avala = new Avala({ apiKey });
Authentication
The SDK authenticates using your Avala API key, which is sent via the X-Avala-Api-Key header on every request.
You can provide the key directly or let the SDK read it from the environment.
Option 1: Pass the key directly
import Avala from "@avala-ai/sdk";
const avala = new Avala({ apiKey: "your-api-key" });
Option 2: Use an environment variable
export AVALA_API_KEY="your-api-key"
import Avala from "@avala-ai/sdk";
// Automatically reads AVALA_API_KEY from the environment
const avala = new Avala();
Working with Datasets
The TypeScript SDK is currently read-only for datasets — you can list and retrieve datasets but not create, update, or delete them. Use the REST API for uploads and mutations.
List Datasets
const datasets = await avala.datasets.list();
for (const dataset of datasets.items) {
console.log(`${dataset.name} (${dataset.uid})`);
console.log(` Items: ${dataset.itemCount}`);
console.log(` Created: ${dataset.createdAt}`);
}
Get a Dataset
const dataset = await avala.datasets.get("550e8400-e29b-41d4-a716-446655440000");
console.log(dataset.name);
console.log(dataset.slug);
console.log(dataset.itemCount);
Working with Projects
List Projects
const projects = await avala.projects.list();
for (const project of projects.items) {
console.log(`${project.name} (${project.uid})`);
console.log(` Status: ${project.status}`);
console.log(` Created: ${project.createdAt}`);
}
Get a Project
const project = await avala.projects.get("770a9600-a40d-63f6-c938-668877660000");
console.log(project.name);
console.log(project.status);
Working with Tasks
List Tasks
const tasks = await avala.tasks.list({
project: "770a9600-a40d-63f6-c938-668877660000",
status: "pending",
});
for (const task of tasks.items) {
console.log(`${task.uid} — ${task.name} (${task.status})`);
}
Get a Task
const task = await avala.tasks.get("990c1800-b62f-85a8-e150-880099880000");
console.log(task.name);
console.log(task.status);
Working with Exports
Create an Export
const exportJob = await avala.exports.create({
project: "770a9600-a40d-63f6-c938-668877660000",
});
console.log(`Export started: ${exportJob.uid}`);
console.log(`Status: ${exportJob.status}`);
Poll for Completion
let exportJob = await avala.exports.create({
project: "770a9600-a40d-63f6-c938-668877660000",
});
while (exportJob.status !== "completed") {
await new Promise((resolve) => setTimeout(resolve, 2000));
exportJob = await avala.exports.get(exportJob.uid);
console.log(`Status: ${exportJob.status}`);
}
console.log(`Download: ${exportJob.downloadUrl}`);
TypeScript Types
The SDK exports full TypeScript interfaces for all API objects. Use them to type your functions and variables.
import Avala from "@avala-ai/sdk";
import type { Dataset, Project, Export, Task, CursorPage } from "@avala-ai/sdk";
function processDataset(dataset: Dataset): void {
console.log(dataset.name); // string
console.log(dataset.uid); // string
console.log(dataset.itemCount); // number
console.log(dataset.createdAt); // string | null
}
function processTask(task: Task): void {
console.log(task.uid); // string
console.log(task.name); // string | null
console.log(task.status); // string | null
console.log(task.project); // string | null
}
Error Handling
The SDK throws typed errors so you can handle different failure modes precisely.
import Avala, { AvalaError, NotFoundError, RateLimitError } from "@avala-ai/sdk";
const avala = new Avala();
try {
const dataset = await avala.datasets.get("nonexistent");
} catch (error) {
if (error instanceof NotFoundError) {
console.log(`Dataset not found: ${error.message}`);
} else if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${error.retryAfter} seconds.`);
} else if (error instanceof AvalaError) {
console.log(`API error (${error.statusCode}): ${error.message}`);
} else {
throw error;
}
}
| Exception | Description |
|---|
AvalaError | Base error class for all Avala API errors. |
AuthenticationError | Invalid or missing API key (HTTP 401). |
NotFoundError | The requested resource does not exist (HTTP 404). |
RateLimitError | You have exceeded the API rate limit (HTTP 429). Includes a retryAfter property. |
ValidationError | The request payload failed validation (HTTP 400/422). |
ServerError | The server returned an internal error (HTTP 5xx). |
List methods return a CursorPage<T> object with cursor-based pagination.
// Access items on the current page
const page = await avala.datasets.list({ limit: 10 });
for (const dataset of page.items) {
console.log(dataset.name);
}
// Fetch the next page
if (page.hasMore) {
const nextPage = await avala.datasets.list({
limit: 10,
cursor: page.nextCursor!,
});
}
Working with Agents
Create an Agent
const agent = await avala.agents.create({
name: "QA Bot",
events: ["task.completed"],
callbackUrl: "https://example.com/webhook",
taskTypes: ["annotation"],
});
List Agent Executions
const executions = await avala.agents.listExecutions(agent.uid);
for (const exec of executions.items) {
console.log(`${exec.eventType} — ${exec.status}`);
}
Working with Webhooks
Create a Webhook
const webhook = await avala.webhooks.create({
targetUrl: "https://example.com/webhook",
events: ["task.completed", "export.ready"],
});
Inspect Deliveries
const deliveries = await avala.webhookDeliveries.list();
for (const d of deliveries.items) {
console.log(`${d.eventType} — ${d.status} (attempts: ${d.attempts})`);
}
Working with Quality & Consensus
Create a Quality Target
const target = await avala.qualityTargets.create("proj_uid", {
name: "Accuracy",
metric: "accuracy",
operator: "gte",
threshold: 0.95,
notifyEmails: ["alerts@example.com"],
});
Check Consensus
const summary = await avala.consensus.getSummary("proj_uid");
console.log(`Mean score: ${summary.meanScore}`);
console.log(`Coverage: ${summary.itemsWithConsensus}/${summary.totalItems}`);
Fleet Management
Fleet Management is in preview. APIs described here may change.
The fleet namespace provides access to device registry, recordings, events, rules, and alerts.
// List online devices
const devices = await avala.fleet.devices.list({ status: "online" });
// Create a timeline event on a recording
const event = await avala.fleet.events.create({
recordingId: "rec_abc123",
timestamp: "2026-01-15T10:30:00Z",
type: "anomaly",
label: "Gripper force spike",
metadata: { force_n: 45.2 },
});
// Create a recording rule
const rule = await avala.fleet.rules.create({
name: "High Latency Alert",
condition: { type: "threshold", topic: "/diagnostics/latency", field: "data.value", operator: "gt", value: 100 },
actions: [{ type: "tag", value: "high-latency" }, { type: "notify", channelId: "ch_your_channel_id" }],
});
See the Fleet Dashboard guide for complete examples.
Configuration
You can customize the client behavior at initialization time.
import Avala from "@avala-ai/sdk";
const avala = new Avala({
apiKey: "your-api-key",
baseUrl: "https://api.avala.ai/api/v1", // Default
timeout: 60_000, // Request timeout in ms (default: 30000)
});
| Parameter | Type | Default | Description |
|---|
apiKey | string | AVALA_API_KEY env var | Your Avala API key. |
baseUrl | string | https://api.avala.ai/api/v1 | The API base URL. |
timeout | number | 30000 | Request timeout in milliseconds. |
Zero Dependencies
The @avala-ai/sdk package has zero runtime dependencies. It uses the native fetch API available in Node.js 18+, Deno, and Bun.
Framework Examples
Next.js (App Router)
// app/api/datasets/route.ts
import Avala from "@avala-ai/sdk";
import { NextResponse } from "next/server";
const avala = new Avala({ apiKey: process.env.AVALA_API_KEY! });
export async function GET() {
const datasets = await avala.datasets.list();
return NextResponse.json(datasets);
}
Express
import express from "express";
import Avala from "@avala-ai/sdk";
const app = express();
const avala = new Avala(); // Reads AVALA_API_KEY from env
app.get("/datasets", async (req, res) => {
try {
const datasets = await avala.datasets.list();
res.json(datasets);
} catch (error) {
res.status(500).json({ error: "Failed to fetch datasets" });
}
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});