Documentation
¶
Index ¶
- func Run(model string, input map[string]any, opts ...RunOption) (map[string]any, error)
- func Upload(file string, opts ...UploadOption) (string, error)
- type Client
- type ClientOption
- func WithAPIKey(apiKey string) ClientOption
- func WithBaseURL(baseURL string) ClientOption
- func WithClientMaxRetries(maxRetries int) ClientOption
- func WithConnectionTimeout(timeout float64) ClientOption
- func WithMaxConnectionRetries(maxRetries int) ClientOption
- func WithRetryInterval(interval float64) ClientOption
- type ClientOptions
- type RunOption
- type RunOptions
- type UploadOption
- type UploadOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
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),
)
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 ¶
WithMaxRetries sets the maximum number of task-level retries.
func WithPollInterval ¶
WithPollInterval sets the interval between status checks.
func WithSyncMode ¶
WithSyncMode enables or disables synchronous mode.
func WithTimeout ¶
WithTimeout sets the maximum time to wait for completion.
type RunOptions ¶
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.