omniimage

package module
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 7 Imported by: 0

README

OmniImage

Go CI Go Lint Go SAST Go Report Card Docs Docs Visualization License

Unified Go library for image generation across multiple providers.

Supported Providers

Provider Models Generate Edit Variations Upscale
OpenAI DALL-E 2, DALL-E 3 Yes Yes Yes No
Fal AI FLUX Pro/Dev/Schnell, SDXL Yes No No Yes

Installation

go get github.com/plexusone/omniimage

Quick Start

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/plexusone/omniimage"
    "github.com/plexusone/omniimage/provider"
)

func main() {
    // Create client with OpenAI provider
    client, err := omniimage.NewClient(omniimage.ClientConfig{
        Providers: []omniimage.ProviderConfig{
            {
                Provider: omniimage.ProviderNameOpenAI,
                APIKey:   "sk-...", // or use OPENAI_API_KEY env var
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    // Generate an image
    resp, err := client.Generate(context.Background(), &provider.GenerateRequest{
        Model:   omniimage.ModelDALLE3,
        Prompt:  "A serene mountain landscape at sunset",
        Size:    provider.Size1024x1024,
        Quality: provider.QualityHD,
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Generated image: %s\n", resp.Images[0].URL)
}

Providers

OpenAI (DALL-E)
client, _ := omniimage.NewClient(omniimage.ClientConfig{
    Providers: []omniimage.ProviderConfig{
        {
            Provider: omniimage.ProviderNameOpenAI,
            APIKey:   "sk-...", // or OPENAI_API_KEY env var
        },
    },
})

// DALL-E 3 - high quality, single image
resp, _ := client.Generate(ctx, &provider.GenerateRequest{
    Model:   omniimage.ModelDALLE3,
    Prompt:  "A futuristic cityscape",
    Size:    provider.Size1024x1024,
    Quality: provider.QualityHD,
    Style:   provider.StyleVivid,
})

// DALL-E 2 - multiple images, edit, variations
resp, _ := client.Generate(ctx, &provider.GenerateRequest{
    Model:  omniimage.ModelDALLE2,
    Prompt: "A cute robot",
    N:      4,
    Size:   provider.Size512x512,
})
Fal AI (FLUX, Stable Diffusion)
client, _ := omniimage.NewClient(omniimage.ClientConfig{
    Providers: []omniimage.ProviderConfig{
        {
            Provider: omniimage.ProviderNameFal,
            APIKey:   "...", // or FAL_KEY env var
        },
    },
})

// FLUX Pro - high quality
resp, _ := client.Generate(ctx, &provider.GenerateRequest{
    Model:  omniimage.ModelFluxPro,
    Prompt: "A photorealistic portrait",
    Size:   provider.Size1024x1024,
})

// FLUX Schnell - fast generation
resp, _ := client.Generate(ctx, &provider.GenerateRequest{
    Model:  omniimage.ModelFluxSchnell,
    Prompt: "Abstract art",
    N:      4,
})

// Upscale an image
upscaled, _ := client.Upscale(ctx, &provider.UpscaleRequest{
    Model: omniimage.ModelClarityUpscaler,
    Image: "https://example.com/image.png",
    Scale: 2,
})

API Reference

GenerateRequest
Field Type Description
Model string Model ID (required)
Prompt string Text description (required)
NegativePrompt string What to avoid (Fal only)
N int Number of images
Size ImageSize Image dimensions
Quality ImageQuality "standard" or "hd"
Style ImageStyle "vivid" or "natural"
Seed *int64 For reproducibility
Steps *int Inference steps (Fal)
GuidanceScale *float64 Prompt adherence (Fal)
Image Sizes
  • Size256x256, Size512x512, Size1024x1024
  • Size1024x1792 (portrait), Size1792x1024 (landscape)
  • Size768x1024, Size1024x768
Models

OpenAI:

  • ModelDALLE3 - DALL-E 3 (highest quality, n=1 only)
  • ModelDALLE2 - DALL-E 2 (edit, variations support)

Fal AI:

  • ModelFluxPro - FLUX Pro (high quality)
  • ModelFluxDev - FLUX Dev (balanced)
  • ModelFluxSchnell - FLUX Schnell (fast)
  • ModelSDXL - Stable Diffusion XL
  • ModelClarityUpscaler - Image upscaling

Environment Variables

Variable Provider Description
OPENAI_API_KEY OpenAI API key for DALL-E
FAL_KEY Fal AI API key for Fal

License

MIT

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

View Source
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

View Source
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.

func (*APIError) Error

func (e *APIError) Error() string

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) Close

func (c *Client) Close() error

Close closes the client and releases resources.

func (*Client) Edit

Edit modifies an existing image based on a prompt. Returns ErrNotSupported if the provider doesn't support editing.

func (*Client) Generate

Generate creates images from a text prompt.

func (*Client) Provider

func (c *Client) Provider() provider.Provider

Provider returns the underlying provider.

func (*Client) SupportsEdit

func (c *Client) SupportsEdit() bool

SupportsEdit returns true if the provider supports image editing.

func (*Client) SupportsUpscale

func (c *Client) SupportsUpscale() bool

SupportsUpscale returns true if the provider supports upscaling.

func (*Client) SupportsVariations

func (c *Client) SupportsVariations() bool

SupportsVariations returns true if the provider supports variations.

func (*Client) Upscale

Upscale increases the resolution of an image. Returns ErrNotSupported if the provider doesn't support upscaling.

func (*Client) Variations

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

func GetModelInfo(modelID string) *ModelInfo

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
Morty Proxy This is a proxified and sanitized view of the page, visit original site.