api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(model string, input map[string]any, opts ...RunOption) (map[string]any, error)

Run executes a model and waits for the output.

Args:

  • model: Model identifier (e.g., "wavespeed-ai/flux-dev").
  • input: Input parameters for the model.
  • opts: Optional parameters (WithTimeout, WithSyncMode, etc.)

Returns:

  • map[string]any containing "outputs" array with model outputs.

Example:

// Simple usage
output, _ := api.Run("wavespeed-ai/z-image/turbo", map[string]any{"prompt": "Cat"})
fmt.Println(output["outputs"].([]any)[0])

// With options
output, _ := api.Run(
    "wavespeed-ai/z-image/turbo",
    map[string]any{"prompt": "Cat"},
    api.WithSyncMode(true),
    api.WithTimeout(60),
)

func Upload

func Upload(file string, opts ...UploadOption) (string, error)

Upload uploads a file to WaveSpeed.

Args:

  • file: File path string to upload.
  • opts: Optional upload options (WithUploadTimeout, etc.)

Returns:

  • URL of the uploaded file.

Example:

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

// With timeout
url, err := api.Upload("/path/to/image.png", api.WithUploadTimeout(30))

Types

type Client

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

Client is the WaveSpeed API client.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new WaveSpeed API client with optional configuration.

All parameters are optional and can be configured using functional options. If not specified, the following defaults are used:

  • apiKey: from WAVESPEED_API_KEY environment variable
  • baseURL: "https://api.wavespeed.ai"
  • connectionTimeout: 10.0 seconds
  • maxRetries: 0 (no task-level retries)
  • maxConnectionRetries: 5
  • retryInterval: 1.0 second

Example:

// With defaults (API key from environment)
client := api.NewClient()

// With custom API key
client := api.NewClient(api.WithAPIKey("your-api-key"))

// With multiple options
client := api.NewClient(
    api.WithAPIKey("your-api-key"),
    api.WithClientMaxRetries(3),
    api.WithRetryInterval(2.0),
)

func (*Client) Run

func (c *Client) Run(model string, input map[string]any, opts ...RunOption) (map[string]any, error)

Run executes a model and waits for the output.

func (*Client) Upload

func (c *Client) Upload(file string, opts ...UploadOption) (string, error)

Upload uploads a file to WaveSpeed.

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that configures a Client.

func WithAPIKey

func WithAPIKey(apiKey string) ClientOption

WithAPIKey sets the API key for the client.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL sets the base URL for the client.

func WithClientMaxRetries

func WithClientMaxRetries(maxRetries int) ClientOption

WithClientMaxRetries sets the maximum number of task-level retries.

func WithConnectionTimeout

func WithConnectionTimeout(timeout float64) ClientOption

WithConnectionTimeout sets the connection timeout in seconds.

func WithMaxConnectionRetries

func WithMaxConnectionRetries(maxRetries int) ClientOption

WithMaxConnectionRetries sets the maximum number of HTTP connection retries.

func WithRetryInterval

func WithRetryInterval(interval float64) ClientOption

WithRetryInterval sets the base interval between retries in seconds.

type ClientOptions

type ClientOptions struct {
	APIKey               string
	BaseURL              string
	ConnectionTimeout    float64
	MaxRetries           int
	MaxConnectionRetries int
	RetryInterval        float64
}

ClientOptions configures the client at initialization time.

type RunOption

type RunOption func(*RunOptions)

RunOption is a function that configures RunOptions.

func WithMaxRetries

func WithMaxRetries(retries int) RunOption

WithMaxRetries sets the maximum number of task-level retries.

func WithPollInterval

func WithPollInterval(interval float64) RunOption

WithPollInterval sets the interval between status checks.

func WithSyncMode

func WithSyncMode(enable bool) RunOption

WithSyncMode enables or disables synchronous mode.

func WithTimeout

func WithTimeout(timeout float64) RunOption

WithTimeout sets the maximum time to wait for completion.

type RunOptions

type RunOptions struct {
	Timeout        float64
	PollInterval   float64
	EnableSyncMode bool
	MaxRetries     int
}

RunOptions contains optional parameters for Run.

type UploadOption

type UploadOption func(*UploadOptions)

UploadOption is a function that configures UploadOptions.

func WithUploadTimeout

func WithUploadTimeout(timeout float64) UploadOption

WithUploadTimeout sets the timeout for file upload.

type UploadOptions

type UploadOptions struct {
	Timeout float64
}

UploadOptions contains optional parameters for Upload.

Jump to

Keyboard shortcuts

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