JavaScript SDK

JavaScript SDK

The official JavaScript/TypeScript SDK for WaveSpeedAI. Run AI models in Node.js or browser environments.

Installation

npm install wavespeed

Or with yarn:

yarn add wavespeed

Quick Start

import wavespeed from 'wavespeed';
 
wavespeed.run("wavespeed-ai/flux-dev", {
  prompt: "A cat wearing a space suit"
})
.then(output => {
  console.log(output["outputs"][0]); // Output URL
});

Authentication

Get your API key from wavespeed.ai/accesskey.

Option 1: Environment variable (recommended)

export WAVESPEED_API_KEY="your-api-key"
import wavespeed from 'wavespeed';
 
// SDK automatically reads WAVESPEED_API_KEY from environment
wavespeed.run("wavespeed-ai/flux-dev", { prompt: "A cat" });

Option 2: Pass directly with Client

import { Client } from 'wavespeed';
 
const client = new Client("your-api-key");
client.run("wavespeed-ai/flux-dev", { prompt: "A cat" })
.then(output => console.log(output));

Configuration

Timeout & Polling

wavespeed.run("wavespeed-ai/flux-dev", {
  prompt: "A cat"
}, {
  timeout: 36000,      // Max wait time in seconds (default: 36000)
  pollInterval: 1.0    // Status check interval (default: 1.0)
})
.then(output => console.log(output));

Sync Mode

Some models support single-request execution without polling:

wavespeed.run("wavespeed-ai/flux-dev", {
  prompt: "A cat"
}, {
  enableSyncMode: true  // No polling, faster for supported models
})
.then(output => console.log(output));

Note: Not all models support sync mode.

Retry Configuration

import { Client } from 'wavespeed';
 
const client = new Client("your-api-key", {
  maxRetries: 3,              // Task-level retries (default: 0)
  maxConnectionRetries: 5,    // HTTP connection retries (default: 5)
  retryInterval: 1.0          // Delay between retries (default: 1.0)
});

File Upload

Upload images, videos, or audio files to use as model inputs:

import wavespeed from 'wavespeed';
 
wavespeed.upload("/path/to/image.png")
.then(url => {
  console.log(url); // Use this URL as input for models
});

Environment Variables

VariableDescription
WAVESPEED_API_KEYYour WaveSpeedAI API key
© 2025 WaveSpeedAI. All rights reserved.