Documentation
¶
Overview ¶
Package imageproviders contains concrete implementations of image.Generation for each supported provider. Add a new file here (e.g. stabilityai.go) to support additional image generation backends — no other package needs changing.
Index ¶
Constants ¶
const ( APIOpenAI = "openai" // POST {base}/images/generations (DALL-E, GPT Image and compatible servers) APIGemini = "gemini" // Gemini API: generateContent for Gemini image models, predict for Imagen APIOpenRouter = "openrouter" // POST {base}/images, the OpenRouter image API )
Wire protocols an image provider can speak.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GeminiClient ¶
type GeminiClient struct {
// contains filtered or unexported fields
}
GeminiClient generates images with the Gemini API: the Gemini image models (gemini-nano-banana-2.1, gemini-3.1-flash-image, ...) through generateContent, and an imagen-* model through the Imagen predict call.
func NewGemini ¶
func NewGemini(apiKey string, opts ...GeminiOption) *GeminiClient
NewGemini creates a Google Imagen image generation client. apiKey is a Google AI Studio API key (AIza...).
func (*GeminiClient) GenerateImage ¶
func (c *GeminiClient) GenerateImage(ctx context.Context, prompt string) (*image.GenerationResponse, error)
GenerateImage generates an image: generateContent for a Gemini image model, the Imagen predict call for an imagen-* model.
func (*GeminiClient) Provider ¶
func (c *GeminiClient) Provider() string
Provider implements image.Generation.
type GeminiOption ¶
type GeminiOption func(*GeminiClient)
GeminiOption configures a GeminiClient.
func WithGeminiAspectRatio ¶
func WithGeminiAspectRatio(ar string) GeminiOption
WithGeminiAspectRatio sets the aspect ratio ("1:1", "3:4", "4:3", "9:16", "16:9").
func WithGeminiBaseURL ¶
func WithGeminiBaseURL(url string) GeminiOption
WithGeminiBaseURL overrides the default Google AI Studio endpoint.
func WithGeminiCount ¶
func WithGeminiCount(n int) GeminiOption
WithGeminiCount sets the number of images to generate (1–4).
func WithGeminiHTTPClient ¶
func WithGeminiHTTPClient(hc *http.Client) GeminiOption
WithGeminiHTTPClient injects a custom HTTP client.
func WithGeminiModel ¶
func WithGeminiModel(model string) GeminiOption
WithGeminiModel sets the Imagen model.
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
OpenAIClient generates images through an OpenAI-compatible /images/generations endpoint: the GPT Image models (gpt-image-2.5-flare, gpt-image-2.5-sunburst, ...) and the older DALL-E ones. The two families take different parameters, see isGPTImage.
func NewOpenAI ¶
func NewOpenAI(apiKey string, opts ...OpenAIOption) *OpenAIClient
NewOpenAI creates an OpenAI DALL-E image generation client.
func (*OpenAIClient) GenerateImage ¶
func (c *OpenAIClient) GenerateImage(ctx context.Context, prompt string) (*image.GenerationResponse, error)
GenerateImage calls the OpenAI Images API and returns the result.
func (*OpenAIClient) Provider ¶
func (c *OpenAIClient) Provider() string
Provider implements image.Generation.
type OpenAIOption ¶
type OpenAIOption func(*OpenAIClient)
OpenAIOption configures an OpenAIClient.
func WithOpenAIBaseURL ¶
func WithOpenAIBaseURL(url string) OpenAIOption
WithOpenAIBaseURL overrides the default endpoint (useful for proxies).
func WithOpenAIHTTPClient ¶
func WithOpenAIHTTPClient(hc *http.Client) OpenAIOption
WithOpenAIHTTPClient injects a custom HTTP client.
func WithOpenAIModel ¶
func WithOpenAIModel(model string) OpenAIOption
WithOpenAIModel sets the model (e.g. "gpt-image-2.5-flare", or "dall-e-3").
func WithOpenAIProviderName ¶ added in v1.8.0
func WithOpenAIProviderName(name string) OpenAIOption
WithOpenAIProviderName sets the name Provider() reports (default "openai").
func WithOpenAIQuality ¶
func WithOpenAIQuality(q string) OpenAIOption
WithOpenAIQuality sets the quality. GPT Image models take low, medium, high (the 2.5 ones also xhigh and max) or auto, the default; dall-e-3 takes standard (its default) or hd.
func WithOpenAISize ¶
func WithOpenAISize(size string) OpenAIOption
WithOpenAISize sets the image dimensions (e.g. "1024x1024", "1792x1024").
type OpenRouterClient ¶ added in v1.8.0
type OpenRouterClient struct {
// contains filtered or unexported fields
}
OpenRouterClient generates images through the OpenRouter image API (POST /images), which fronts Google, OpenAI, Black Forest Labs, ByteDance, Recraft and others behind one key. The response carries base64 bytes.
func NewOpenRouter ¶ added in v1.8.0
func NewOpenRouter(apiKey string, opts ...OpenRouterOption) *OpenRouterClient
NewOpenRouter creates an OpenRouter image generation client.
func (*OpenRouterClient) GenerateImage ¶ added in v1.8.0
func (c *OpenRouterClient) GenerateImage(ctx context.Context, prompt string) (*image.GenerationResponse, error)
GenerateImage calls the OpenRouter image API.
func (*OpenRouterClient) Provider ¶ added in v1.8.0
func (c *OpenRouterClient) Provider() string
Provider implements image.Generation.
type OpenRouterOption ¶ added in v1.8.0
type OpenRouterOption func(*OpenRouterClient)
OpenRouterOption configures an OpenRouterClient.
func WithOpenRouterAspectRatio ¶ added in v1.8.0
func WithOpenRouterAspectRatio(ratio string) OpenRouterOption
WithOpenRouterAspectRatio sets the aspect ratio ("1:1", "16:9", ...).
func WithOpenRouterBaseURL ¶ added in v1.8.0
func WithOpenRouterBaseURL(url string) OpenRouterOption
WithOpenRouterBaseURL overrides the API root.
func WithOpenRouterHTTPClient ¶ added in v1.8.0
func WithOpenRouterHTTPClient(hc *http.Client) OpenRouterOption
WithOpenRouterHTTPClient injects a custom HTTP client.
func WithOpenRouterModel ¶ added in v1.8.0
func WithOpenRouterModel(model string) OpenRouterOption
WithOpenRouterModel sets the model (for example "black-forest-labs/flux-3-image").
type Profile ¶ added in v1.8.0
type Profile struct {
ID string
DisplayName string
API string
BaseURL string
EnvVars []string // environment variables that can carry the API key
// Models lists the models of the provider; the first is the default.
Models []string
}
Profile describes an image provider: protocol, endpoint, key variable and models. It is the image counterpart of the chat catalog in internal/providers: the SDK looks a provider up here instead of accepting only "openai" and "gemini", and a provider that is not listed works when it speaks the OpenAI image API and the host gives its base URL.
func ProfileFor ¶ added in v1.8.0
ProfileFor returns the profile of a provider ID, case-insensitively.
func Profiles ¶ added in v1.8.0
func Profiles() []Profile
Profiles returns the image providers this build knows.
func (Profile) DefaultModel ¶ added in v1.8.0
DefaultModel returns the model used when the host does not name one.