Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 28 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,15 @@ npm install wavespeed
```javascript
const { WaveSpeed } = require('wavespeed');

// Initialize the client with your API key
const client = new WaveSpeed('YOUR_API_KEY');
const client = new WaveSpeed(); // reads WAVESPEED_API_KEY from env

// Generate an image and wait for the result
async function generateImage() {
const prediction = await client.run(
'wavespeed-ai/flux-dev',
{
prompt: 'A futuristic cityscape with flying cars and neon lights',
size: '1024*1024',
num_inference_steps: 28,
guidance_scale: 5.0,
num_images: 1,
seed: -1,
enable_safety_checker: true
}
'wavespeed-ai/z-image/turbo',
{ prompt: 'A simple red circle on white background' }
);

// Print the generated image URLs
prediction.outputs.forEach((imgUrl, i) => {
console.log(`Image ${i+1}: ${imgUrl}`);
});
prediction.outputs.forEach((imgUrl) => console.log(imgUrl));
}

generateImage().catch(console.error);
Expand All @@ -47,27 +34,15 @@ generateImage().catch(console.error);
```typescript
import WaveSpeed from 'wavespeed';

// Initialize the client with your API key
const client = new WaveSpeed('YOUR_API_KEY');
const client = new WaveSpeed(); // reads WAVESPEED_API_KEY from env

// Generate an image and wait for the result
async function generateImage(): Promise<void> {
const input: Record<string, any> = {
prompt: 'A futuristic cityscape with flying cars and neon lights',
size: '1024*1024',
num_inference_steps: 28,
guidance_scale: 5.0,
num_images: 1,
seed: -1,
enable_safety_checker: true
};

const prediction = await client.run('wavespeed-ai/flux-dev', input);

// Print the generated image URLs
prediction.outputs.forEach((imgUrl, i) => {
console.log(`Image ${i+1}: ${imgUrl}`);
});
const prediction = await client.run(
'wavespeed-ai/z-image/turbo',
{ prompt: 'A simple red circle on white background' }
);

prediction.outputs.forEach((imgUrl) => console.log(imgUrl));
}

generateImage().catch(console.error);
Expand All @@ -86,11 +61,7 @@ const client = new WaveSpeed('YOUR_API_KEY');
async function generateWithManualPolling(): Promise<void> {
// Create a prediction without waiting
const prediction = await client.create('wavespeed-ai/flux-dev', {
prompt: 'A beautiful mountain landscape at sunset',
size: '1024*1024',
num_inference_steps: 28,
guidance_scale: 5.0,
num_images: 1
prompt: 'A beautiful mountain landscape at sunset'
});

console.log(`Prediction created with ID: ${prediction.id}`);
Expand Down Expand Up @@ -129,35 +100,43 @@ generateWithManualPolling().catch(console.error);
new WaveSpeed(apiKey?: string, options?: {
baseUrl?: string,
pollInterval?: number,
timeout?: number
timeout?: number // overall wait timeout (seconds)
})
```

#### Parameters:
- `apiKey` (string): Your WaveSpeed API key
- `options` (object, optional):
- `baseUrl` (string): API base URL (default: 'https://api.wavespeed.ai/api/v2/')
- `baseUrl` (string): API base URL without path (default: 'https://api.wavespeed.ai'; e.g. `https://your.domain` if self-hosted)
- `pollInterval` (number): Interval in seconds for polling prediction status (default: 1)
- `timeout` (number): Timeout in seconds for API requests (default: 60)
- `timeout` (number): Overall wait timeout in seconds for a run (default: 36000)

### Methods

#### run

```typescript
run(modelId: string, input: Record<string, any>, options?: RequestOptions): Promise<Prediction>
run(modelId: string, input: Record<string, any>, options?: { pollInterval?: number; timeout?: number }): Promise<Prediction>
```

Generate an image and wait for the result.

#### create

```typescript
create(modelId: string, input: Record<string, any>, options?: RequestOptions): Promise<Prediction>
create(modelId: string, input: Record<string, any>, options?: { pollInterval?: number; timeout?: number }): Promise<Prediction>
```

Create a prediction without waiting for it to complete.

#### upload

```typescript
upload(filePath: string): Promise<string>
```

Upload a file by local path (Node) and get a `download_url` for use as model input.

### Prediction Model

The Prediction object contains information about an image generation job:
Expand All @@ -178,15 +157,16 @@ prediction.executionTime // Time taken to execute the prediction in milliseconds
#### Methods

```typescript
prediction.wait(): Promise<Prediction> // Wait for the prediction to complete
prediction.wait(pollIntervalSeconds?: number, timeoutSeconds?: number): Promise<Prediction> // Wait for the prediction to complete with optional overrides
prediction.reload(): Promise<Prediction> // Reload the prediction status
```

## Environment Variables

- `WAVESPEED_API_KEY`: Your WaveSpeed API key
- `WAVESPEED_BASE_URL`: API base URL without path (default: https://api.wavespeed.ai)
- `WAVESPEED_POLL_INTERVAL`: Interval in seconds for polling prediction status (default: 1)
- `WAVESPEED_TIMEOUT`: Timeout in seconds for API requests (default: 60)
- `WAVESPEED_TIMEOUT`: Overall wait timeout in seconds for a run (default: 36000)

## License

Expand Down
Loading