aiutils-sdk
v1.0.0
Published
AiUtils Developer API SDK for Node.js — 100+ AI models, one unified API
Maintainers
Readme
aiutils-sdk
Official Node.js/TypeScript SDK for the AiUtils Developer API — access 1400+ AI models (LLM, image, video, audio, 3D) through one unified API. v0.3.2
Install
npm install aiutils-sdkQuick Start
import AiUtils from 'aiutils-sdk';
const client = new AiUtils({ apiKey: 'ak-dev-YOUR_KEY' });
// Chat completion (OpenAI-compatible)
const chat = await client.chat.completions.create({
model: 'gen:deepseek:deepseek-v4-flash', // Cheapest LLM
messages: [{ role: 'user', content: 'Explain quantum computing' }],
max_tokens: 1000,
});
console.log(chat.choices[0].message.content);
console.log(`Cost: ${chat.usage.dt_consumed} DT`);Authentication
const client = new AiUtils({
apiKey: 'ak-dev-YOUR_KEY', // Required
baseUrl: 'https://developer-api.aiutils.io', // Default
timeout: 60000, // ms (default: 60s)
});Chat Completions
const response = await client.chat.completions.create({
model: 'gen:deepseek:deepseek-v4-flash',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is TypeScript?' },
],
temperature: 0.7,
max_tokens: 1000,
});Image Generation
const result = await client.generations.create({
model: 'elidia-2:flux/dev',
parameters: { prompt: 'A futuristic city at sunset', image_size: 'landscape_16_9' },
});
console.log(result.download_urls);Video Generation (async + webhook)
// Option 1: Block until done (auto-polling)
const video = await client.generations.create({
model: 'elidia-2:kling-video/v1.6/pro/text-to-video',
parameters: { prompt: 'Drone shot over mountains' },
wait_for_completion: true,
timeout: 300,
});
console.log(video.download_urls);
// Option 2: Fire-and-forget with webhook
const task = await client.generations.create({
model: 'elidia-2:kling-video/v1.6/pro/text-to-video',
parameters: { prompt: 'Ocean waves' },
wait_for_completion: false,
webhook_url: 'https://your-server.com/webhook/aiutils',
});
console.log(task.id, task.status); // "processing"Audio & 3D
// Text-to-speech
const audio = await client.generations.create({
model: 'elidia-2:playht/tts/v3',
parameters: { text: 'Hello world', voice: 'en-US-1' },
});
// 3D model
const mesh = await client.generations.create({
model: 'elidia-2:trellis',
parameters: { prompt: 'A medieval castle' },
wait_for_completion: true,
});Embeddings
const embeddings = await client.embeddings.create({
model: 'text-embedding-3-small',
input: ['Hello world', 'How are you?'],
});
console.log(embeddings.data[0].embedding.length); // 1536Model Catalog
// List models by category
const models = await client.models.list({ category: 'image', vendor: 'elidia-2' });
console.log(`${models.total} image models from Elidia-2`);
// Get model detail with input/output schema
const detail = await client.models.get('elidia-2:flux/dev');
console.log(detail.input_schema); // Full parameter schemaWallet & Billing
// Check balance
const balance = await client.wallet.balance();
console.log(`Available: ${balance.balance_dt} DT`);
console.log(`Used today: ${balance.daily_dt_used} DT`);
// Transaction history
const txns = await client.wallet.transactions({ limit: 10 });
txns.transactions.forEach(t =>
console.log(`${t.created_at} | ${t.type} | ${t.amount_dt} DT`)
);
// Estimate cost before running
const estimate = await client.wallet.estimateCost('gen:deepseek:deepseek-v4-flash', { max_tokens: 2000 });
console.log(`Estimated: ${estimate.estimated_dt} DT ($${estimate.estimated_usd.toFixed(4)})`);Webhooks
Global Webhook (all async results delivered here)
// Set global webhook
await client.webhooks.setConfig({
url: 'https://your-server.com/webhook/aiutils',
events: ['generation.completed', 'generation.failed', 'balance.low'],
secret: 'whsec_your_signing_secret',
});
// Check config
const config = await client.webhooks.getConfig();
console.log(config.is_active, config.url);
// View delivery history
const deliveries = await client.webhooks.listDeliveries({ limit: 10 });
deliveries.deliveries.forEach(d =>
console.log(`${d.event} | ${d.status} | HTTP ${d.response_code}`)
);
// Remove webhook
await client.webhooks.deleteConfig();Per-Request Webhook (overrides global)
await client.generations.create({
model: 'elidia-2:flux/dev',
parameters: { prompt: 'sunset' },
wait_for_completion: false,
webhook_url: 'https://your-server.com/webhook/job-123',
});Webhook Payload
{
"event": "generation.completed",
"generation_id": "abc123-...",
"status": "completed",
"model": "elidia-2:flux/dev",
"download_urls": ["https://cdn.aiutils.io/..."],
"dt_consumed": 5,
"created_at": 1721234567.89
}Headers: X-Webhook-Signature: sha256=... (HMAC of body using your secret).
Error Handling
import AiUtils, { AuthenticationError, InsufficientDTError, RateLimitError } from 'aiutils-sdk';
try {
await client.chat.completions.create({ ... });
} catch (e) {
if (e instanceof AuthenticationError) console.error('Bad API key');
if (e instanceof InsufficientDTError) console.error('Top up DT balance');
if (e instanceof RateLimitError) console.error('Back off and retry');
}Pricing
All usage = DT (Developer Tokens): 1 DT = $0.001 USD.
Formula: DT = CEIL(provider_cost * 1.08 * 1000) — platform fee, no hidden costs.
Use client.wallet.estimateCost(model, params) to check before running.
Billing Packages
// List DT packs
const packs = await client.billing.listPacks();
packs.forEach(p => console.log(`${p.name}: ${p.dt_amount} DT for $${p.price_usd}`));
// Create checkout
const checkout = await client.billing.checkout("pack_10k");
console.log(checkout);
// View invoice (returns PDF Buffer)
const invoiceBuffer = await client.billing.getInvoice("txn_abc123");
fs.writeFileSync("invoice.pdf", invoiceBuffer);File Upload
// Upload image for vision
const file = await client.files.upload("photo.jpg");
// List files
const files = await client.files.list();
files.forEach(f => console.log(`${f.id}: ${f.url}`));Portal Tools
// List tool categories
const genres = await client.tools.genres();
// Execute a tool
const result = await client.tools.execute("email-send", {
to: "[email protected]", subject: "Hello", body: "Test"
});Batch Requests
const batch = await client.batch.create({
requests: [
{ method: "POST", path: "/v1/chat/completions", body: { model: "...", messages: [...] }},
]
});
const status = await client.batch.status(batch.batch_id);