@@ -33,11 +33,11 @@ const WaveSpeed = require('wavespeed');
3333
3434const client = new WaveSpeed (' your-api-key' );
3535
36- client .run (' wavespeed-ai/z-image/turbo' , { prompt : ' Cat ' })
37- . then ( prediction => {
38- console . log ( prediction . outputs [ 0 ]); // Output URL
39- })
40- . catch ( console . error );
36+ const prediction = await client .run (' wavespeed-ai/z-image/turbo' , {
37+ prompt : ' Cat '
38+ });
39+
40+ console . log ( prediction . outputs [ 0 ]); // Output URL
4141```
4242
4343Or with TypeScript:
@@ -51,7 +51,7 @@ const prediction = await client.run('wavespeed-ai/z-image/turbo', {
5151 prompt: ' Cat'
5252});
5353
54- console .log (prediction .outputs [0 ]); // Output URL
54+ console .log (prediction .outputs [0 ]); // Output URL
5555```
5656
5757### Authentication
@@ -65,24 +65,24 @@ export WAVESPEED_API_KEY="your-api-key"
6565Or pass it directly:
6666
6767``` javascript
68+ const WaveSpeed = require (' wavespeed' );
69+
6870const client = new WaveSpeed (' your-api-key' );
71+ const prediction = await client .run (' wavespeed-ai/z-image/turbo' , { prompt: ' Cat' });
6972```
7073
7174### Options
7275
7376``` javascript
74- const client = new WaveSpeed (' your-api-key' , {
75- timeout: 36000 , // Max wait time in seconds (default: 36000)
76- pollInterval: 1 , // Status check interval (default: 1)
77- });
78-
79- const prediction = await client .run (' wavespeed-ai/z-image/turbo' , {
80- prompt: ' Cat'
81- }, {
82- timeout: 300 , // Override timeout for this request
83- pollInterval: 2 , // Override poll interval for this request
84- enableSyncMode: false , // Single request mode, no polling (default: false)
85- });
77+ const prediction = await client .run (
78+ ' wavespeed-ai/z-image/turbo' ,
79+ { prompt: ' Cat' },
80+ {
81+ timeout: 36000 , // Max wait time in seconds (default: 36000)
82+ pollInterval: 1 , // Status check interval (default: 1)
83+ enableSyncMode: false , // Single request mode, no polling (default: false)
84+ }
85+ );
8686```
8787
8888### Sync Mode
@@ -92,18 +92,20 @@ Use `enableSyncMode: true` for a single request that waits for the result (no po
9292> ** Note:** Not all models support sync mode. Check the model documentation for availability.
9393
9494``` javascript
95- const prediction = await client .run (' wavespeed-ai/z-image/turbo ' , {
96- prompt : ' Cat '
97- }, {
98- enableSyncMode: true
99- } );
95+ const prediction = await client .run (
96+ ' wavespeed-ai/z-image/turbo ' ,
97+ { prompt : ' Cat ' },
98+ { enableSyncMode: true }
99+ );
100100```
101101
102102### Retry Configuration
103103
104104Configure retries at the client level:
105105
106106``` javascript
107+ const WaveSpeed = require (' wavespeed' );
108+
107109const client = new WaveSpeed (' your-api-key' , {
108110 maxRetries: 0 , // Task-level retries (default: 0)
109111 maxConnectionRetries: 3 , // HTTP connection retries (default: 3)
@@ -116,63 +118,10 @@ const client = new WaveSpeed('your-api-key', {
116118Upload images, videos, or audio files:
117119
118120``` javascript
119- client .upload (' /path/to/image.png' )
120- .then (url => console .log (url))
121- .catch (console .error );
122- ```
123-
124- ## API Reference
125-
126- ### WaveSpeed Client
127-
128- ``` typescript
129- new WaveSpeed (apiKey ?: string , options ?: {
130- baseUrl?: string ,
131- pollInterval?: number ,
132- timeout?: number
133- })
134- ```
135-
136- #### Parameters:
137- - ` apiKey ` (string): Your WaveSpeed API key
138- - ` options ` (object, optional):
139- - ` baseUrl ` (string): API base URL without path (default: ` https://api.wavespeed.ai ` )
140- - ` pollInterval ` (number): Poll interval in seconds (default: 1)
141- - ` timeout ` (number): Overall wait timeout in seconds (default: 36000)
142-
143- ### Methods
144-
145- #### run
146-
147- ``` typescript
148- run (modelId : string , input : Record < string , any > , options ?: { pollInterval?: number ; timeout ?: number }): Promise < Prediction >
149- ```
150-
151- Run a model and wait for completion.
152-
153- #### create
154-
155- ``` typescript
156- create (modelId : string , input : Record < string , any > ): Promise < Prediction >
157- ```
158-
159- Create a prediction without waiting for completion.
160-
161- #### upload
162-
163- ``` typescript
164- upload (filePath : string ): Promise < string >
165- ```
166-
167- Upload a file and get a download URL.
168-
169- ### Prediction
121+ const WaveSpeed = require (' wavespeed' );
170122
171- ``` typescript
172- prediction .id // Unique prediction ID
173- prediction .status // Status: processing, completed, failed
174- prediction .outputs // Array of output URLs
175- prediction .error // Error message if failed
123+ const url = await client .upload (' /path/to/image.png' );
124+ console .log (url);
176125```
177126
178127## Environment Variables
@@ -182,9 +131,6 @@ prediction.error // Error message if failed
182131| Variable | Description |
183132| ----------| -------------|
184133| ` WAVESPEED_API_KEY ` | WaveSpeed API key |
185- | ` WAVESPEED_BASE_URL ` | API base URL without path (default: ` https://api.wavespeed.ai ` ) |
186- | ` WAVESPEED_POLL_INTERVAL ` | Poll interval seconds for ` run ` (default: ` 1 ` ) |
187- | ` WAVESPEED_TIMEOUT ` | Overall wait timeout seconds for ` run ` (default: ` 36000 ` )
188134
189135## License
190136
0 commit comments