wavespeed

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 13 Imported by: 0

README

WaveSpeedAI logo

WaveSpeedAI Go SDK

Official Go SDK for the WaveSpeedAI inference platform

🌐 Visit wavespeed.ai • 📖 Documentation • 💬 Issues


Installation

go get github.com/WaveSpeedAI/wavespeed-go

API Client

Run WaveSpeed AI models with a simple API:

import wavespeed "github.com/WaveSpeedAI/wavespeed-go"

client, err := wavespeed.NewClient("")
if err != nil {
	log.Fatal(err)
}

output, err := client.Run("wavespeed-ai/z-image/turbo", map[string]any{
	"prompt": "Cat",
})
if err != nil {
	log.Fatal(err)
}

fmt.Println(output.Outputs[0]) // Output URL

Or with direct API key:

client, err := wavespeed.NewClient("your-api-key")
output, err := client.Run("wavespeed-ai/z-image/turbo", map[string]any{
	"prompt": "Cat",
})

Authentication

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 when creating the client (see examples above).

Options

output, err := client.Run("wavespeed-ai/z-image/turbo", map[string]any{
	"prompt": "Cat",
}, &wavespeed.RunOptions{
	TimeoutSeconds:      36000, // Max wait time in seconds (default: 36000)
	PollIntervalSeconds: 1,     // Status check interval (default: 1)
	EnableSyncMode:      false, // Single request mode, no polling (default: false)
})

Sync Mode

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.

output, err := client.Run("wavespeed-ai/z-image/turbo", map[string]any{
	"prompt": "Cat",
}, &wavespeed.RunOptions{
	EnableSyncMode: true,
})

Retry Configuration

Configure retries at the client level:

client, err := wavespeed.NewClient("your-api-key", &wavespeed.ClientOptions{
	MaxRetries:           0, // Task-level retries (default: 0)
	MaxConnectionRetries: 5, // HTTP connection retries (default: 5)
	RetryInterval:        1, // Base delay between retries in seconds (default: 1)
})

Upload Files

Upload images, videos, or audio files:

url, err := client.Upload("/path/to/image.png")
if err != nil {
	log.Fatal(err)
}
fmt.Println(url)

Environment Variables

API Client

Variable Description
WAVESPEED_API_KEY WaveSpeed API key
WAVESPEED_BASE_URL API base URL without path (default: https://api.wavespeed.ai)
WAVESPEED_POLL_INTERVAL Poll interval seconds for Run (default: 1)
WAVESPEED_TIMEOUT Overall wait timeout seconds for Run (default: 36000)

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides methods to run models and upload files.

func NewClient

func NewClient(apiKey string, opts *ClientOptions) (*Client, error)

NewClient creates a new WaveSpeed client. If apiKey is empty, it reads WAVESPEED_API_KEY from the environment.

func (*Client) Run

func (c *Client) Run(modelID string, input map[string]any, opts *RunOptions) (*Prediction, error)

Run submits a model and waits for completion.

func (*Client) Upload

func (c *Client) Upload(filePath string) (string, error)

Upload uploads a local file and returns download_url.

type ClientOptions

type ClientOptions struct {
	BaseURL              string   // API base URL without path (default: https://api.wavespeed.ai)
	APIKey               string   // overrides provided apiKey or env
	PollIntervalSeconds  *float64 // default: 1
	TimeoutSeconds       *float64 // overall wait timeout, default: 36000
	HTTPClient           *http.Client
	MaxRetries           *int     // task-level retries (default: 0)
	MaxConnectionRetries *int     // HTTP connection retries (default: 5)
	RetryInterval        *float64 // base delay between retries in seconds (default: 1)
}

ClientOptions configures the client at construction time.

type Prediction

type Prediction struct {
	ID      string   `json:"id"`
	Model   string   `json:"model"`
	Status  string   `json:"status"`
	Input   any      `json:"input"`
	Outputs []string `json:"outputs"`
	Error   string   `json:"error"`
}

Prediction matches the API response data for a prediction.

type RunOptions

type RunOptions struct {
	TimeoutSeconds      *float64 // overall wait timeout for this call
	PollIntervalSeconds *float64 // poll interval for this call
	EnableSyncMode      *bool    // if true, use synchronous mode (single request)
	MaxRetries          *int     // maximum retries for this request (overrides client default)
}

RunOptions applies to a single Run call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL