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.
Quickstart Guide
From zero to generating prompts in under 2 minutes.
Install the package
Install via npm, yarn, or pnpm. The SDK ships with full TypeScript types no @types needed.
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.
Generate your first prompt
Call prompts.generate() with a subject, style, and lighting. The SDK returns a fully-typed PromptResult object.
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.
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.