or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

built-in-tools.mdimage-generation.mdindex.mdlanguage-models.mdprovider-setup.mdtext-embeddings.md
tile.json

image-generation.mddocs/

Image Generation

Image generation capabilities using Google's Imagen models for creating high-quality images from text prompts with configurable settings and output options.

Capabilities

Image Model Access

Get image generation model instances for creating images from text descriptions.

/**
 * Get an image generation model instance
 * @param modelId - Google image model identifier
 * @param settings - Optional image generation settings
 * @returns ImageModelV2 instance
 */
image(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV2<
  GoogleGenerativeAIImageProviderOptions
>;

/**
 * Get an image generation model instance (alias for image)
 * @param modelId - Google image model identifier  
 * @param settings - Optional image generation settings
 * @returns ImageModelV2 instance
 */
imageModel(modelId: GoogleGenerativeAIImageModelId, settings?: GoogleGenerativeAIImageSettings): ImageModelV2<
  GoogleGenerativeAIImageProviderOptions
>;

Usage Examples:

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";

// Basic image generation
const result = await generateImage({
  model: google.image("imagen-3.0-generate-002"),
  prompt: "A beautiful sunset over mountains with a lake in the foreground",
});

console.log("Generated image URL:", result.image.url);

// Using imageModel method (alias for image)
const imageModel = google.imageModel("imagen-3.0-generate-002");
const result2 = await generateImage({
  model: imageModel,
  prompt: "A futuristic city with flying cars",
});

// Multiple images generation
const result = await generateImage({
  model: google.image("imagen-3.0-generate-002"),
  prompt: "A cute robot playing with a ball",
  n: 3, // Generate 3 images
});

result.images.forEach((image, index) => {
  console.log(`Image ${index + 1}:`, image.url);
});

Image Model IDs

Supported Google image generation model identifiers.

type GoogleGenerativeAIImageModelId =
  | "imagen-3.0-generate-002"
  | (string & {});

Model Information:

  • imagen-3.0-generate-002: Google's latest Imagen model with high-quality image generation capabilities

Image Provider Options

Configuration options for image generation behavior and output settings.

interface GoogleGenerativeAIImageProviderOptions {
  /** Custom settings for the image model */
  maxImagesPerCall?: number;
}

interface GoogleGenerativeAIImageSettings {
  /** Override the maximum number of images per call (default: 4) */
  maxImagesPerCall?: number;
}

Usage Examples:

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";

// Custom image generation settings
const imageModel = google.image("imagen-3.0-generate-002");

const result = await generateImage({
  model: imageModel,
  prompt: "A fantasy landscape with magical creatures",
  n: 2,
  providerOptions: {
    maxImagesPerCall: 2, // Override default maximum
  },
});

// Access generated images
for (const image of result.images) {
  console.log("Image URL:", image.url);
  console.log("Alt text:", image.alt);
}

Image Generation Features

Single Image Generation

Generate a single image from a text prompt.

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";

const result = await generateImage({
  model: google.image("imagen-3.0-generate-002"),
  prompt: "A serene Japanese garden with cherry blossoms and a koi pond",
});

// Access the generated image
console.log("Image URL:", result.image.url);
console.log("Alt description:", result.image.alt);

Multiple Image Generation

Generate multiple variations of images from the same prompt.

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";

const result = await generateImage({
  model: google.image("imagen-3.0-generate-002"),
  prompt: "A modern office space with natural lighting",
  n: 4, // Generate 4 variations
});

// Process all generated images
result.images.forEach((image, index) => {
  console.log(`Variation ${index + 1}:`);
  console.log("  URL:", image.url);
  console.log("  Description:", image.alt);
});

console.log(`Generated ${result.images.length} images total`);

Advanced Prompting

Create detailed prompts for specific image characteristics.

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";

// Detailed artistic prompt
const artisticResult = await generateImage({
  model: google.image("imagen-3.0-generate-002"),
  prompt: `A photorealistic portrait of a wise old wizard with a long white beard, 
           wearing deep blue robes with golden embroidery, holding a glowing crystal staff, 
           standing in an ancient library filled with floating books and magical artifacts, 
           dramatic lighting, high detail, fantasy art style`,
});

// Architectural prompt
const architecturalResult = await generateImage({
  model: google.image("imagen-3.0-generate-002"),
  prompt: `Modern minimalist house design with floor-to-ceiling windows, 
           clean geometric lines, surrounded by lush greenery, 
           natural materials like wood and stone, bright daylight, 
           architectural photography style`,
});

// Abstract art prompt
const abstractResult = await generateImage({
  model: google.image("imagen-3.0-generate-002"),
  prompt: `Abstract digital art with flowing organic shapes in vibrant colors, 
           gradients of blue and purple merging into golden highlights, 
           dreamlike and ethereal composition, high resolution`,
});

Configuration Options

Maximum Images Per Call

Control the maximum number of images that can be generated in a single call.

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";

// Custom provider with specific image settings
const customGoogle = createGoogleGenerativeAI({
  apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY,
});

const result = await generateImage({
  model: customGoogle.image("imagen-3.0-generate-002"),
  prompt: "A collection of geometric patterns",
  n: 3,
  providerOptions: {
    maxImagesPerCall: 3, // Ensure we can generate 3 images
  },
});

Error Handling

Handle image generation errors and limitations.

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";

try {
  const result = await generateImage({
    model: google.image("imagen-3.0-generate-002"),
    prompt: "A beautiful landscape painting",
    n: 5, // This might exceed maxImagesPerCall
  });
  
  console.log(`Successfully generated ${result.images.length} images`);
} catch (error) {
  if (error.code === "INVALID_ARGUMENT") {
    console.error("Invalid request parameters:", error.message);
  } else if (error.code === "QUOTA_EXCEEDED") {
    console.error("API quota exceeded:", error.message);
  } else {
    console.error("Image generation failed:", error.message);
  }
}

Best Practices

Prompt Engineering

  • Be Specific: Include details about style, composition, lighting, and atmosphere
  • Use Descriptive Adjectives: Add adjectives that describe quality (photorealistic, detailed, vibrant)
  • Specify Art Styles: Mention specific art styles or photography techniques when desired
  • Include Technical Details: Specify resolution, lighting conditions, or camera angles for realistic images

Performance Optimization

  • Batch Requests: Generate multiple variations in a single call when possible
  • Appropriate Image Count: Use the default maxImagesPerCall (4) unless you need fewer images
  • Prompt Length: Keep prompts descriptive but concise for optimal results

Content Guidelines

  • Follow Google's content policies for image generation
  • Avoid generating images of real people without consent
  • Be mindful of copyrighted characters or brands
  • Consider cultural sensitivity in image descriptions

Example: Complete Image Generation Workflow

import { google } from "@ai-sdk/google";
import { generateImage } from "ai";
import fs from "fs/promises";

async function generateAndSaveImages() {
  try {
    // Generate multiple image variations
    const result = await generateImage({
      model: google.image("imagen-3.0-generate-002"),
      prompt: `A cozy reading nook by a window with warm sunlight, 
               comfortable armchair, stacks of books, steaming coffee cup, 
               indoor plants, soft textures, inviting atmosphere`,
      n: 3,
    });

    // Process and save each image
    for (let i = 0; i < result.images.length; i++) {
      const image = result.images[i];
      console.log(`Processing image ${i + 1}:`);
      console.log(`  URL: ${image.url}`);
      console.log(`  Description: ${image.alt}`);
      
      // Optional: Download and save the image
      // const response = await fetch(image.url);
      // const buffer = await response.arrayBuffer();
      // await fs.writeFile(`reading-nook-${i + 1}.png`, Buffer.from(buffer));
    }

    return result;
  } catch (error) {
    console.error("Failed to generate images:", error);
    throw error;
  }
}