imagen

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 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

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 added in v1.1.3

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 added in v1.1.3

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

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

func NewProvider added in v1.1.3

func NewProvider(config Config) *Provider

NewProvider creates a new Imagen provider

func (*Provider) CalculateCost added in v1.1.3

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

CalculateCost calculates cost breakdown (simplified for Imagen)

func (*Provider) Close added in v1.1.3

func (p *Provider) Close() error

Close cleans up resources

func (*Provider) Predict added in v1.1.3

Predict generates images based on the last user message

func (*Provider) PredictStream added in v1.1.3

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

PredictStream is not supported for image generation

func (*Provider) SupportsStreaming added in v1.1.3

func (p *Provider) 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