go get github.com/WaveSpeedAI/wavespeed-goRun WaveSpeed AI models with a simple API:
import "github.com/WaveSpeedAI/wavespeed-go"
output, err := wavespeed.Run(
"wavespeed-ai/z-image/turbo",
map[string]any{"prompt": "Cat"},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(output["outputs"].([]any)[0]) // Output URLSet 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:
import "github.com/WaveSpeedAI/wavespeed-go/api"
client := api.NewClient(api.WithAPIKey("your-api-key"))
output, err := client.Run(
"wavespeed-ai/z-image/turbo",
map[string]any{"prompt": "Cat"},
)All parameters are optional. Use option functions to customize behavior:
output, err := wavespeed.Run(
"wavespeed-ai/z-image/turbo",
map[string]any{"prompt": "Cat"},
wavespeed.WithTimeout(60), // Max wait time in seconds
wavespeed.WithPollInterval(1.0), // Status check interval
wavespeed.WithSyncMode(true), // Enable synchronous mode
wavespeed.WithMaxRetries(3), // Maximum task retries
)Use WithSyncMode(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.
output, err := wavespeed.Run(
"wavespeed-ai/z-image/turbo",
map[string]any{"prompt": "Cat"},
wavespeed.WithSyncMode(true),
)Configure retries at the client level:
import "github.com/WaveSpeedAI/wavespeed-go/api"
client := api.NewClient(
api.WithAPIKey("your-api-key"),
api.WithClientMaxRetries(0), // Task-level retries (default: 0)
api.WithMaxConnectionRetries(5), // HTTP connection retries (default: 5)
api.WithRetryInterval(1.0), // Base delay between retries in seconds (default: 1.0)
)Upload images, videos, or audio files:
import "github.com/WaveSpeedAI/wavespeed-go"
// Simple upload
url, err := wavespeed.Upload("/path/to/image.png")
if err != nil {
log.Fatal(err)
}
fmt.Println(url)
// With timeout
url, err := wavespeed.Upload("/path/to/image.png", wavespeed.WithUploadTimeout(30))# Run all tests
go test -v ./...
# Run a single test file
go test -v ./api
# Run a specific test
go test -v -run TestRunSuccess ./api| Variable | Description |
|---|---|
WAVESPEED_API_KEY |
WaveSpeed API key |
MIT