TutorialsGetting StartedNode.js Integration
BeginnerUpdated Dec 12, 2025

Node.js Integration

Learn async/await patterns for image generation with the JavaScript SDK, including error handling and streaming.

JL
Jordan Lee
Platform Engineer
4 min read

Installation

Install the Abstrakt JavaScript SDK:

npm install @abstrakt/sdk
# or
yarn add @abstrakt/sdk
# or
pnpm add @abstrakt/sdk

Basic Setup

javascript
import { AbstraktClient } from '@abstrakt/sdk';

const client = new AbstraktClient({
  apiKey: process.env.ABSTRAKT_API_KEY
});

Generating Images

javascript
async function generateImage() {
  const result = await client.run('fal-ai/flux/schnell', {
    input: {
      prompt: 'A serene Japanese garden with cherry blossoms',
      image_size: { width: 1024, height: 1024 },
      num_images: 1
    }
  });

  console.log('Generated image:', result.images[0].url);
  return result;
}

generateImage();

Handling Multiple Requests

Use Promise.all for concurrent generation:

javascript
async function generateMultiple(prompts) {
  const results = await Promise.all(
    prompts.map(prompt => 
      client.run('fal-ai/flux/schnell', {
        input: { prompt, image_size: { width: 512, height: 512 } }
      })
    )
  );

  return results.map(r => r.images[0].url);
}

const prompts = [
  'A mountain landscape at dawn',
  'A bustling city street at night',
  'A peaceful beach at sunset'
];

const images = await generateMultiple(prompts);

Streaming Progress

For long-running tasks, use streaming:

javascript
const stream = client.stream('fal-ai/flux/dev', {
  input: {
    prompt: 'An intricate fantasy castle',
    num_inference_steps: 50
  }
});

stream.on('progress', (progress) => {
  console.log(`Progress: ${progress.percentage}%`);
});

stream.on('complete', (result) => {
  console.log('Done!', result.images[0].url);
});

stream.on('error', (error) => {
  console.error('Generation failed:', error);
});

Express.js Integration

javascript
import express from 'express';
import { AbstraktClient } from '@abstrakt/sdk';

const app = express();
const client = new AbstraktClient();

app.post('/generate', async (req, res) => {
  try {
    const { prompt } = req.body;
    
    const result = await client.run('fal-ai/flux/schnell', {
      input: { prompt }
    });

    res.json({ imageUrl: result.images[0].url });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(3000);

Next Steps

#nodejs#javascript#async