Developer SDK

The ZETRAXAI Node.js SDK

Integrate world-class AI prompt generation into your app in 3 lines of code. TypeScript-first, fully typed, zero dependencies.

Terminal zetrax-app
$

Quickstart Guide

From zero to generating prompts in under 2 minutes.

1

Install the package

Install via npm, yarn, or pnpm. The SDK ships with full TypeScript types no @types needed.

Shell
npm install @zetrax/sdk
2

Initialize the client

Import the SDK and create a client with your API key. Store your key securely in an environment variable never hardcode it.

TypeScript
import { ZetraxClient } from '@zetrax/sdk'; const zetrax = new ZetraxClient({ apiKey: process.env.ZETRAX_API_KEY, // ? from .env });
3

Generate your first prompt

Call prompts.generate() with a subject, style, and lighting. The SDK returns a fully-typed PromptResult object.

TypeScript
const result = await zetrax.prompts.generate({ subject: 'Epic Fantasy Landscape', style: 'Cinematic Film', lighting: 'Golden Hour', quality: 'ultra', }); console.log(result.prompt.text); // ? "A breathtaking cinematic fantasy landscape......" // Access usage stats console.log(result.usage.remaining); // ? "unlimited"

What's in the SDK

Full TypeScript Support

Complete type definitions for every request and response. IntelliSense auto-complete across all parameters.

Automatic Retries

Configurable retry logic with exponential backoff. Never lose a request to a transient network error.

Promise & Async/Await

First-class async support. Works seamlessly with Next.js Server Actions, Express, Fastify, and more.

Robust Error Handling & Config

Build resilient integrations with comprehensive error management and detailed client options.

Handling Exceptions

When integrating the ZETRAXAI SDK into your production server, it is highly recommended to wrap calls in try-catch blocks. The SDK throws custom errors (such as ZetraxError, ZetraxRateLimitError, or ZetraxAuthError) to help you handle API exceptions gracefully. This allows your application to differentiate between transient network errors, authorization failures, and monthly limit errors.

By handling these errors on your backend, you can present friendly error messages to your users or retry the operation after a delay, ensuring a seamless user experience.

TypeScript
try { const result = await client.prompts.generate({ subject: 'Cyberpunk City' }); } catch (error) { if (error.status === 429) { console.error('Rate limit exceeded. Please back off and retry later.'); } else if (error.status === 401) { console.error('Authentication failed. Please verify your API Key.'); } else { console.error('An unexpected SDK error occurred:', error.message); } }

Advanced Client Options

The ZetraxClient constructor accepts optional configuration parameters to customize its behavior. You can override the default request timeout, specify the maximum number of network retries for transient errors, and define custom HTTP headers for auditing or tracking.

  • timeout: The request timeout in milliseconds (default is 10,000ms).
  • maxRetries: The number of times to retry failed requests on 5xx errors (default is 3).
  • baseUrl: Useful for testing against local environments or staging servers.

These settings provide complete control over how your application communicates with the ZETRAXAI APIs, optimizing response latency and enhancing overall application robustness under varying network conditions.