Create AI-generated Emails in Beefree SDK with Claude AI
Create AI-generated Emails in Beefree SDK with Anthropic's Claude AI and Simple Schema
Overview
This recipe explains how to build an AI-powered email creation system that generates email templates using Anthropic's Messages API, along with the Claude Sonnet 4 model, and converts them to full Beefree SDK templates using both Simple Schema and the Content Services API.
This recipe covers:
Simple Schema: Understanding the template structure and unified schema.
Anthropic API Integration: Structuring API calls and handling responses.
Frontend Integration: Capturing end user email descriptions and sending it to Anthropic inside a detailed prompt.
Response Parsing: Extracting and validating JSON from Anthropic's responses.
Beefree SDK Integration: Converting simple templates to full templates and loading them in the builder.
Reference the complete code for this project in the simple-schema-concept folder inside the Simple Schema GitHub repository.
Prerequisites
Node.js
Beefree SDK credentials
Understanding of Beefree SDK's Simple Schema
Knowledge of Beefree SDK's Content Services API and
/simple-to-full-json endpoint
Core Concepts and Steps
This section details all of the core concepts required to integrate AI-generated emails within Beefree SDK. It includes descriptions of each concept, sample code, and a the complete implementation at the end, along with customization tips.
As a reminder, the complete code for this recipe is available for reference in GitHub.
The following video shows the final result, and how the code for this recipe looks when you run it locally on your machine.
The following diagram shows how these core concepts relate to one another to create the experience shown in the video above.

1. Simple Schema Structure
Simple Schema is a simplified JSON format that makes it easy to generate email templates programmatically. It uses a hierarchical structure with templates, rows, columns, and modules. Understanding and using Simple Schema is critical for building AI-powered workflows, because it's simpler JSON makes it much easier for AI to read, understand, and build. Beefree SDK's full JSON is complex and feature-rich, making it difficult to train AI on.
Template Structure
The following code snippet shows the template structure for simple JSON.
Supported Module Types
Simple Schema supports the following module types:
title- Email titles and headingsparagraph- Text contentbutton- Call-to-action buttonsimage- Images and graphicsdivider- Visual separatorshtml- Custom HTML contentlist- Bulleted or numbered listsmenu- Menusicons- Social media and other icons
2. Anthropic API Integration
This section discusses how to structure and make an API call to Anthropic.
API Call Structure
The following code snippet shows an example API call to Anthropic.
Sample Request
The following code snippet shows an example prompt. It includes pre-defined instructions, and the end user's input on the frontend to guide the creation of the email template.
Sample Response
The following code snippet shows an example response from Anthropic.
3. Frontend Integration
This section discusses the Frontend integration and how to capture an end user's email description prompt, and pass it to the Anthropic API call for context on what type of email template it should build.
Capturing User Input
Sending to Anthropic API
4. Response Parsing
This section includes two important topics. The first is how to parse the response from Anthropic to only get the simple JSON and pass it to the /simple-to-full-json endpoint. The second is how to configure a second API call in the event the first one fails. Beefree SDK provides comprehensive feedback in the error message for a failed /simple-to-full-json API call. By applying this comprehensive feedback in a second API, the AI model being used can tyically return a valid simple JSON ready for conversion to full JSON.
Extracting JSON from Response
Error Correction Loop
5. Beefree SDK Integration
This section discusses the Beefree SDK integration. Beefree SDK provides the editing environment to load the full JSON into once it is created. Once it is loaded within the editor, the end user can begin customizing their AI-generated email design.
Converting Simple to Full JSON
Loading in Beefree SDK Builder
Complete Implementation
This section includes the code for both APIs together (Anthropic API call and /simple-to-full-json API call), and the dependencies they require.
Proxy Server (proxy-server.js)
Customization Tips
This section list a few customization tips you can apply to the code in your own environment.
Prompt Engineering: Modify the prompt to generate different types of emails or include specific branding requirements
Module Types: Add custom module types or modify existing ones based on your needs
Error Handling: Implement more sophisticated error correction logic
Template Validation: Add additional validation before sending to Beefree API
User Experience: Add progress indicators and better error messages
Troubleshooting
If you encounter any errors, try troubleshooting the following:
JSON Parsing Errors: Check the raw response from Anthropic and adjust parsing logic
Beefree Validation Errors: Review the error details and update the correction prompt
API Rate Limits: Implement rate limiting and retry logic
Template Loading Issues: Verify localStorage permissions and data format
This recipe provides a complete foundation for building AI-powered email creation systems with Beefree SDK and Anthropic's Messages API and Claude Sonnet 4 model.
Last updated
Was this helpful?

