Skip to main content
Flux provides official SDKs for Node.js, Python, Go, and Ruby. Each SDK provides idiomatic access to the Flux API with built-in retry logic, type safety, and error handling.

Installation

npm install @flux/node
The Node.js SDK supports Node 18+ and includes TypeScript definitions.

Configuration

Initialize the client with your API key:
import Flux from '@flux/node';

const flux = new Flux(process.env.FLUX_API_KEY, {
  // Optional configuration
  timeout: 30000,        // Request timeout in ms
  maxRetries: 3,         // Retry failed requests
  baseUrl: 'https://api.flux.dev/v1'  // API endpoint
});

Configuration Options

OptionDefaultDescription
timeout30000Request timeout in milliseconds
maxRetries3Number of retries for failed requests
baseUrlhttps://api.flux.dev/v1API base URL

Error Handling

The SDK throws typed errors that you can catch and handle:
import Flux, { FluxError, RateLimitError, AuthenticationError } from '@flux/node';

try {
  await flux.events.send({ type: 'test', data: {} });
} catch (error) {
  if (error instanceof RateLimitError) {
    // Wait and retry
    console.log(`Rate limited. Retry after ${error.retryAfter}s`);
  } else if (error instanceof AuthenticationError) {
    // Invalid API key
    console.error('Check your API key');
  } else if (error instanceof FluxError) {
    // Other API error
    console.error(error.message, error.code);
  }
}

Next Steps