<dependency>
<groupId>ai.wavespeed</groupId>
<artifactId>wavespeed-java-sdk</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>Run WaveSpeed AI models with a simple API:
import ai.wavespeed.WaveSpeed;
import ai.wavespeed.openapi.client.model.Prediction;
import java.util.HashMap;
import java.util.Map;
public class Example {
public static void main(String[] args) {
WaveSpeed client = new WaveSpeed("your-api-key");
try {
Map<String, Object> input = new HashMap<>();
input.put("prompt", "Cat");
Prediction result = client.run("wavespeed-ai/z-image/turbo", input);
System.out.println(result.getOutputs().get(0)); // Output URL
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}Set your API key via environment variable (You can get your API key from https://wavespeed.ai/accesskey):
export WAVESPEED_API_KEY="your-api-key"Or pass it directly:
WaveSpeed client = new WaveSpeed("your-api-key");Prediction result = client.run(
"wavespeed-ai/z-image/turbo",
input,
300.0, // Max wait time in seconds (default: 36000.0)
2.0, // Status check interval (default: 1.0)
false // Single request mode, no polling (default: false)
);Use enableSyncMode: true for a single request that waits for the result (no polling).
Note: Not all models support sync mode. Check the model documentation for availability.
Prediction result = client.run(
"wavespeed-ai/z-image/turbo",
input,
null, // use default timeout
null, // use default poll interval
true // enable sync mode
);Configure retries when creating the client:
WaveSpeed client = new WaveSpeed(
"your-api-key",
null, // use default poll interval
null, // use default timeout
0, // Task-level retries (default: 0)
5, // HTTP connection retries (default: 5)
1.0 // Base delay between retries in seconds (default: 1.0)
);Upload images, videos, or audio files:
import ai.wavespeed.WaveSpeed;
WaveSpeed client = new WaveSpeed("your-api-key");
try {
String downloadUrl = client.upload("/path/to/image.png");
System.out.println(downloadUrl);
} catch (Exception e) {
System.err.println("Upload failed: " + e.getMessage());
}| Variable | Description |
|---|---|
WAVESPEED_API_KEY |
WaveSpeed API key |
MIT