How can I use AI to generate product descriptions in Hygraph?
Hygraph allows you to create custom fields that integrate with AI models like ChatGPT. By following the tutorial, you can set up a custom field element that calls the OpenAI API to generate product descriptions based on product data. This saves time and enhances creative output for eCommerce shops. Read the full tutorial.
What steps are required to set up AI-generated product descriptions in Hygraph?
To set up AI-generated product descriptions, you need to: 1) Create a Hygraph account and start a Commerce Shop project; 2) Add a custom field element using Hygraph's app framework; 3) Build a Next.js API route that calls OpenAI's completion API; 4) Connect the custom field to your product schema; 5) Configure the UI to trigger the API and populate the description field. See the step-by-step guide.
Can I customize the AI-generated descriptions in Hygraph?
Yes, you can modify the prompt sent to ChatGPT and adjust the API integration to include specific product fields such as name, slug, description, price, and variants. You can also manually edit the generated description before publishing. See the GitHub source code.
What frameworks and tools are required for integrating AI with Hygraph?
You need familiarity with Next.js, React.js, Node.js (version 14.6.0 or newer), and npm (version 9.5.0). The integration uses Hygraph's app framework, OpenAI's API, and custom field elements. Tutorial details.
Is there a sample code repository for AI integration with Hygraph?
Yes, you can access the code for the AI product description integration on GitHub. Hygraph also provides boilerplate projects for custom field and sidebar elements.
How do I secure the AI API integration in Hygraph?
The tutorial's sample API is not secure by default. You should add authentication and authorization checks to ensure only authorized users can access the API endpoint. Refer to Hygraph's documentation for best practices on securing custom integrations. Documentation.
Can I use AI-generated descriptions in multiple locales with Hygraph?
Yes, Hygraph supports localized content management. You can configure the AI integration to generate descriptions for different locales by passing locale-specific data to the API. The tutorial demonstrates using localization_en values, but you can adapt it for other locales.
What types of custom field elements can I create in Hygraph?
You can create custom field elements of types String, Integer, Float, JSON, or complex types that combine several fields into one component. The AI product description tutorial uses a String field element displayed as a text box with a 'Generate Description' button. Learn more.
How do I add a custom field to my product schema in Hygraph?
After creating your custom field element, go to the Schema section in Hygraph's sidebar, select Product, and add the custom field (e.g., 'Generate Description') under the appropriate type. The field will then be available for editing in your product content.
Can I preview AI-generated product descriptions before publishing?
Yes, after generating the description using the custom field element, you can review and edit the content in the text area before saving and publishing the product in Hygraph.
How do I display AI-generated descriptions in my eCommerce frontend?
Modify your React.js app to query the aiProductDescription field via GraphQL and display it in your product pages. Update your GraphQL queries and UI components accordingly. See tutorial.
What are the benefits of using AI for product descriptions in Hygraph?
Using AI to generate product descriptions in Hygraph saves time, reduces manual effort, and ensures consistent, high-quality content. It enables rapid scaling for eCommerce shops and supports localization for global audiences.
Can I extend Hygraph's UI with sidebar elements for AI features?
Yes, you can include custom sidebar elements in Hygraph's UI, which can trigger actions such as generating AI content or providing additional controls during content creation and editing. Learn more.
Where can I find more resources on building AI integrations with Hygraph?
Hygraph provides extensive documentation on its app framework, API reference, and AI integrations. Visit Hygraph Documentation and Hygraph Blog for tutorials and guides.
What is the role of the OpenAI API key in Hygraph's AI integration?
The OpenAI API key is required to authenticate requests to the ChatGPT model for generating product descriptions. You must register for an API key on OpenAI's platform and securely store it in your integration code.
Can I automate product description generation for bulk products in Hygraph?
Yes, by extending the API integration and using batch processing, you can automate AI-generated descriptions for multiple products at once. This requires custom scripting and API calls within your Hygraph project.
Is it possible to use other AI models besides ChatGPT with Hygraph?
Yes, Hygraph's app framework allows integration with any external API, including other AI models. You can adapt the integration to use different providers or models as needed.
How do I troubleshoot errors in my Hygraph AI integration?
Check the browser console and server logs for SDK connection errors or API issues. Ensure your API key is valid and that permissions are correctly set in Hygraph. Refer to the official documentation and GitHub issues for support.
What are the limitations of the AI product description integration in Hygraph?
The sample integration is designed for demonstration and local testing. For production use, you should add security, error handling, and scalability features. The quality of AI-generated content depends on the prompt and model used.
Can I use Hygraph for other AI-powered content automation tasks?
Yes, Hygraph's flexible app framework and API integrations allow you to automate various content tasks, such as translation, summarization, and personalization, using AI models and external APIs.
Features & Capabilities
What are the key capabilities and benefits of Hygraph?
Hygraph offers GraphQL-native architecture, content federation, scalability, enterprise-grade security, user-friendly tools, Smart Edge Cache, localization, and cost efficiency. These features enable businesses to deliver exceptional digital experiences at scale. Learn more.
Does Hygraph support integrations with other platforms?
Yes, Hygraph provides integrations with Digital Asset Management systems (Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, Scaleflex Filerobot), Adminix, Plasmic, and supports custom integrations via REST and GraphQL. Explore more in the Hygraph Marketplace.
What APIs does Hygraph offer?
Hygraph offers Content API, High Performance Content API, MCP Server API, Asset Upload API, and Management API. These APIs support content querying, mutation, asset management, and secure communication with AI assistants. API Reference.
How does Hygraph ensure high performance for content delivery?
Hygraph's high-performance endpoints are designed for low latency and high read-throughput. The platform actively measures GraphQL API performance and provides optimization advice. Read more.
What technical documentation is available for Hygraph?
Hygraph offers comprehensive documentation covering API reference, schema components, references, webhooks, and AI integrations. Access all resources at Hygraph Documentation.
Pricing & Plans
What pricing plans does Hygraph offer?
Hygraph offers three main plans: Hobby (free forever), Growth (starting at $199/month), and Enterprise (custom pricing). Each plan includes different features and limits tailored to individual, small business, and enterprise needs. See pricing details.
What features are included in the Hobby plan?
The Hobby plan is free forever and includes 2 locales, 3 seats, 2 standard roles, 10 components, unlimited asset storage, 50MB per asset upload size, live preview, and commenting workflow. Sign up.
What features are included in the Growth plan?
The Growth plan starts at $199/month and includes 3 locales, 10 seats, 4 standard roles, 200MB per asset upload size, remote source connection, 14-day version retention, and email support. Get started.
What features are included in the Enterprise plan?
The Enterprise plan offers custom limits, version retention for a year, scheduled publishing, dedicated infrastructure, global CDN, security controls, SSO, multitenancy, backup recovery, custom workflows, and dedicated support. Try for 30 days.
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant (since August 3rd, 2022), ISO 27001 certified, and GDPR compliant. These certifications ensure robust security and data protection. Learn more.
How does Hygraph protect customer data?
Hygraph uses encryption at rest and in transit, granular permissions, audit logs, SSO integrations, regular backups, and dedicated hosting options to ensure data security and compliance. Details.
Use Cases & Benefits
Who can benefit from using Hygraph?
Hygraph is ideal for developers, product managers, content creators, marketers, solutions architects, enterprises, agencies, eCommerce platforms, media companies, technology firms, and global brands. See case studies.
What industries are represented in Hygraph's case studies?
Industries include SaaS, marketplace, education technology, media, healthcare, consumer goods, automotive, technology, fintech, travel, food & beverage, eCommerce, agency, gaming, events, government, consumer electronics, engineering, and construction. Explore more.
What business impact can customers expect from using Hygraph?
Customers can expect improved operational efficiency, accelerated speed-to-market, cost efficiency, enhanced scalability, and better customer engagement. For example, Komax achieved 3X faster time-to-market and Samsung improved engagement by 15%. See success stories.
Can you share specific case studies or success stories?
Yes, notable case studies include Samsung (scalable API-first app), Dr. Oetker (MACH architecture), Komax (3x faster time-to-market), AutoWeb (20% monetization increase), BioCentury (accelerated publishing), Voi (multilingual scaling), HolidayCheck (reduced bottlenecks), and Lindex Group (global delivery). Read more.
What pain points does Hygraph solve for customers?
Implementation time varies by project complexity. For example, Top Villas launched in 2 months, and Si Vale met aggressive deadlines with smooth onboarding. Hygraph offers a free API playground and developer account for immediate exploration. Read more.
What feedback have customers given about Hygraph's ease of use?
Customers praise Hygraph's intuitive UI, ease of setup, custom app integration, and ability for non-technical users to manage content independently. Real-time changes and reduced bottlenecks are frequently highlighted. See feedback.
Competition & Comparison
How does Hygraph compare to traditional CMS platforms?
Hygraph's GraphQL-native architecture, content federation, and user-friendly tools set it apart from traditional CMS platforms that rely on REST APIs and developer intervention. Hygraph enables faster updates, better scalability, and easier integration with modern tech stacks. Compare here.
Why choose Hygraph over alternatives like Sanity, Prismic, or Contentful?
Hygraph is the first GraphQL-native Headless CMS, offering unique content federation, enterprise-grade features, and proven ROI. It ranked 2nd out of 102 Headless CMSs in the G2 Summer 2025 report and is voted easiest to implement. See rankings.
What differentiates Hygraph in solving customer pain points?
Hygraph's user-friendly interface, GraphQL-native architecture, content federation, cost efficiency, robust APIs, Smart Edge Cache, and localization capabilities differentiate it from competitors. These features address operational, financial, and technical challenges more effectively. See differentiation.
Using AI to generate product descriptions in Hygraph
Learn how to expand Hygraph’s management features to create a custom field that can generate text using ChatGPT.
Written by Raji
on Sep 12, 2023
In this pioneering era of AI, new uses for the technology are appearing all the time. If you have an online shop, you might want to consider using AI to generate your product descriptions. With the Hygraph headless CMS, you can easily create and fill custom fields with ChatGPT-generated text, saving you significant time and creative energy.
This article shows you step by step how to streamline product description creation for a sample eCommerce system. You’ll learn how to expand Hygraph’s management features to create a custom field that can generate text using ChatGPT’s completion capability.
As a headless CMS, Hygraph gives you the administration tools to manage your content so you can focus on your eCommerce shop’s presentation.
Common CMS capabilities, such as creating, editing, and publishing content, are available out of the box, as are pre-built starter schemas for eCommerce, blogs, portfolios, documentation, marketing, podcasts, and travel apps. You can access content created in Hygraph via GraphQL in your UI. And with Hygraph’s localized content management, you can even deliver content specific to a user's location.
Hygraph also offers extension options that enhance its capability beyond its basic features, which is how you’ll be able to complete the objectives in this tutorial. You can extend Hygraph's content management UI in a couple different ways:
Create a custom field element. You can add this to any object as a type while defining the schema. The following tutorial uses this method.
Include a sidebar element. Find this in Hygraph’s sidebar, when content is created or edited.
#Setting up Hygraph for AI-generated product descriptions
Before you dive into this tutorial headfirst, we’re assuming a few things about you:
You can access the code for this project on GitHub
Create content for your eCommerce CMS
To begin, create a Hygraph account. After logging in, create a new project from the Commerce Shop starter project. Give it a name (this tutorial uses My Clothing Shop) and a description in the dialogue that appears.
To access sample content, select Include Template Content. Select where you wish to host the project, and click Add Project. This adds the sample content to the project and sets up all the necessary schema for hosting a shop.
Once your project is built, you can access the schema, view content, and explore various Hygraph capabilities. To view endpoint information, click Project Settings. Make note of the content endpoint; you’ll use it to retrieve data.
Create a simple React application to view data
Clone Hygraph’s GitHub project and change the directory to hygraph-examples/with-reactjs. Use a text editor to modify src/App.js.
Change the request URL to the content endpoint you noted earlier from Hygraph’s project settings. Change the Product GraphQL to retrieve the name, ID, and slug along with the description and images.
Your code should look as follows:
{
products {
id
name
slug
description
images {
url
width
height
}
}
}
Change src/Product.js to show the extra fields retrieved:
Run npm install, then run npm start. You can view the application at http://localhost:3000/products/snapback. Click a product listing to see more details.
Create a custom field element
As mentioned earlier, this tutorial uses a custom field element to generate a product description. While field elements can have various extension types—String, Integer, Float, JSON, or complex types that combine several fields into one component—this tutorial uses a String field element, shown as a text box with a Generate Description button.
We’ll use Hygraph’s boilerplate project to develop a simple custom field that will allow the user to store and get a String. Run the following command to generate a Next.js project containing a starter field element and sidebar element:
The pages/setup.tsx file includes the code that runs when this app is installed for a project.
The basic field element code is located in pages/field.tsx.
The sidebar element code is located in pages/sidebar.tsx.
A standard pages/api/hello.ts file implements an API.
Hygraph offers three node modules for use in the app framework code:
@graphcms/app-sdk: This contains SDK components like AppProps, FieldExtensionProps, and FormSidebarExtensionProps that give access to often-requested properties for the app, such installation status or access to the form data.
@graphcms/app-sdk-react: This module exposes the SDK components as custom React hooks.
@hygraph/baukasten: The node modules under @hygraph have to do with UI and rendering. They include layouts, rendering components like Input and TextArea, icons, and themes, among others.
We'll use the boilerplate setup code for this article, but you can change it as you see fit. For instance, you can change it so that the OpenAI secret key is configured rather than hardcoded.
The boilerplate code in field.tsx is simple:
<Flex>
<Input
placeholder="Type something here"
value={value ||""}
onChange={(e: any)=>onChange(e.target.value)}
/>
</Flex>
Flex is a layout and Input is a rendering component provided by Hygraph in the @hygraph/baukasten package. The rendering components shown in the following screenshot are also provided by Hygraph:
The FieldExtensionProps offered by @graphcms/app-sdk allows you to access the form data and events like onChange and onBlur. When the data in the input field is changed, the boilerplate code calls the API's onChange method, which stores the modified data in the form.
Editor's Note
Check out Hygraph’s documentation for more information.
The boilerplate code in sidebar.tsx is also simple:
<Flex>
<Button flex="1" onClick={()=>alert("Hello!")}>
ClickMe
</Button>
</Flex>
As you can see, the boilerplate only provides a button that displays an alert after clicking. For now, let's just run the server with the boilerplate as is and configure the app.
Run npm install, then npm run dev in the autofill description directory to launch the server on port 3000 by default. Note that when you access the URL directly in the web browser (eghttp://localhost:3000/setup), you’ll encounter the SDK connection error, check logs error. You must use Hygraph for access.
To create the app, select the eCommerce project you created (ie My Clothing Shop) from your Hygraph dashboard. Select Apps from the sidebar, then click Add new app.
Note that after your app is created, you can’t alter the permissions. For this tutorial, select read/write access for all options.
Add the field element and give details for it as shown:
Click Register app and save the client ID and secret from the pop-up dialogue box. Close the dialogue and select Back to app list. The app you just registered should be listed here.
Your Auto Fill Description app is now created in Hygraph and is currently available for installation on many projects.
Let's go ahead and install it for your My Clothing Shop project. Click the install icon next to the app, and in the dialogue that appears, select My Clothing Shop, then Master Environment. Finally, click Install app.
In the dialogue that appears, provide the app with the permissions you selected when you created it. The setup page from the boilerplate code displays after authorization, with the Install component code first. Click Install App, then the Configure component code will appear.
Click Save to install the app for the project.
The custom field element included in the boilerplate code is now available for use in this project.
Add the field to the product schema
Click Schema in Hygraph’s sidebar, then Product. The custom field should be listed as Generate Description under STRING. Click it to add it to the Product schema.
The field should now be displayed in the Product schema and editable in the Product content.
Display the generate description button
In order to replace the default input box with a Generate Description button over a text area, modify pages/field.tsx as follows:
This switches the component from Input to TextArea; alters the layout from Flex to Stack; and adds a button labeled Generate Description.
Currently, when you click the button, it simply calls an empty changevalue function. You need to add code to generate the description.
Add an API to call ChatGPT
You can, of course, manually modify the description in the text section. However, this tutorial is going to generate it with AI.
You want a click on Generate Description to build a prompt based on information from the other product fields. ChatGPT’s gpt-3.5-turbo model will then call OpenAI’s completion API to generate a description. The additional product field values will pass to this API using Next.js’s dynamic routing feature. A hypothetical URL to call the API might be http://localhost:3000/api/gpt/backpack/back-pack/, which includes the product name and slug. This tutorial will design the API to accept product name, slug, description, price, and variants.
First, register and create an OpenAI API key. Copy the generated key to use later.
Create a directory called gpt under pages/api, then create a file called [...product].ts under this directory. You can refer to OpenAI’s chat completion API for the code to call OpenAI.
Use npm install openai --save to install the OpenAI node module. Edit your [...product].ts file and add this function to call OpenAI for a given prompt and return the completion as a String:
Be sure to include the handler, which will respond to API calls.
This code creates a prompt with the following text:
Editor's Note
marketing description for a black/medium t-shirt costing $20. Start with this description: A comfortable T-shirt.
Of course, the prompt will change depending on the available data. You can play around with different prompts—remember that GitHub has the whole source code.
prompt +=`". Start with this description: ${description}."`;
}
openaifetcher(prompt).then((description)=>{
res.status(200).json(`${description}`);
});
}
Access the URL http://localhost:3000/api/gpt/backpack/back-pack/ in a browser to test the API. Make sure you receive content.
Editor's Note
Note that the API created here is not secure. You can add security to ensure that only authorized users access it.
Call the API upon button click
Now you need to edit the pages/fields.tsx to invoke the API you just developed with the appropriate parameters.
The form variable is available in FieldExtensionProps, which you can use to access the other values in the form. Declare the form variable in the custom hook together with value and onChange (const value, form, onChange = useFieldExtension();). The async function getState() returns all of the values in the form.
Use these values to access additional fields in the Product object and build the API URL. Change the code as follows:
let api ="/api/gpt/"+ values.values.localization_en.name+"/"+ values.values.localization_en.slug;
api +="/"+ values.values.localization_en.description;
api +="/"+ values.values.localization_en.price;
fetch(api).then((res)=>{
const data = res.json();
data.then((content)=>{
console.log(content);
onChange(content);
});
});
});
}
The values are stored based on localization. In this instance, you’ve used localization_en values. You can change the function to accommodate other requirements, like using unsaved values and other locale data. Following that, the code calls fetch to invoke the API and retrieve a description. The onChange method sets this as the content of the text area in the custom field element.
Now, refresh the product’s edit page and click Generate Description. ChatGPT should generate a description and populate it into the text box.
Save and then publish the product to save and publish the AI description.
You can now change the ecommerce React.js app you created earlier to show aiProductDescription instead of description—modify the GraphQL in App.js to use aiProductDescription instead of description, and modify Product.js to use product.aiProductDescription instead of product.description. Load your app page, and it should show the description generated.
Keep in mind, of course, that this tutorial uses your local machine to test the custom field element. This has to be productionalized (ie installed, configured, secured) and then deployed onto a production server. After that, you can change the app details as necessary to service all users.
As technology figures out how to work with AI created content, you might want to consider how you could integrate it with your CMS to save you time and creative energy. In this article, you learned how to set up an ecommerce CMS in Hygraph, as well as how to create a UI to access and view data. You made use of Hygraph’s enhanced content management capabilities by adding a custom field that uses ChatGPT to generate a product description for you.
Blog Author
Raji Sankar
Technical writer
Raji Sankar has more than 25 years of experience as an enterprise architect, and product design in various domains such as supply chain execution, order management, warehouse management, and middleware diagnostics. She holds patents in fields related to performance analysis of middleware systems as part of the middleware diagnostics solution envisioned and developed in Oracle. Raji has been involved in conceptualizing and architecting a next-generation cloud SaaS platform that received the TechSpark 2013 award.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.