Generate images

The Image API is part of the Product Studio sub-API. It leverages the generative AI tools of Google Product Studio (GPS) API to generate and optimize product images. You can use it to improve customer engagement and conversion.

What can you generate using the API?

  • Product images with AI-generated backgrounds based on provided product information and a text prompt
  • Product images with the background of the original image removed
  • Product images where the resolution of the original image is enhanced

Generate an image background

The GenerateProductImageBackground method can create product images with AI-generated backgrounds using your original product image and a text prompt detailing the background.

The API accepts:

  • Product image: It can be either of the following:
    • A URI pointing to the product image (such as, {"image_uri": "https://my-store.com/img/1.png"})
    • Raw image bytes, such as, {"image_bytes": b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01'}
  • Prompt: A string that specifies the background to generate:
    • product_description: Description of the product.
    • background_description: Description of the wanted background.

Remove an image background

The RemoveProductImageBackground method can generate images with the background removed from your original product image.

The API accepts:

  • Product image: It can be either of the following:
    • A URI pointing to the product image, such as, {"image_uri": "https://my-store.com/img/1.png"}
    • Raw image bytes, such as, {"image_bytes": b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01'}
  • Background color: The color of the background after removal, given in RGB format. If no color is specified, the background will be a RGBA 4-channel transparent image.

Upscale an image

The UpscaleProductImage method can generate images where the resolution of your original product image is enhanced.

The API accepts a Product Image. It can be either of the following:

  • A URI pointing to the product image, such as, {"image_uri": "https://my-store.com/img/1.png"}
  • Raw image bytes, such as, {"image_bytes": "image_bytes"}

Use client libraries

We recommend that you use client libraries to submit your requests. If a supported client library isn't available for your language, we can provide the library files directly for you (in email or a shared drive folder) to install, for example, within your Maven project.

Examples

The following examples use the API to generate or optimize product images.

Generate a background for a product image

The example shows how to generate a product image with your chosen background.

Request

The request body contains the image (URI or bytes) and the prompt for background generation. Here's an example of the request structure using an image URI:

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground

{
   "input_image": {
      "image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
   },
   "config": {
      "product_description": "a jar"
      "background_description": "sitting on a cracked stone surface surrounded by a cherry blossom tree and pink and white flowers in the background, high resolution, product photography, strong shadows and lights, creative"
   }
}

Alternatively, you can use raw image bytes:

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground

{
   "input_image": {
      "image_bytes": "b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff'"
   },
   "config": {
      "product_description": "a jar"
      "background_description": "sitting on a cracked stone surface surrounded by a cherry blossom tree and pink and white flowers in the background, high resolution, product photography, strong shadows and lights, creative"
   }
}

Response

You can expect a response like:

{
  "generated_image": {
    "image_bytes": "b'\x7d\x1b\x8f\x04\x5c\x9e\x23\xf0\x6a\xd1\x4b\x87\x0c\x3e\xa9\x21\xb5'"
    "generation_time": "2025-05-13T00:06:54.754828Z"
  },
}

Or, if return_image_uri is set to true in output_config,it will look like this:

{
  "generated_image": {
    "uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEvIFfK0YaLKvwvIBc9ItJtJGFE6hi25o6-N3Fz6YTw57pFghfIVlCGve7eyJcQkhoAqGAf8NDzW70qjwGOCuHhiouqF2nqxBwCcfDxZPkYRl3h7CIjyev9asJw7x-0g0V_xvurfowZJ0moXu98kmV01A3Thv2ZRlTAiOPYuEb8wnY7EeyD9l48lDdwJgZ4jqxtTgrRbwvpno4NICj9q830RzATiBHuJ_WUFQJiHOMAqbGyrQIWQTQ",
    "generation_time": "2025-05-13T00:06:54.754828Z"
  }
}

Remove a background from a product image

The example shows how to remove the background from a product image.

Request

The request body contains the image (URI or bytes) and, optionally, the color to replace the background with.

Notes:

  • Specify the color values in RGB format in the range [0-255].
  • If you don't specify a background color, it will be an RGBA 4-channel transparent image.

Here's an example of the request structure using an image URI and setting the background to green (0, 255, 0):

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:removeProductImageBackground

{
   "input_image": {
      "image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
   },
   "config": {
      "background_color": {
      "red": 0
      "green": 255
      "blue": 0
    }
   }
}

Alternatively, you can perform the same function using raw image bytes:

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:removeProductImageBackground

{
   "input_image": {
      "image_bytes": "b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff'"
   },
   "config": {
      "background_color": {
      "red": 0
      "green": 255
      "blue": 0
    }
   }
}
Response

You can expect a response like:

{
  "generated_image": {
    "image_bytes": "b'\x7d\x1b\x8f\x04\x5c\x9e\x23\xf0\x6a\xd1\x4b\x87\x0c\x3e\xa9\x21\xb5'"
    "generation_time": "2025-05-13T00:06:54.754828Z"
  },
}

Or, if return_image_uri is set to true in output_config, it will look like this:

{
  "generated_image": {
    "uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEsYi83dcMKVV44i3vHDHzz_PJLuPyJHh9iX7IrsZ0ZIIRIS6SB4ovBmr0L9lZ1VNacZ5duwhcJ8Q8mXMYaIEArf2ieC2OuKEhRzVb-UxlkAUpitEpS5-M3Y3Ch3TGhQTZmBJXlsHLTuf0XcPwNHoNxJlgF0v_mQ6DIlPugZKC_WiYN2DNUkJivfr4WvifhMn5NaMKpDwpH4Acj-bdGNQ77M-8sj4SyEu3sHCF8ZtnMvF5DbGIYOJQ"
  }
}

Upscale a product image

The example shows how to enhance the resolution of your product image.

Request

The request body contains the image (URI or bytes). Here's an example of the request structure using an image URI:

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:upscaleProductImage

{
   "input_image": {
      "image_uri": "https://services.google.com/fh/files/misc/ring_image_400_600.jpg"
   }
}

Alternatively, you may choose to use the raw image bytes instead:

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:upscaleProductImage

{
   "input_image": {
      "image_bytes": "b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff'"
   }
}
Response

You can expect a response like

{
  "generated_image": {
    "image_bytes": "b'\x7d\x1b\x8f\x04\x5c\x9e\x23\xf0\x6a\xd1\x4b\x87\x0c\x3e\xa9\x21\xb5'"
    "generation_time": "2025-05-13T00:06:54.754828Z"
  },
}

Or, if return_image_uri is set to true in output_config,it will look like this:

{
  "generated_image": {
    "uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEvIFfK0YaLKvwvIBc9ItJtJGFE6hi25o6-N3Fz6YTw57pFghfIVlCGve7eyJcQkhoAqGAf8NDzW70qjwGOCuHhiouqF2nqxBwCcfDxZPkYRl3h7CIjyev9asJw7x-0g0V_xvurfowZJ0moXu98kmV01A3Thv2ZRlTAiOPYuEb8wnY7EeyD9l48lDdwJgZ4jqxtTgrRbwvpno4NICj9q830RzATiBHuJ_WUFQJiHOMAqbGyrQIWQTQ"
  }
}

Common errors and issues

Here are a few common issues and their solutions.

"Input image is required"

If you receive the following error message, add input_image in the request body:

Error message:
"error": {
    "code": 400,
    "message": "[input_image] Input image is required to generate product image background.",
    "status": "INVALID_ARGUMENT",
 ...
}

"At least one field of image is required"

If you receive the following error message, populate correctly only one of image_uri or image_bytes in the request body.

Error message:
"error": {
    "code": 400,
    "message": "[input_image.image] At least one field of image is required to generate product image background.",
    "status": "INVALID_ARGUMENT",
 ...
}

For example, posting this will result in an error.

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground

{
   "config": {
      "product_description": "a jar"
      "background_description": "sitting on a cracked stone surface surrounded by a cherry blossom tree and pink and white flowers in the background, high resolution, product photography, strong shadows and lights, creative"
   }
}

"Config is required to generate product image background"

If you get this error, add config in the request body and populate both the product_description and background_description:

Error message:
"error": {
    "code": 400,
    "message": "[config] Config is required to generate product image background.",
    "status": "INVALID_ARGUMENT",
 ...
}

For example, posting this results in an error.

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground

{
   "input_image": {
      "image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
   }
}

"Product description is required to generate product image background"

Should you receive either of the following two error messages, make sure to populate both the product_description and background_description in config:

This is an example of a missing product description:

Error message:
"error": {
    "code": 400,
    "message": "[config.product_description] Product description is required to generate product image background.",
    "status": "INVALID_ARGUMENT",
 ...
}

This is an example of a missing background description:

Error message:
"error": {
    "code": 400,
    "message": "[config.background_description] Background description is required to generate product image background.",
    "status": "INVALID_ARGUMENT",
 ...
}

For example, running the following request will result in an error.

POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground

{
   "input_image": {
      "image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
   },
   "config": {
   }
}