Image API 是 Product Studio 子 API 的一部分。它利用 Google Product Studio (GPS) API 的生成式 AI 工具来生成和优化商品图片。您可以使用它来提高客户互动度和转化率。
您可以使用该 API 生成哪些内容?
- 根据提供的产品信息和文字提示,使用 AI 生成背景的商品图片
- 移除了原始图片背景的产品图片
- 原始图片分辨率得到增强的商品图片
生成图片背景
GenerateProductImageBackground
方法可以使用您的原始商品图片和详细描述背景的文本提示来创建具有 AI 生成背景的商品图片。
该 API 接受:
- 商品图片:可以是以下任一类型:
- 指向商品图片的 URI(例如
{"image_uri": "https://my-store.com/img/1.png"}
) - 原始图片字节,例如
{"image_bytes": b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01'}
- 指向商品图片的 URI(例如
- 提示:用于指定要生成的背景的字符串:
product_description
:商品的说明。background_description
:所需背景的说明。
移除图片背景
RemoveProductImageBackground
方法可以生成从原始商品图片中移除背景的图片。
该 API 接受:
- 商品图片:可以是以下任一类型:
- 指向商品图片的 URI,例如
{"image_uri": "https://my-store.com/img/1.png"}
- 原始图片字节,例如
{"image_bytes": b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01'}
- 指向商品图片的 URI,例如
- 背景颜色:移除后的背景颜色,以 RGB 格式提供。如果未指定颜色,背景将为 RGBA 4 通道透明图片。
放大图片
UpscaleProductImage
方法可以生成分辨率高于原始商品图片的图片。
该 API 接受商品图片。可以是以下任一值:
- 指向商品图片的 URI,例如
{"image_uri": "https://my-store.com/img/1.png"}
- 原始图片字节,例如
{"image_bytes": "image_bytes"}
使用客户端库
我们建议您使用客户端库来提交请求。如果您的语言没有受支持的客户端库,我们可以直接为您提供库文件(通过电子邮件或共享云端硬盘文件夹),以便您在 Maven 项目中安装这些文件。
示例
以下示例展示了如何使用 API 生成或优化商品图片。
为产品图片生成背景
此示例展示了如何生成具有所选背景的商品图片。
请求
请求正文包含图片(URI 或字节)和用于生成背景的提示。以下示例展示了使用图片 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"
}
}
或者,您也可以使用原始图片字节:
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"
}
}
响应
您可能会收到如下所示的回答:
{
"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"
},
}
或者,如果 return_image_uri
在 output_config,
中设置为 true
,则如下所示:
{
"generated_image": {
"uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEvIFfK0YaLKvwvIBc9ItJtJGFE6hi25o6-N3Fz6YTw57pFghfIVlCGve7eyJcQkhoAqGAf8NDzW70qjwGOCuHhiouqF2nqxBwCcfDxZPkYRl3h7CIjyev9asJw7x-0g0V_xvurfowZJ0moXu98kmV01A3Thv2ZRlTAiOPYuEb8wnY7EeyD9l48lDdwJgZ4jqxtTgrRbwvpno4NICj9q830RzATiBHuJ_WUFQJiHOMAqbGyrQIWQTQ",
"generation_time": "2025-05-13T00:06:54.754828Z"
}
}
代码示例
以下代码示例展示了如何生成商品图片背景:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateImageBackgroundConfig;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductImageBackgroundRequest;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductImageBackgroundResponse;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceSettings;
import com.google.shopping.merchant.productstudio.v1alpha.InputImage;
import com.google.shopping.merchant.productstudio.v1alpha.OutputImageConfig;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create product images with generated backgrounds. */
public class GenerateProductImageBackgroundSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void generateProductImageBackground(Config config, String imageUri)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
ImageServiceSettings imageServiceSettings =
ImageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ImageServiceClient imageServiceClient = ImageServiceClient.create(imageServiceSettings)) {
OutputImageConfig outputImageConfig =
// Set this field to false to return the image bytes in the response instead.
OutputImageConfig.newBuilder().setReturnImageUri(true).build();
InputImage inputImage =
InputImage.newBuilder()
// You can also use image bytes here instead of a URI.
.setImageUri(imageUri)
.build();
GenerateImageBackgroundConfig generateImageBackgroundConfig =
GenerateImageBackgroundConfig.newBuilder()
.setProductDescription("a jar")
.setBackgroundDescription(
"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")
.build();
GenerateProductImageBackgroundRequest request =
GenerateProductImageBackgroundRequest.newBuilder()
.setName(name)
.setOutputConfig(outputImageConfig)
.setInputImage(inputImage)
.setConfig(generateImageBackgroundConfig)
.build();
System.out.println("Sending GenerateProductImageBackground request: " + name);
GenerateProductImageBackgroundResponse response =
imageServiceClient.generateProductImageBackground(request);
System.out.println("Generated product image background response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// Replace with your image URI.
String imageUri =
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg";
generateProductImageBackground(config, imageUri);
}
}
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_productstudio_v1alpha import GenerateImageBackgroundConfig
from google.shopping.merchant_productstudio_v1alpha import GenerateProductImageBackgroundRequest
from google.shopping.merchant_productstudio_v1alpha import ImageServiceClient
from google.shopping.merchant_productstudio_v1alpha import InputImage
from google.shopping.merchant_productstudio_v1alpha import OutputImageConfig
# Gets the merchant account ID from the user's configuration.
_ACCOUNT = configuration.Configuration().read_merchant_info()
# The name of the account to which the request is sent.
# Format: accounts/{account}
_NAME = f"accounts/{_ACCOUNT}"
def generate_product_image_background(image_uri: str) -> None:
"""Generates a product image with a custom background.
Args:
image_uri: The URI of the input image.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = ImageServiceClient(credentials=credentials)
# Creates the output config.
# Set `return_image_uri` to False to return the image bytes in the response.
output_config = OutputImageConfig(return_image_uri=True)
# Creates the input image.
# You can also use image bytes here instead of a URI.
input_image = InputImage(image_uri=image_uri)
# Creates the generate image background config.
generate_image_background_config = GenerateImageBackgroundConfig(
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"
),
)
# Creates the request.
request = GenerateProductImageBackgroundRequest(
name=_NAME,
output_config=output_config,
input_image=input_image,
config=generate_image_background_config,
)
# Makes the request and catches and prints any error messages.
try:
print(f"Sending GenerateProductImageBackground request: {_NAME}")
response = client.generate_product_image_background(request=request)
print("Generated product image background response below:")
print(response)
except RuntimeError as e:
print("Request failed.")
print(e)
if __name__ == "__main__":
# The URI of the image to use as the base for the generation.
# Replace with your image URI.
_IMAGE_URI = (
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
)
generate_product_image_background(_IMAGE_URI)
从商品图片中移除背景
此示例展示了如何从商品图片中移除背景。
请求
请求正文包含图片(URI 或字节)以及可选的用于替换背景的颜色。
注意:
- 以 RGB 格式指定颜色值,范围为 [0-255]。
- 如果您未指定背景颜色,则会生成 RGBA 4 通道透明图片。
以下是使用图片 URI 并将背景设置为绿色 (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
}
}
}
或者,您也可以使用原始图片字节执行相同的功能:
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
}
}
}
响应
您可能会收到如下所示的回答:
{
"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"
},
}
或者,如果 return_image_uri
在 output_config
中设置为 true
,则如下所示:
{
"generated_image": {
"uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEsYi83dcMKVV44i3vHDHzz_PJLuPyJHh9iX7IrsZ0ZIIRIS6SB4ovBmr0L9lZ1VNacZ5duwhcJ8Q8mXMYaIEArf2ieC2OuKEhRzVb-UxlkAUpitEpS5-M3Y3Ch3TGhQTZmBJXlsHLTuf0XcPwNHoNxJlgF0v_mQ6DIlPugZKC_WiYN2DNUkJivfr4WvifhMn5NaMKpDwpH4Acj-bdGNQ77M-8sj4SyEu3sHCF8ZtnMvF5DbGIYOJQ"
}
}
代码示例
以下代码示例展示了如何移除商品图片背景:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceSettings;
import com.google.shopping.merchant.productstudio.v1alpha.InputImage;
import com.google.shopping.merchant.productstudio.v1alpha.OutputImageConfig;
import com.google.shopping.merchant.productstudio.v1alpha.RemoveImageBackgroundConfig;
import com.google.shopping.merchant.productstudio.v1alpha.RemoveProductImageBackgroundRequest;
import com.google.shopping.merchant.productstudio.v1alpha.RemoveProductImageBackgroundResponse;
import com.google.shopping.merchant.productstudio.v1alpha.RgbColor;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create product images with the background removed. */
public class RemoveProductImageBackgroundSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void removeProductImageBackground(Config config, String imageUri) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
ImageServiceSettings imageServiceSettings =
ImageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ImageServiceClient imageServiceClient = ImageServiceClient.create(imageServiceSettings)) {
OutputImageConfig outputImageConfig =
// Set this field to false to return the image bytes in the response instead.
OutputImageConfig.newBuilder().setReturnImageUri(true).build();
InputImage inputImage =
InputImage.newBuilder()
// You can also use image bytes here instead of a URI.
.setImageUri(imageUri)
.build();
RemoveImageBackgroundConfig removeImageBackgroundConfig =
RemoveImageBackgroundConfig.newBuilder()
// Setting the background color to green. Don't set this field if you want the image
// to have a RGBA 4-channel transparent image as the background.
.setBackgroundColor(RgbColor.newBuilder().setRed(0).setGreen(255).setBlue(0))
.build();
RemoveProductImageBackgroundRequest request =
RemoveProductImageBackgroundRequest.newBuilder()
.setName(name)
.setOutputConfig(outputImageConfig)
.setInputImage(inputImage)
.setConfig(removeImageBackgroundConfig)
.build();
System.out.println("Sending RemoveProductImageBackground request: " + name);
RemoveProductImageBackgroundResponse response =
imageServiceClient.removeProductImageBackground(request);
System.out.println("Removed product image background response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// Replace with your image URI.
String imageUri =
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg";
removeProductImageBackground(config, imageUri);
}
}
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_productstudio_v1alpha import ImageServiceClient
from google.shopping.merchant_productstudio_v1alpha import InputImage
from google.shopping.merchant_productstudio_v1alpha import OutputImageConfig
from google.shopping.merchant_productstudio_v1alpha import RemoveImageBackgroundConfig
from google.shopping.merchant_productstudio_v1alpha import RemoveProductImageBackgroundRequest
from google.shopping.merchant_productstudio_v1alpha import RgbColor
# Gets the merchant account ID from the user's configuration.
_ACCOUNT = configuration.Configuration().read_merchant_info()
# The name of the account to which the request is sent.
# Format: accounts/{account}
_NAME = f"accounts/{_ACCOUNT}"
def remove_product_image_background(image_uri: str) -> None:
"""Removes the background from a product image.
Args:
image_uri: The URI of the input image.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = ImageServiceClient(credentials=credentials)
# Creates the output config.
# Set `return_image_uri` to False to return the image bytes in the response.
output_config = OutputImageConfig(return_image_uri=True)
# Creates the input image.
# You can also use image bytes here instead of a URI.
input_image = InputImage(image_uri=image_uri)
# Creates the remove image background config.
# Setting the background color to green. Don't set this field if you want the
# image to have a RGBA 4-channel transparent image as the background.
remove_image_background_config = RemoveImageBackgroundConfig(
background_color=RgbColor(red=0, green=255, blue=0)
)
# Creates the request.
request = RemoveProductImageBackgroundRequest(
name=_NAME,
output_config=output_config,
input_image=input_image,
config=remove_image_background_config,
)
# Makes the request and catches and prints any error messages.
try:
print(f"Sending RemoveProductImageBackground request: {_NAME}")
response = client.remove_product_image_background(request=request)
print("Removed product image background response below:")
print(response)
except RuntimeError as e:
print("Request failed.")
print(e)
if __name__ == "__main__":
# The URI of the image to remove the background from.
# Replace with your image URI.
_IMAGE_URI = (
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
)
remove_product_image_background(_IMAGE_URI)
放大商品图片
此示例展示了如何提高商品图片的画质和大小。
请求
请求正文包含图片(URI 或字节)。下面是使用图片 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"
}
}
或者,您也可以选择改用原始图片字节:
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'"
}
}
响应
您可能会收到如下回复
{
"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"
},
}
或者,如果 return_image_uri
在 output_config,
中设置为 true
,则如下所示:
{
"generated_image": {
"uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEvIFfK0YaLKvwvIBc9ItJtJGFE6hi25o6-N3Fz6YTw57pFghfIVlCGve7eyJcQkhoAqGAf8NDzW70qjwGOCuHhiouqF2nqxBwCcfDxZPkYRl3h7CIjyev9asJw7x-0g0V_xvurfowZJ0moXu98kmV01A3Thv2ZRlTAiOPYuEb8wnY7EeyD9l48lDdwJgZ4jqxtTgrRbwvpno4NICj9q830RzATiBHuJ_WUFQJiHOMAqbGyrQIWQTQ"
}
}
代码示例
以下代码示例展示了如何放大商品图片:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceSettings;
import com.google.shopping.merchant.productstudio.v1alpha.InputImage;
import com.google.shopping.merchant.productstudio.v1alpha.OutputImageConfig;
import com.google.shopping.merchant.productstudio.v1alpha.UpscaleProductImageRequest;
import com.google.shopping.merchant.productstudio.v1alpha.UpscaleProductImageResponse;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create upscaled product images. */
public class UpscaleProductImageSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void upscaleProductImage(Config config, String imageUri) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
ImageServiceSettings imageServiceSettings =
ImageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ImageServiceClient imageServiceClient = ImageServiceClient.create(imageServiceSettings)) {
OutputImageConfig outputImageConfig =
// Set this field to false to return the image bytes in the response instead.
OutputImageConfig.newBuilder().setReturnImageUri(true).build();
InputImage inputImage =
InputImage.newBuilder()
// You can also use image bytes here instead of a URI.
.setImageUri(imageUri)
.build();
UpscaleProductImageRequest request =
UpscaleProductImageRequest.newBuilder()
.setName(name)
.setOutputConfig(outputImageConfig)
.setInputImage(inputImage)
.build();
System.out.println("Sending UpscaleProductImage request: " + name);
UpscaleProductImageResponse response = imageServiceClient.upscaleProductImage(request);
System.out.println("Upscaled product image response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// Replace with your image URI.
String imageUri = "https://services.google.com/fh/files/misc/ring_image_400_600.jpg";
upscaleProductImage(config, imageUri);
}
}
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_productstudio_v1alpha import ImageServiceClient
from google.shopping.merchant_productstudio_v1alpha import InputImage
from google.shopping.merchant_productstudio_v1alpha import OutputImageConfig
from google.shopping.merchant_productstudio_v1alpha import UpscaleProductImageRequest
# Gets the merchant account ID from the user's configuration.
_ACCOUNT = configuration.Configuration().read_merchant_info()
# The name of the account to which the request is sent.
# Format: accounts/{account}
_NAME = f"accounts/{_ACCOUNT}"
def upscale_product_image(image_uri: str) -> None:
"""Upscales a product image.
Args:
image_uri: The URI of the input image.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = ImageServiceClient(credentials=credentials)
# Creates the output config.
# Set `return_image_uri` to False to return the image bytes in the response.
output_config = OutputImageConfig(return_image_uri=True)
# Creates the input image.
# You can also use image bytes here instead of a URI.
input_image = InputImage(image_uri=image_uri)
# Creates the request.
request = UpscaleProductImageRequest(
name=_NAME, output_config=output_config, input_image=input_image
)
# Makes the request and catches and prints any error messages.
try:
print(f"Sending UpscaleProductImage request: {_NAME}")
response = client.upscale_product_image(request=request)
print("Upscaled product image response below:")
print(response)
except RuntimeError as e:
print("Request failed.")
print(e)
if __name__ == "__main__":
# The URI of the image to upscale.
# Replace with your image URI.
_IMAGE_URI = "https://services.google.com/fh/files/misc/ring_image_400_600.jpg"
upscale_product_image(_IMAGE_URI)
常见错误和问题
下面列出了一些常见问题及其解决方案。
“必须提供输入图片”
如果您收到以下错误消息,请在请求正文中添加 input_image
:
Error message:
"error": {
"code": 400,
"message": "[input_image] Input image is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
“必须至少提供一个图片字段”
如果您收到以下错误消息,请在请求正文中正确填充 image_uri
或 image_bytes
,但只能填充其中一个。
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",
...
}
例如,发布以下内容会导致错误。
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
,并填充 product_description
和 background_description
:
Error message:
"error": {
"code": 400,
"message": "[config] Config is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
例如,发布以下内容会导致错误。
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
和 background_description
:
以下是缺少商品说明的示例:
Error message:
"error": {
"code": 400,
"message": "[config.product_description] Product description is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
以下是缺少背景说明的示例:
Error message:
"error": {
"code": 400,
"message": "[config.background_description] Background description is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
例如,运行以下请求会导致错误。
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": {
}
}