CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-dev-langchain4j--langchain4j-vertex-ai

LangChain4j integration for Google Vertex AI models including chat, language, embedding, image, and scoring capabilities

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

api.mddocs/models/image/

Image Model API Reference

Class Definition

public class VertexAiImageModel implements ImageModel {
    public Response<Image> generate(String prompt);
    public Response<List<Image>> generate(String prompt, int n);
    public Response<Image> edit(Image image, String prompt);
    public Response<Image> edit(Image image, Image mask, String prompt);
    public static Builder builder();
}

Methods

/**
 * Generate a single image from a text prompt.
 *
 * @param prompt The text description of the desired image
 * @return Response containing the generated image
 */
public Response<Image> generate(String prompt);

/**
 * Generate multiple image variations from a text prompt.
 *
 * @param prompt The text description of the desired images
 * @param n The number of image variations to generate
 * @return Response containing list of generated images
 */
public Response<List<Image>> generate(String prompt, int n);

/**
 * Edit an image using a text prompt.
 *
 * @param image The source image to edit
 * @param prompt The text description of desired changes
 * @return Response containing the edited image
 */
public Response<Image> edit(Image image, String prompt);

/**
 * Edit an image using a mask and text prompt.
 *
 * @param image The source image to edit
 * @param mask The mask image indicating areas to modify (white = edit, black = preserve)
 * @param prompt The text description of desired changes for masked areas
 * @return Response containing the edited image
 */
public Response<Image> edit(Image image, Image mask, String prompt);

/**
 * Create a new builder for configuring a VertexAiImageModel.
 *
 * @return A new Builder instance
 */
public static Builder builder();

Builder Methods

Required

public Builder endpoint(String endpoint);
public Builder project(String project);
public Builder location(String location);
public Builder publisher(String publisher);
public Builder modelName(String modelName);

Optional

public Builder seed(Long seed);                              // Random seed (0-4,294,967,295)
public Builder language(String language);                    // Language code
public Builder guidanceScale(Integer guidanceScale);         // Edit strength (0-21+)
public Builder negativePrompt(String negativePrompt);        // What to avoid
public Builder sampleImageStyle(ImageStyle sampleImageStyle); // Style (Imagen v1 only)
public Builder sampleImageSize(Integer sampleImageSize);     // Output size in pixels
public Builder aspectRatio(AspectRatio aspectRatio);         // Image aspect ratio
public Builder mimeType(MimeType mimeType);                  // PNG or JPEG
public Builder compressionQuality(Integer compressionQuality); // JPEG quality (1-100)
public Builder personGeneration(PersonGeneration personGeneration); // Person policy
public Builder watermark(Boolean watermark);                 // Add watermark
public Builder maxRetries(Integer maxRetries);               // Retry attempts (default: 3)
public Builder persistToCloudStorage(String gcsUri);         // Save to GCS
public Builder withPersisting();                             // Enable local persistence
public Builder persistTo(Path persistTo);                    // Local save path
public Builder logRequests(Boolean logRequests);             // Log requests
public Builder logResponses(Boolean logResponses);           // Log responses
public VertexAiImageModel build();

Constructor

/**
 * Create a VertexAiImageModel with explicit parameters.
 */
public VertexAiImageModel(
    String endpoint,
    String project,
    String location,
    String publisher,
    String modelName,
    Long seed,
    String language,
    Integer guidanceScale,
    String negativePrompt,
    ImageStyle sampleImageStyle,
    Integer sampleImageSize,
    AspectRatio aspectRatio,
    PersonGeneration personGeneration,
    Integer maxRetries,
    MimeType mimeType,
    Integer compressionQuality,
    Boolean addWatermark,
    String cloudStorageBucket,
    Boolean withPersisting,
    Path persistTo,
    Boolean logRequests,
    Boolean logResponses
);

Enums

AspectRatio

public enum AspectRatio {
    SQUARE,         // 1:1 - toString() returns "1:1"
    PORTRAIT,       // 9:16 - toString() returns "9:16"
    LANDSCAPE,      // 16:9 - toString() returns "16:9"
    THREE_FOURTHS,  // 3:4 - toString() returns "3:4"
    FOUR_THIRDS;    // 4:3 - toString() returns "4:3"

    public String toString();
}

ImageStyle (Imagen v1 only)

public enum ImageStyle {
    PHOTOGRAPH,     // Photographic - toString() returns "photograph"
    DIGITAL_ART,    // Digital art - toString() returns "digital_art"
    LANDSCAPE,      // Landscape - toString() returns "landscape"
    SKETCH,         // Sketch - toString() returns "sketch"
    WATERCOLOR,     // Watercolor - toString() returns "watercolor"
    CYBERPUNK,      // Cyberpunk - toString() returns "cyberpunk"
    POP_ART;        // Pop art - toString() returns "pop_art"

    public String toString();
}

MimeType

public enum MimeType {
    PNG,   // PNG format - toString() returns "image/png"
    JPEG;  // JPEG format - toString() returns "image/jpeg"

    public String toString();
}

PersonGeneration

public enum PersonGeneration {
    DONT_ALLOW,    // Don't generate people - toString() returns "dont_allow"
    ALLOW_ADULT,   // Allow adult only - toString() returns "allow_adult"
    ALLOW_ALL;     // Allow all - toString() returns "allow_all"

    public String toString();
}

Parameter Details

seed

  • Type: Long
  • Range: 0 to 4,294,967,295
  • Purpose: Reproducible generation (same seed + prompt = same image)

language

  • Type: String
  • Examples: "en", "es", "fr", "de", "ja"
  • Purpose: Language code for prompt interpretation

guidanceScale

  • Type: Integer
  • Range: 0 to 30+
  • Usage:
    • 0-9: Low guidance (subtle changes)
    • 10-20: Medium guidance (moderate changes)
    • 21+: High guidance (strong changes)

negativePrompt

  • Type: String
  • Purpose: Describe what to avoid in generation
  • Examples: "blurry, distorted, low quality"

sampleImageStyle

  • Type: ImageStyle enum
  • Supported: Imagen v1 models only (imagegeneration@002)
  • Values: See ImageStyle enum above

sampleImageSize

  • Type: Integer
  • Purpose: Output image size in pixels

aspectRatio

  • Type: AspectRatio enum
  • Default: Varies by model
  • Values: See AspectRatio enum above

mimeType

  • Type: MimeType enum
  • Default: PNG
  • Values: PNG (lossless), JPEG (lossy)

compressionQuality

  • Type: Integer
  • Range: 1-100
  • Purpose: JPEG compression quality (only for JPEG)
  • Higher: Better quality, larger file

personGeneration

  • Type: PersonGeneration enum
  • Default: Varies by model
  • Purpose: Policy for generating people in images

watermark

  • Type: Boolean
  • Default: Varies by model version
  • Purpose: Add AI-generated watermark

maxRetries

  • Type: Integer
  • Default: 3
  • Purpose: Retry attempts on API failures

persistToCloudStorage

  • Type: String
  • Format: Google Cloud Storage URI (gs://bucket/path/)
  • Purpose: Automatically save images to GCS

withPersisting

  • Purpose: Enable local file persistence
  • Use with: persistTo(Path)

persistTo

  • Type: Path
  • Purpose: Local directory for saving images

logRequests

  • Type: Boolean
  • Default: false
  • Purpose: Log API requests for debugging

logResponses

  • Type: Boolean
  • Default: false
  • Purpose: Log API responses for debugging

Response Types

Response<Image>

public class Response<T> {
    public T content();
    public TokenUsage tokenUsage();
    public FinishReason finishReason();
}

Image

public class Image {
    public byte[] bytes();
    public String base64Data();
    public URI uri();
}

Creating Image Objects

// From bytes
public static Image fromBytes(byte[] bytes);

// From file
Image image = Image.fromBytes(Files.readAllBytes(Path.of("image.png")));

// From URL
Image image = Image.fromUrl(new URL("https://..."));

Error Handling

  • Automatically retries transient failures up to maxRetries times
  • Common errors:
    • Invalid aspect ratio for model version
    • Negative prompt not supported by model
    • Invalid image format for editing
    • Quota exceeded

Thread Safety

Thread-safe, can be reused across threads. Builder is not thread-safe.

Best Practices

Prompt Writing

  • Be descriptive and specific
  • Include style, lighting, composition details
  • Use negative prompts to avoid unwanted elements

Reproducibility

  • Use fixed seed for reproducible results
  • Same seed + prompt = same output

Quality vs Performance

  • PNG: Lossless, larger files
  • JPEG: Lossy, smaller files, adjustable quality

Person Generation

  • DONT_ALLOW: Safest, no people
  • ALLOW_ADULT: Adults only
  • ALLOW_ALL: All ages (use with caution)

Storage

  • Local: withPersisting() + persistTo(Path)
  • Cloud: persistToCloudStorage("gs://bucket/")

Install with Tessl CLI

npx tessl i tessl/maven-dev-langchain4j--langchain4j-vertex-ai@1.11.0

docs

index.md

quick-reference.md

tile.json