imagen

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImagenConfig

type ImagenConfig 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 ImagenProvider

type ImagenProvider struct {
	providers.BaseProvider
	Model      string
	BaseURL    string
	ApiKey     string
	ProjectID  string
	Location   string
	Defaults   providers.ProviderDefaults
	HTTPClient *http.Client
}

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

func NewImagenProvider

func NewImagenProvider(config ImagenConfig) *ImagenProvider

NewImagenProvider creates a new Imagen provider

func (*ImagenProvider) CalculateCost

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

CalculateCost calculates cost breakdown (simplified for Imagen)

func (*ImagenProvider) Close

func (p *ImagenProvider) Close() error

Close cleans up resources

func (*ImagenProvider) Predict

Predict generates images based on the last user message

func (*ImagenProvider) PredictStream

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

PredictStream is not supported for image generation

func (*ImagenProvider) SupportsStreaming

func (p *ImagenProvider) SupportsStreaming() bool

SupportsStreaming returns false for Imagen

Jump to

Keyboard shortcuts

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