Learn Bubble with 500+ tutorials, courses & AI Assistant ✨

Limited time launch offer get $80 off today

0 days 0 hours 0 minutes 0 seconds
SAVE $80 NOW
Planet No Code logo
Bubble.io CoachingFounder MentoringSponsorships
LoginLearn Bubble.io

Bubble & OpenAI - Send only recent messages

In this Bubble tutorial we demonstrate how you can lower your OpenAI token spend by just sending the most recent messages to the OpenAI API. This method will ensure your message still has some awareness of previous messages without sending the oldest messages.

Join now $19/monthLearn more
Get 500+ tutorials, a No-Code AI Assistant, 4 premium courses, and everything you need to build faster!
Bubble & OpenAI - Send only recent messages
Explore these topics...
Database
Plugins
OpenAI

With just this tutorial learn...

Limit OpenAI messages: Learn the secret to optimizing your OpenAI conversations in Bubble!

Master Bubble workflows: Discover how to send only the most recent messages and avoid token limits with this workflow hack.

Boost your AI chat app: Unlock the power of context-aware conversations while keeping your OpenAI requests efficient.

With membership you'll...

Learn how to build a ChatGPT Clone, Custom CRM for your business & SaaS Marketing website with Webflow & AI.

Unlock 500+ Bubble tutorial videos with AI powered Q&A.

Debug your Bubble app instantly with our custom trained No Code AI Assistant.

Join now $19/month
Risk-free! 14-day money-back guarantee. Cancel anytime.

Limiting Messages Sent to OpenAI API

Thank you to everyone who has subscribed, liked and commented on the video. It really helps our YouTube channel and us to continue to create fantastic content around Bubble and low-code development. One of the comments we received was asking a question about OpenAI and Bubble and that is how can I limit the number of messages that I send through to the OpenAI API? And that's because even if you increase the token limit to say the 16k models, you will eventually get to a point where the conversation with your user exceeds the number of tokens that you can send back over to OpenAI because remember the OpenAI requires you to send all of the history of all of the messages of that conversation in order for it to be aware of what's been said in previous messages.

Implementing a Message Limit

I'm going to show you how very quickly you could limit it to say the last 10 messages so that there is still some contextual historical awareness in the conversation, but you're not sending 60 messages. You're only sending 10. So I'm going to adapt this workflow here. This is one that I've demoed in plenty of other OpenAI videos. If you're not sure how to get to this point go and check those ones out. But I basically create a message that's the one that the user has created. I then send all of the messages that have been between the user and the AI. I then reset the inputs and I create a new message. That's the AI's response. This is the box I'm going to change. I'm going to set it to only send the last 10 messages.

Sorting Messages by Date

I'll go back to just search for messages. If you were to constrain them by add a constraint by conversation, you would have that in here. But I'm going to do something such as created date descending yes. What this will do is this will put the most recent message first. This is the wrong way around for OpenAI. OpenAI is expecting like any other chat application for the oldest to be up top and then for it to get newer as the conversation goes down to the bottom. So the last message should be the most recent.

Using Items Until for Message Limit

I'm flipping it around and that's because of a limitation that Bubble gives us here which it gives us items until and items from. The items from is only going to be useful in our calculation of the last 10 if we're keeping a count of how many messages there are. So if there have been 40 messages, we need to know there's been 40 messages to take 10 from that leaving us with 30 and then we could say items from 30. Now you could keep some sort of running count in your app. Maybe you could keep a count on the conversation. In that case, yeah, you could make it work. But you could also just use what I'm about to show you with items until. So I'm going to say items until 10.

Reversing the Order for OpenAI

And so what that will do is it's going to start with the most recent message and it will then show the previous 10. So message one is the most recent. Message two is the one before that all the way through to message 10 which will be the oldest message but of that most recent block of 10. It's still the wrong way around for OpenAI. So then what I can do is I can say sort. So now that I've got this operator of getting the most recent 10 messages, they're in the wrong order. So now I've put them back in the right order which is created date descending note. So now they're again in the right chronological order for OpenAI.

Formatting Messages as JSON

And then I can add in my format as text and this is how I get my JSON expression. And to do that I'm just going to pop into the OpenAI documentation and copy this part here. The delimiter that's the computer science term for what you put in between. So that's going to be a comma and a space and then roll. I simply need to put I'm not sure in this demo if I have this set up. Basically this message. This message roll. There we go. So that's again if it's system assistant or user and then the context. Remember I'm making this all JSON safe. We don't want to be getting those error 400s because the syntax issues with our JSON.

Finalizing the Message Format

So I'm going to get rid of all of that. And the context is this content is this message is text JSON safe. So remember we format it like this because JSON safe encloses the content in speech marks. And also it will escape it will make safe any characters in the content that the user has typed in that could cause the syntax error JSON safe. So set for us. So. Yeah they have it. That's how to send the most recent 10 messages. You reverse the order get the first 10 reverse the order back and then format as text.

Conclusion and Call to Action

And if you find this video useful and you're learning Bubble you need to check out our website planetnocode.com. We've got hundreds of Bubble tutorial videos at the moment we're releasing a new video basically every day of the week. Our library is growing and growing and growing and we've got so much that we love to teach you about building a Bubble and many of those videos are exclusive to our members. And you can find out more at planetnocode.com.

Table of contents

Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Your No-Code Journey Starts Here

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.

Monthly
Yearly
Member
Accelerate your Bubble app to launch
$99 / month
$19/month/mo
Includes:
500+ tutorials
4 premium courses
Find the right tutorial with our custom trained AI
New tutorials added each week
Cancel anytime
14 day money back
Join now
Member
Accelerate your Bubble app to launch
$990 / year
$149/year/mo
Includes:
500+ tutorials
4 premium courses
Find the right tutorial with our custom trained AI
New tutorials added each week
Cancel anytime
14 day money back
Join now

Frequently Asked Questions

Find answers to common questions about our courses, tutorials & content.

Do I need any coding experience?

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.

How does the AI No-Code Coach work?

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.

How long can I access the content?

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.

What courses are included

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!

What if I get stuck on a lesson?

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.

Do you offer a money-back guarantee?

Yes! If you don’t see real progress within 14 days, let us know, and we’ll issue a full refund—no questions asked.

Can I cancel anytime?

Absolutely. Your subscription is month-to-month, and you can cancel anytime—no lock-ins, no hidden fees.

What if I want more than just tutorials & courses?

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:1 mentorship to fast-track your progress
  2. Marketing strategies tailored for no-code founders‍
  3. Product management insights to scale your startup‍
  4. Personalized support from experienced founders

‍

Still have questions?

Reach out to our dedicated team.

Contact
Services
Search Bubble TutorialsBubble.io CoursesBook Bubble.io CoachingApply for Mastery
Latest Bubble tutorials
Rerank Text By MEANING With Cohere In Bubble.io Step by Step!
Unlock RAG Providers for NO CODE AI App Development TODAY!
Better Tables with Built-in Search and Sort By in Bubble.io
Partnerships
Flusk.eu
VectorShift
Comnoco
Plumb
Toddle
Whereby
Get started with no code
AI Powered No Code AppsNo Code Web ScrapingBubble.io Plugin tutorialsBubble API Connector tutorialsStudent & Teacher DiscountBest tools for no coders
Follow us
Youtube
X
LinkedIn
Planet No Code logo
In partnership with
Queen Mary University of London Logo
© 2024 Planet No Code. All rights reserved.
Privacy PolicyTerms of ServiceCookies SettingsContact Us