Documentation
¶
Overview ¶
Package omniimage provides a unified interface for image generation across multiple providers.
Supported providers:
- OpenAI (DALL-E 2, DALL-E 3)
- Fal AI (FLUX, Stable Diffusion)
Example usage:
client, err := omniimage.NewClient(omniimage.ClientConfig{
Providers: []omniimage.ProviderConfig{
{Provider: omniimage.ProviderNameOpenAI, APIKey: "sk-..."},
},
})
if err != nil {
log.Fatal(err)
}
defer client.Close()
resp, err := client.Generate(ctx, &provider.GenerateRequest{
Model: "dall-e-3",
Prompt: "A serene mountain landscape at sunset",
Size: provider.Size1024x1024,
})
Index ¶
- Constants
- Variables
- type APIError
- type Capabilities
- type Client
- func (c *Client) Close() error
- func (c *Client) Edit(ctx context.Context, req *provider.EditRequest) (*provider.EditResponse, error)
- func (c *Client) Generate(ctx context.Context, req *provider.GenerateRequest) (*provider.GenerateResponse, error)
- func (c *Client) Provider() provider.Provider
- func (c *Client) SupportsEdit() bool
- func (c *Client) SupportsUpscale() bool
- func (c *Client) SupportsVariations() bool
- func (c *Client) Upscale(ctx context.Context, req *provider.UpscaleRequest) (*provider.UpscaleResponse, error)
- func (c *Client) Variations(ctx context.Context, req *provider.VariationsRequest) (*provider.VariationsResponse, error)
- type ClientConfig
- type ModelInfo
- type ProviderConfig
- type ProviderName
Constants ¶
const ( // OpenAI GPT Image models (current) ModelGPTImage2 = "gpt-image-2" ModelGPTImage1 = "gpt-image-1" // OpenAI DALL-E models (legacy, dall-e-3 retired March 2026) ModelDALLE3 = "dall-e-3" ModelDALLE2 = "dall-e-2" // Fal AI FLUX models ModelFluxPro = "fal-ai/flux-pro" ModelFluxDev = "fal-ai/flux/dev" ModelFluxSchnell = "fal-ai/flux/schnell" // Fal AI Stable Diffusion models ModelSDXL = "fal-ai/fast-sdxl" ModelSD3 = "fal-ai/stable-diffusion-v3-medium" ModelSDXLTurbo = "fal-ai/fast-turbo-diffusion" ModelPlayground = "fal-ai/playground-v25" // Fal AI upscaling models ModelClarityUpscaler = "fal-ai/clarity-upscaler" ModelCreativeUpscale = "fal-ai/creative-upscaler" )
Model constants for image generation.
Variables ¶
var ( // ErrNoProviders is returned when no providers are configured. ErrNoProviders = errors.New("no providers configured") // ErrUnknownProvider is returned for an unknown provider name. ErrUnknownProvider = errors.New("unknown provider") // ErrNotSupported is returned when an operation is not supported. ErrNotSupported = errors.New("operation not supported") // ErrInvalidRequest is returned for invalid request parameters. ErrInvalidRequest = errors.New("invalid request") // ErrRateLimited is returned when the API rate limit is exceeded. ErrRateLimited = errors.New("rate limited") // ErrContentPolicy is returned when content violates the provider's policy. ErrContentPolicy = errors.New("content policy violation") // ErrModelNotFound is returned when the requested model is not available. ErrModelNotFound = errors.New("model not found") )
Errors returned by omniimage.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// StatusCode is the HTTP status code.
StatusCode int
// Code is the provider-specific error code.
Code string
// Message is the error message.
Message string
// Provider is the provider that returned the error.
Provider string
}
APIError represents an error from the image generation API.
type Capabilities ¶
type Capabilities struct {
// Generate indicates support for image generation.
Generate bool
// Edit indicates support for image editing.
Edit bool
// Variations indicates support for image variations.
Variations bool
// Upscale indicates support for image upscaling.
Upscale bool
// Models lists supported model IDs.
Models []string
// MaxImages is the maximum number of images per request.
MaxImages int
// SupportedSizes lists supported image sizes.
SupportedSizes []provider.ImageSize
}
Capabilities describes the features supported by a provider.
func GetCapabilities ¶
func GetCapabilities(name ProviderName) *Capabilities
GetCapabilities returns the capabilities for a provider.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main client for image generation.
func NewClient ¶
func NewClient(config ClientConfig) (*Client, error)
NewClient creates a new image generation client.
func (*Client) Edit ¶
func (c *Client) Edit(ctx context.Context, req *provider.EditRequest) (*provider.EditResponse, error)
Edit modifies an existing image based on a prompt. Returns ErrNotSupported if the provider doesn't support editing.
func (*Client) Generate ¶
func (c *Client) Generate(ctx context.Context, req *provider.GenerateRequest) (*provider.GenerateResponse, error)
Generate creates images from a text prompt.
func (*Client) SupportsEdit ¶
SupportsEdit returns true if the provider supports image editing.
func (*Client) SupportsUpscale ¶
SupportsUpscale returns true if the provider supports upscaling.
func (*Client) SupportsVariations ¶
SupportsVariations returns true if the provider supports variations.
func (*Client) Upscale ¶
func (c *Client) Upscale(ctx context.Context, req *provider.UpscaleRequest) (*provider.UpscaleResponse, error)
Upscale increases the resolution of an image. Returns ErrNotSupported if the provider doesn't support upscaling.
func (*Client) Variations ¶
func (c *Client) Variations(ctx context.Context, req *provider.VariationsRequest) (*provider.VariationsResponse, error)
Variations creates variations of an existing image. Returns ErrNotSupported if the provider doesn't support variations.
type 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
}
ClientConfig holds configuration for creating a client.
type ModelInfo ¶
type ModelInfo struct {
ID string
Provider ProviderName
Name string
MaxImages int
SupportsHD bool
SupportsEdit bool
}
ModelInfo contains information about a model.
func GetModelInfo ¶
GetModelInfo returns information about a model.
type 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
}
ProviderConfig configures a provider.
type ProviderName ¶
type ProviderName string
ProviderName identifies an image generation provider.
const ( // ProviderNameOpenAI is the OpenAI provider (DALL-E). ProviderNameOpenAI ProviderName = "openai" // ProviderNameFal is the Fal AI provider. ProviderNameFal ProviderName = "fal" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package provider defines the core interfaces that image generation providers must implement.
|
Package provider defines the core interfaces that image generation providers must implement. |
|
providers
|
|
|
fal
Package fal implements the image generation provider for Fal AI.
|
Package fal implements the image generation provider for Fal AI. |
|
openai
Package openai implements the image generation provider for OpenAI's image models.
|
Package openai implements the image generation provider for OpenAI's image models. |