How to Track Message History in Bubble.io AI Applications with OpenAI and Claude?
Understanding Message History in AI Applications
Creating a conversational AI application in Bubble.io requires properly tracking and managing message history. Unlike simple one-off queries, conversational AI needs to reference previous exchanges to maintain context and provide relevant responses. Both OpenAI (GPT models) and Anthropic (Claude) APIs require you to send previous messages in each request to enable this contextual awareness.
This capability is what makes AI assistants feel natural - they can reference information mentioned earlier in the conversation, creating a coherent multi-turn dialogue experience. Let's explore how to implement this functionality in a no-code Bubble.io application.
Setting Up Your Database Structure
The foundation of message history tracking is a well-designed database structure. In Bubble.io, you'll need to create the following:
1. Message Data Type: Create a data type (e.g., "Message" or "AIMessage") with these essential fields:
- Content (Text): The actual message content
- Role (Option Set): Who sent the message - typically "user" or "assistant"
- Thread/Conversation ID (Reference to a Conversation data type): Links messages to a specific conversation
- Timestamp (Date/Time): When the message was sent
2. Conversation/Thread Data Type: This helps organize messages into distinct conversations:
- Title (Text): Optional name for the conversation
- User (User): The user who owns this conversation
- Created Date (Date/Time): When the conversation started
- Last Updated (Date/Time): When the conversation was last active
Using option sets for roles is particularly useful as it creates a standardized way to identify message senders, matching the exact format expected by AI APIs.
Formatting Messages for API Calls
Both OpenAI and Claude APIs expect messages in a specific JSON format. Each message needs a "role" and "content" parameter, and they must be arranged chronologically (oldest first). Here's how to properly format your message history in Bubble:
1. Retrieve Messages: Use Bubble's "Do a search for" action to get all messages in a specific thread, sorted by creation date (ascending).
2. Format as JSON: Use Bubble's "Format as Text" feature to structure the messages in the required format:
For OpenAI/Claude, each message should look like: {"role": "user/assistant", "content": "message text"}
3. Make Content JSON-safe: Always use the JSON Safe function on message content to escape special characters that could break your JSON structure (like quotation marks and line breaks).
The exact format will look like this in your Bubble workflow:
Format as Text: {"role":"current cell's Message's Role's display","content":"current cell's Message's Content JSON safe"}
With the delimiter set as a comma to separate each message object.
Managing Context and Token Limits
A significant challenge in implementing conversation history is managing token limits. Both OpenAI and Claude have maximum token limits for each request (e.g., 4K, 8K, 16K, or 32K tokens depending on the model).
As conversations grow longer, you'll eventually hit these limits. Here are strategies to handle this:
1. Send Only Recent Messages: Instead of sending the entire conversation history, send only the most recent N messages (e.g., the last 10-15 messages).
In Bubble, you can implement this by:
- Sorting messages by date (descending)
- Using "Items until X" to get the most recent messages
- Re-sorting them by date (ascending) before formatting
2. Include System Messages for Context: Add a system message at the beginning that summarizes earlier parts of the conversation to maintain context while reducing token usage.
3. Implement Conversation Summarization: For very long conversations, you might use the AI itself to periodically generate summaries of the conversation that can be included instead of all previous messages.
Implementing Multi-Turn Dialogue Workflow
The complete workflow for handling a conversation turn in your Bubble application should include these steps:
1. User Message Creation:
- Save the user's message to your database with role="user"
- Link it to the current conversation thread
2. Message History Retrieval:
- Search for messages in the current thread
- Sort by creation date (ascending)
- Optionally limit to most recent N messages
3. API Request Preparation:
- Format messages as JSON using "Format as Text"
- Make content JSON-safe
- Add any system prompts or instructions
4. API Call:
- Send the formatted messages to OpenAI/Claude
- Include your API key and other required parameters
5. Response Handling:
- Save the AI's response to your database with role="assistant"
- Link it to the same conversation thread
- Display the response to the user
Best Practices for Message History Management
To ensure your AI application works effectively while maintaining performance:
1. Implement Privacy Rules: Ensure users can only see their own conversations by setting up proper privacy rules in your Bubble database.
2. Consider Caching: For frequently accessed conversations, consider caching techniques to improve performance.
3. Monitor Token Usage: Keep track of token usage to optimize costs and prevent hitting limits.
4. Handle Errors Gracefully: Implement error handling for cases where token limits are exceeded or API calls fail.
5. Provide Thread Management: Allow users to start new conversations or continue existing ones.
6. Clean Up Old Data: Implement a system to archive or delete very old conversations to maintain database performance.
Conclusion
Implementing message history tracking in your Bubble.io AI application is crucial for creating contextual, multi-turn conversations. With the right database structure, proper message formatting, and thoughtful context management, you can build sophisticated AI applications that maintain coherent conversations over time.
By following these best practices, your no-code AI application can provide a user experience similar to commercial AI assistants like ChatGPT or Claude, all without writing a single line of code. The key is understanding how to structure your data and workflows to maintain that all-important conversation context across multiple interactions.
Learn more with Bubble tutorials

Bubble & OpenAI - Send only recent messages

Build a Claude 3 AI No Code App in 15 mins

The Best Designed ChatGPT Clone in Bubble.io: Build It With No Code!
Hi, I'm Matt 👋
My Journey
- Discovered Bubble.io in 2017 while working as a WordPress web designer.
- Transitioned into a full-time Bubble coach and tutor with over 7 years of experience.
Achievements
- Helped hundreds of students turn their app ideas into reality.
- Over 36,000 YouTube subscribers and 1,100,000+ views on tutorial videos.
Why Learn from me
- Real-World Experience: Built internal tools, side projects, and collaborated with entrepreneurs using Bubble.io.
- Proven Success: Students have launched successful apps, some even selling their creations.
- Passionate Educator: Committed to your success and eager to share hard-won insights and strategies.

The best way to learn Bubble.io?
Build No Code Confidently
No more delays. With 30+ hours of expert content, you’ll have the insights needed to build effectively.
Find every solution in one place
No more searching across platforms for tutorials. Our bundle has everything you need, with 500+ videos covering every feature and technique.
Dive deep into every detail
Get beyond the basics with comprehensive, in-depth courses & no code tutorials that empower you to create a feature-rich, professional app.
Frequently Asked Questions
Find answers to common questions about our courses, tutorials & content.
No. Our Beginner Essentials course and AI No-Code Coach are designed for total newcomers. You’ll learn Bubble.io step by step - no coding required.
Simply type your question in plain English, and our AI taps into the entire video library to recommend the exact lessons you need. It’s like having a personal instructor on demand.
As long as you’re subscribed! With our monthly subscription, you get unlimited access to all 500+ videos, our growing course library, and the AI No-Code Coach.
Your subscription includes:
- Bubble Beginner Essentials – Get up and running fast.
- Build a ChatGPT Clone – Integrate AI into your no-code apps.
- Build Your SaaS Website with AI – Learn to create a scalable startup site.
- Develop a Custom CRM App in Bubble - Learn database relationships with a CRM.
Plus, new tutorials every week!
The AI No-Code Coach is your first stop for instant answers. If you need deeper help, you can book 1:1 Bubble coaching for expert guidance.
Yes! If you don’t see real progress within 14 days, let us know, and we’ll issue a full refund—no questions asked.
Absolutely. Your subscription is month-to-month, and you can cancel anytime—no lock-ins, no hidden fees.
Absolutely. Your subscription is month-to-month, and you can cancel anytime—no lock-ins, no hidden fees.
If you’re serious about building a successful SaaS startup, check out Mastery—our intensive mentorship program. Mastery goes beyond Bubble.io development and includes:
- 1:1 mentorship to fast-track your progress
- Marketing strategies tailored for no-code founders
- Product management insights to scale your startup
- Personalized support from experienced founders