Client API¶
The Client struct provides the main interface for image generation.
Creating a Client¶
ClientConfig¶
type ClientConfig struct {
// Providers is a list of provider configurations.
// Index 0 is the primary provider.
Providers []ProviderConfig
// Logger for internal logging (optional).
Logger *slog.Logger
}
ProviderConfig¶
type ProviderConfig struct {
// Provider is the provider name.
Provider ProviderName
// APIKey is the API key for authentication.
APIKey string
// BaseURL is an optional custom base URL for the API.
BaseURL string
// CustomProvider allows injecting a custom provider implementation.
CustomProvider provider.Provider
}
Example¶
client, err := omniimage.NewClient(omniimage.ClientConfig{
Providers: []omniimage.ProviderConfig{
{
Provider: omniimage.ProviderNameOpenAI,
APIKey: "sk-...",
},
},
})
if err != nil {
log.Fatal(err)
}
defer client.Close()
Methods¶
Generate¶
Generate images from a text prompt.
func (c *Client) Generate(ctx context.Context, req *provider.GenerateRequest) (*provider.GenerateResponse, error)
Example:
resp, err := client.Generate(ctx, &provider.GenerateRequest{
Model: omniimage.ModelGPTImage2,
Prompt: "A sunset over the ocean",
Size: provider.Size1024x1024,
N: 1,
})
Edit¶
Edit an existing image with a mask.
func (c *Client) Edit(ctx context.Context, req *provider.EditRequest) (*provider.EditResponse, error)
Returns ErrNotSupported if the provider doesn't support editing.
Example:
resp, err := client.Edit(ctx, &provider.EditRequest{
Model: omniimage.ModelDALLE2,
Image: "data:image/png;base64,...",
Mask: "data:image/png;base64,...",
Prompt: "Add a red car",
})
Variations¶
Create variations of an existing image.
func (c *Client) Variations(ctx context.Context, req *provider.VariationsRequest) (*provider.VariationsResponse, error)
Returns ErrNotSupported if the provider doesn't support variations.
Example:
resp, err := client.Variations(ctx, &provider.VariationsRequest{
Model: omniimage.ModelDALLE2,
Image: "data:image/png;base64,...",
N: 4,
})
Upscale¶
Upscale an image to a higher resolution.
func (c *Client) Upscale(ctx context.Context, req *provider.UpscaleRequest) (*provider.UpscaleResponse, error)
Returns ErrNotSupported if the provider doesn't support upscaling.
Example:
resp, err := client.Upscale(ctx, &provider.UpscaleRequest{
Model: omniimage.ModelClarityUpscaler,
Image: "https://example.com/image.jpg",
Scale: 2,
})
Capability Checks¶
// SupportsEdit returns true if the provider supports image editing.
func (c *Client) SupportsEdit() bool
// SupportsVariations returns true if the provider supports variations.
func (c *Client) SupportsVariations() bool
// SupportsUpscale returns true if the provider supports upscaling.
func (c *Client) SupportsUpscale() bool
Example:
Close¶
Release resources held by the client.
Example:
Provider¶
Get the underlying provider.
Helper Functions¶
GetCapabilities¶
Get provider capabilities without creating a client.
Capabilities struct:
type Capabilities struct {
Generate bool
Edit bool
Variations bool
Upscale bool
Models []string
MaxImages int
SupportedSizes []provider.ImageSize
}
Example:
caps := omniimage.GetCapabilities(omniimage.ProviderNameOpenAI)
if caps.Edit {
fmt.Println("Provider supports editing")
}
GetModelInfo¶
Get information about a specific model.
ModelInfo struct:
type ModelInfo struct {
ID string
Provider ProviderName
Name string
MaxImages int
SupportsHD bool
SupportsEdit bool
}
Example: