Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

VertexAIImageGenerator

Generate images using Google Vertex AI generative model.

Key Features​

  • Generates images from text prompts using Google Vertex AI
  • Supports negative prompts to exclude unwanted elements from generated images
  • Returns images as ByteStream objects
  • Authenticates using Google Cloud Application Default Credentials (ADCs)

Configuration​

  1. Drag the VertexAIImageGenerator component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Enter your GCP project ID. Create a secret with the key GCP_PROJECT_ID. For detailed instructions, see Create Secrets.
    2. Optionally, enter the location. If not set, uses us-central1.
    3. The default model is imagegeneration.
  4. Go to the Advanced tab to configure additional model keyword arguments.

Connections​

VertexAIImageGenerator accepts a text prompt (str) and an optional negative_prompt (Optional[str]) as inputs. It outputs generated images as a list of ByteStream objects through its images output.

Connect PromptBuilder's prompt output to this component's prompt input.

Source Code​

To check this component's source code, open image_generator.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

VertexAIImageGenerator:
type: haystack_integrations.components.generators.google_vertex.image_generator.VertexAIImageGenerator
init_parameters:
model: imagegeneration

This pipeline uses VertexAIImageGenerator to generate images from text prompts:

# haystack-pipeline
components:
VertexAIImageGenerator:
type: haystack_integrations.components.generators.google_vertex.image_generator.VertexAIImageGenerator
init_parameters:
project_id:
model: imagegeneration
location:
PromptBuilder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: "Generate an image described in the query.\n\nQuery: {{ query }}"
required_variables: "\\n"
variables:

max_runs_per_component: 100

metadata: {}

connections:
- sender: PromptBuilder.prompt
receiver: VertexAIImageGenerator.prompt

inputs:
query:
- PromptBuilder.query

Parameters​

Inputs​

ParameterTypeDefaultDescription
promptstrThe prompt to generate images from.
negative_promptOptional[str]NoneA description of what you want to omit in the generated images.

Outputs​

ParameterTypeDescription
imagesList[ByteStream]A list of ByteStream objects, each containing an image.

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
project_idOptional[str]NoneID of the GCP project to use. By default, it is set during Google Cloud authentication.
modelstrimagegenerationName of the model to use.
locationOptional[str]NoneThe default location to use when making API calls. If not set, uses us-central-1.
kwargsAnyAdditional keyword arguments to pass to the model. See the ImageGenerationModel.generate_images() documentation.

Run Method Parameters​

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
promptstrThe prompt to generate images from.
negative_promptOptional[str]NoneA description of what you want to omit in the generated images.