The Text Suggestions API leverages the generative AI tools of Product Studio API to generate and optimize product titles and descriptions. You can use it to improve customer engagement and conversion.
What can you generate using the API?
- Suggested product titles and descriptions based on your product image and/or product attributes.
- SEO-optimized titles for your products
- Custom-formatted titles for your products
- Product descriptions from your product feed
You can also specify tone of voice for the descriptions.
Quickstart
The GenerateProductTextSuggestions
method can generate or optimize product titles and descriptions using your
product information.
The API accepts:
- Product Attributes (JSON Dictionary): A JSON object containing product
attributes (such as,
{"title": "White Tee", "brand": "MyBrand", "size": "XL"}
) - Product Image: A URI pointing to the product image (such as,
{"uri": "https://my-store.com/img/1.png"}
) - Title Formatting Options: Parameters for customizing title generation,
including:
attribute_separator
: Specifies the separator between attributes.target_language
: Sets the output language.attribute_order
: Defines the order of attributes in the generated title.
- Data labelling examples: See an example of how to Generate a title from a description.
- Workflow ID (
output_spec.workflow_id
): Theworkflow_id
field within theoutput_spec
object determines the type of text generation:title
: Generates or optimizes the product title.description
: Generates or optimizes the product description.tide
: Generates or optimizes both the product title and description.
Examples
The following are examples using the API to generate or optimize a title or description or both from different product data inputs. We also present Common errors and issues and their solutions.
Optimized title generation
The example shows how to generate a optimal title.
Request
The request body contains the product information to use for title optimization. Here's an example of the request structure:
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Nike Mens shoes",
"description": "Give strength to your step with the Nike Air Zoom Pegasus 38 shoe for Men with shoe size 12. Ensuring the fit is loved by the runners. This shoes comes in Blue color.",
"brand": "Nike"
}
},
"output_spec": {
"workflow_id": "title"
}
}
Response
You can expect a response like
{
"title": {
"text": "Nike Mens shoes Air Zoom Pegasus 38 Running Shoes, Blue, Size 12"
},
"metadata": {
"metadata": {
"attributes": {
"color": "Blue",
"size": "12",
"product": "Running shoes",
"model": "Air Zoom Pegasus 38"
},
}
}
}
Generate a title from only an image
The example shows how to provide a product image and generate a optimal title.
Request
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_image":{
"uri": "https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415"
}
},
"output_spec": {
"workflow_id": "title",
"attribute_separator": "-"
}
}
Response
{
"title": {
"text": "Rustic Ceramic & Leather Leaves Necklace"
},
"metadata": {
"metadata": {
"attributes": {
"material": "Rustic Ceramic & Leather",
"pattern": "Leaves",
"product": "Necklace"
},
}
}
}
Generate a title from a description
The example shows how to provide a product description and generate a optimal title.
Request
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"description": "selling size 12 nike dunks. oh they are red by the way!"
}
},
"output_spec": {
"workflow_id": "title",
}
}
Response
{
"title": {
"text": "Nike Dunks Red Size 12"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Nike",
"color": "Red",
"size": "12",
"product": "Dunks"
},
}
}
}
Optimize titles from a title and description (along with custom example)
In this example, we explicitly label the product attributes we want the AI to identify and the attribute ordering in the output.
Request
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
"brand": "Luxe Beauty"
}
},
"output_spec": {
"workflow_id": "title"
}
"title_examples": [
{
"product_info": {
"title": "Lash Paradise Volumizing & Lengthening Mascara - Waterproof - Blackest Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Lash Paradise",
"mascara_type": "Volumizing & Lengthening",
"colour": "Blackest Black",
"waterproof": "Waterproof",
}
},
{
"product_info": {
"title": "Hypnose Drama Instant Full Body Volume Mascara - Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Hypnose",
"sub_brand": "Drama",
"mascara_type": "Full Body Volume",
"colour": "Black",
"eye_lash_type": "All lash types"
}
}
]
}
Response
{
"title": {
"text": "Luxe Beauty Dark Brown Volumizing & Lengthening Mascara"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Luxe Beauty",
"colour": "Dark Brown",
"mascara_type": "Volumizing & Lengthening",
"product": "Mascara"
},
}
}
}
Generate description from a title
The example shows how to provide a product title and ask the API to generate a corresponding product description.
Request
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Rustic Ceramic & Leather Leaves Necklace",
}
},
"output_spec": {
"workflow_id": "description"
}
}
Response
{
"description": {
"text": "Rustic Ceramic & Leather Leaves Necklace is a beautiful necklace made from high-quality ceramic and leather. It features a unique design that is sure to turn heads.
"
},
}
Generate a title and description from product attributes (like brand and color)
This example demonstrates providing product attributes to generate an optimal product title and description.
Request
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"brand": "Mr. Beast",
"color": "purple",
},
"product_image":{
"uri": "https://mrbeast.store/cdn/shop/files/0015dlv_0000_327.jpg?v=1702754475&width=500"
}
},
"output_spec": {
"workflow_id": "description"
}
}
Response
{
"title": {
"text": "Pajamas - Mr. Beast | Purple"
},
"description": {
"text": "Slip into the ultimate comfort and style with these Mr. Beast pajamas in a vibrant shade of purple. Crafted from the softest materials, these pajamas will envelop you in a cozy embrace, ensuring a restful night's sleep. The shorts feature a relaxed fit, allowing for easy movement, while the top boasts a classic design with a comfortable neckline. Whether you're lounging at home or drifting off to dreamland, these Mr. Beast pajamas are the perfect choice for a peaceful and stylish slumber."
},
}
Target Language Support
This field specifies the language of the description text generated in the API
response. You can add the target_language
as part of the output_spec
parameters:
{
"output_spec": {
"target_language": "language"
}
}
Example Values:
"korean" (Korean)
"english" (English)
"spanish" (Spanish)
"french" (French)
Example Request
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Granos de café negro",
"description": "Los granos de café negro en California",
"brand": "Parfums de Paris",
"scent": "Floral",
},
"product_image":{
"uri": "https://mrbeast.store/cdn/shop/files/0015dlv_0000_327.jpg?v=1702754475&width=500"
}
},
"output_spec": {
"workflow_id": "description",
"target_language": "japanese",
"attribute_order": ["scent", "product"],
"tone": "playful",
}
}
Response
{
"description": {
"text": "カリフォルニアの黒いコーヒー豆は、あなたの鼻をくすぐる、甘く、フローラルな香りです。この香りは、コーヒー豆の豊かな香りと、ジャスミンとバラの繊細な花の香りをブレンドしたものです。カリフォルニアの黒いコーヒー豆は、あなたの家を居心地の良いカフェに変え、あなたをリラックスした気分にさせてくれるでしょう。この香りは、コーヒー好きにも、フローラルな香り好きにも最適です。カリフォルニアの黒いコーヒー豆で、あなたの家を幸せな香りで満たしましょう!."
},
}
Tone of Voice Personalization for Description Generation
To help establish your brand and differentiate your online store from others, you can personalize the tone of voice of your generated descriptions. The Text API offers two options:
- Predefined Tone Selection: You can select from a list of tones to
generate new descriptions. The list includes these tone styles:
- Default: Simple, clear, and elegant.
- Playful: Lighthearted, using positive language, humor (jokes, puns), and exaggeration (no irony, sarcasm, or emojis).
- Formal: Standard English, proper grammar, complete sentences, no slang or contractions.
- Persuasive: Logical, concise, and argument-driven to convince the reader.
- Conversational: Friendly, easy-to-understand, everyday language.
- Brand-Specific Tone: You can provide existing descriptions or other text
assets in your brand's tone of voice. The Generative AI model will analyze
the tone of the text and generate a "writing style descriptor" according to
these aspects:
- Formality (such as, formal, casual)
- Verbosity (such as, concise, very verbose)
- Tone (such as, professional, informative, positive, persuasive)
- Sentence structure (such as, "simple sentence with few conjunctions")
- Most frequent words and phrases used
Client libraries
We recommend that you use client libraries to submit your requests. We will share the client libraries with you which you can install in your Maven project.
Code samples
Choose your method of authentication, and set up these code samples using these instructions. Here's a sample you can use to generate text suggestions.
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductTextSuggestionsRequest;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductTextSuggestionsResponse;
import com.google.shopping.merchant.productstudio.v1alpha.OutputSpec;
import com.google.shopping.merchant.productstudio.v1alpha.ProductInfo;
import com.google.shopping.merchant.productstudio.v1alpha.TextSuggestionsServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.TextSuggestionsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to generate product text suggestions. */
public class GenerateProductTextSuggestionsSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void generateProductTextSuggestions(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
TextSuggestionsServiceSettings textSuggestionsServiceSettings =
TextSuggestionsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (TextSuggestionsServiceClient textSuggestionsServiceClient =
TextSuggestionsServiceClient.create(textSuggestionsServiceSettings)) {
ProductInfo productInfo =
ProductInfo.newBuilder()
.putProductAttributes("title", "Mens shirt")
.putProductAttributes("description", "A blue shirt for men in size S")
.build();
OutputSpec outputSpec = OutputSpec.newBuilder().setWorkflowId("title").build();
GenerateProductTextSuggestionsRequest request =
GenerateProductTextSuggestionsRequest.newBuilder()
.setName(name)
.setProductInfo(productInfo)
.setOutputSpec(outputSpec)
.build();
System.out.println("Sending GenerateProductTextSuggestions request: " + name);
GenerateProductTextSuggestionsResponse response =
textSuggestionsServiceClient.generateProductTextSuggestions(request);
System.out.println("Generated product text suggestions response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occured: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
generateProductTextSuggestions(config);
}
}
Common errors and issues
Here are a few common pitfalls and their solutions.
Product info is required to generate text suggestions
Should you receive the following error message
Error message:
"error": {
"code": 400,
"message": "[product_info] Product info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
add product_info
in the request body and populate correctly at least one of
product_attributes
or product_image
.
For example, posting this will result in an error.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"output_spec": {
"workflow_id": "title"
}
}
At least one field of product_info is required to generate text suggestions
This error
{
"error": {
"code": 400,
"message": "[product_info.product_attributes] At least one field of product_info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
is an indication that you need to include at least one product_info
field in
the request body.
For example, posting this would result in an error.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
},
"output_spec": {
"workflow_id": "title"
}
}
Use instead something like
"product_info": {
"product_attributes": {
"description": "Selling size 12 Nike dunks. Oh they are red by the way!"
}
}
or
"product_info": {
"product_image":{
"uri": "https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415"
}
}
(Something) is required in each title_example
Errors like the following four examples
{
"error": {
"code": 400,
"message": "[title_examples.product_info] At least one field of product_info is required in each title_example.",
"status": "INVALID_ARGUMENT",
...
}
or
{
...
"message": "[title_examples.category] Category is required in each title_example.",
...
}
or
{
...
"message": "[title_examples.title_format] Title format is required in each title_example.",
...
}
or
{
...
"message": "[title_examples.final_product_info] At least one field of final_product_info is required in each title_example.",
...
}
indicate that you have not populated a required sub-field.
For example, the following request would generate an error.
POST
https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"description": "selling size 12 nike dunks. oh they are red by the way!"
}
},
"output_spec": {
"workflow_id": "title"
},
"title_examples": []
}
To solve this, for each title_example specified in the request populate all of of the following sub-fields:
product_info
category
title_format
final_product_info
Here's an example that works:
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
}
},
"output_spec": {
"workflow_id": "title"
},
"title_examples": [
{
"product_info": {
"title": "Lash Paradise Volumizing & Lengthening Mascara - Waterproof - Blackest Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Lash Paradise",
"mascara_type": "Volumizing & Lengthening",
"colour": "Blackest Black",
"waterproof": "Waterproof",
}
}
]
}
Unsupported workflow_id
This type of error
{
"error": {
"code": 400,
"message": "[\u003ceye3 title='/ProductStudioTextGenerationService.GenerateProductText, INVALID_ARGUMENT'/\u003e APPLICATION_ERROR; ... ;Unsupported workflow_id: attributes. Supported workflows are: [\"title\", \"description\", \"tide\"];AppErrorCode=3;StartTimeMs=1740696804045;unknown;ResFormat=uncompressed;ServerTimeSec=0.005976589;LogBytes=256;Non-FailFast;EffSecLevel=none;ReqFormat=uncompressed;ReqID=4d1786f59faa3ea7;GlobalID=0;Server=[2002:a05:6e16:618:b0:2c2:7cfc:bebd]:14001] Invalid value",
"status": "INVALID_ARGUMENT",
...
}
would result from a request like
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
},
"output_spec": {
"workflow_id": "attributes"
}
}
The request sets workflow_id
to "attributes", but this field supports only one
of the following values:
- title: Generates or optimizes the product title.
- description: Generates or optimizes the product description.
- tide: Generates or optimizes both the product title and description.
Unsupported tone
An "Unsupported tone" error such as
{
"error": {
"code": 400,
"message": "[\u003ceye3 title='/ProductStudioTextGenerationService.GenerateProductText, INVALID_ARGUMENT'/\u003e APPLICATION_ERROR; ... ; Unsupported tone: 'asdf'. Supported tones are: [\"default\", \"playful\", \"formal\", \"persuasive\", \"conversational\"];AppErrorCode=3;StartTimeMs=1740697325058;unknown;ResFormat=uncompressed;ServerTimeSec=7.45346E-4;LogBytes=256;Non-FailFast;EffSecLevel=none;ReqFormat=uncompressed;ReqID=f7d9bbbc73a1d342;GlobalID=0;Server=[2002:a05:6918:3486:b0:2bc:ccd4:79e6]:14001] Invalid value",
"status": "INVALID_ARGUMENT",
...
}
would result from a request such as
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
},
"output_spec": {
"workflow_id": "description"
"tone": "cheerful"
}
}
Notice that tone
is being set to "cheerful", but this field supports only one
of the following values:
- default: Simple, clear, and elegant.
- playful: Lighthearted, using positive language, humor (jokes, puns), and exaggeration (no irony, sarcasm, or emojis).
- formal: Standard English, proper grammar, complete sentences, no slang or contractions.
- persuasive: Logical, concise, and argument-driven to convince the reader.
- conversational: Friendly, easy-to-understand, everyday language.