imagen

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

Google Imagen Provider

Google Imagen 4.0 provider for image generation using the Gemini API.

Requirements

✅ Works with AI Studio API keys - No Google Cloud billing required!

  • Google AI Studio API key (same as Gemini)
  • Access via generativelanguage.googleapis.com endpoint
  • Model: imagen-4.0-generate-001

Configuration

apiVersion: promptkit.altairalabs.ai/v1alpha1
kind: Provider
metadata:
  name: imagen-provider
spec:
  type: imagen
  model: imagen-4.0-generate-001

Note: Project ID and location are no longer required when using the Gemini API endpoint.

Environment Variables

  • GOOGLE_API_KEY or GEMINI_API_KEY - Required for authentication

Cost

  • $0.04 per image (fixed cost, not token-based)
  • No token counting

API Details

  • Endpoint: https://generativelanguage.googleapis.com/v1beta/models/{model}:predict
  • Authentication: x-goog-api-key header (same as Gemini)
  • Method: POST
  • Request format: {"instances": [{"prompt": "..."}], "parameters": {"sampleCount": 1, ...}}
  • Response format: {"predictions": [{"bytesBase64Encoded": "...", "mimeType": "image/png"}]}

Limitations

  • No streaming support
  • Works with AI Studio API keys (no GCP billing required!)
  • Only supports image generation (no analysis or multimodal understanding)
  • Always generates PNG format - cannot generate JPEG, WebP, or other formats
  • Cannot convert or manipulate existing images
  • Generates one image per request (even if prompt asks for multiple)

Alternative for Testing

For testing image generation scenarios without GCP billing:

  • Use the mock provider with pre-generated images
  • Or implement an OpenAI DALL-E provider (requires OpenAI API key)

Documentation

Overview

Package imagen provides Google Imagen image generation provider integration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ID               string
	Model            string
	BaseURL          string
	ApiKey           string
	ProjectID        string
	Location         string
	IncludeRawOutput bool
	Defaults         providers.ProviderDefaults
}

ImagenConfig holds configuration for creating an Imagen provider

type Provider

type Provider struct {
	providers.BaseProvider

	BaseURL    string
	ApiKey     string
	ProjectID  string
	Location   string
	Defaults   providers.ProviderDefaults
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Provider implements the Provider interface for Google's Imagen image generation

func NewProvider

func NewProvider(config Config) *Provider

NewProvider creates a new Imagen provider

func (*Provider) CalculateCost

func (p *Provider) CalculateCost(inputTokens, outputTokens, cachedTokens int) types.CostInfo

CalculateCost calculates cost breakdown (simplified for Imagen)

func (*Provider) Close

func (p *Provider) Close() error

Close cleans up resources

func (*Provider) Generate

func (p *Provider) Generate(ctx context.Context, req base.ImageRequest) (base.ImageResponse, error)

Generate satisfies base.ImageProvider. It delegates to Predict by translating the ImageRequest into the legacy PredictionRequest shape internally, then extracts the image bytes back into an ImageResponse.

This is a thin shim — call sites that already use Predict continue to work. Future PRs can migrate call sites to Generate directly.

func (*Provider) Model

func (p *Provider) Model() string

Model returns the model name/identifier used by this provider.

func (*Provider) Predict

Predict generates images based on the last user message

func (*Provider) PredictStream

func (p *Provider) PredictStream(
	ctx context.Context,
	req providers.PredictionRequest,
) (<-chan providers.StreamChunk, error)

PredictStream is not supported for image generation

func (*Provider) Pricing

func (p *Provider) Pricing() *base.PricingDescriptor

Pricing returns Imagen's per-image pricing descriptor.

func (*Provider) SupportsStreaming

func (p *Provider) SupportsStreaming() bool

SupportsStreaming returns false for Imagen

func (*Provider) Type

func (p *Provider) Type() base.ProviderType

Type returns base.ProviderTypeImage. Imagen is an image generation provider, not an inference provider — overriding the default from the embedded providers.BaseProvider helper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL