# Using Open AI Chat GPT API

**URL:** <https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672>\
**Category:** Need help\
**Created:** [March 2, 2023, 1:19pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672 "2023-03-02T13:19:56Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![freddybobjones](https://avatars.discourse-cdn.com/v4/letter/f/b5a626/32.png) [@freddybobjones](https://forum.bubble.io/u/freddybobjones)\
**Post date:** [March 2, 2023, 1:19pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/1 "2023-03-02T13:19:56Z")

</div>

Hi - has anyone had a chance to use the new Chat GTP API in their bubble app yet? If so, grateful for any tips on how to get it going. I’m using the GPT3 Model Davinci at the moment in my app. It’s performed great to date but would like to migrate over to Chat GPT 3.5 turbo as soon as possible.

---

<div class="post-metadata">

**Author:** ![Eugene\_West](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/eugene_west/32/106508_2.png) [@Eugene\_West](https://forum.bubble.io/u/Eugene_West)\
**Post date:** [March 2, 2023, 2:31pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/2 "2023-03-02T14:31:31Z")

</div>

What is the problem? Works like a text completion, just another api request,mm

---

<div class="post-metadata">

**Author:** ![freddybobjones](https://avatars.discourse-cdn.com/v4/letter/f/b5a626/32.png) [@freddybobjones](https://forum.bubble.io/u/freddybobjones)\
**Post date:** [March 2, 2023, 2:43pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/3 "2023-03-02T14:43:50Z")

</div>

Thanks Eugene - i’ve tried running the request but it’s not working for some reason. Was hoping to get some screen grabs from some who has been able to get it going using the API connector.

---

<div class="post-metadata">

**Author:** ![Eugene\_West](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/eugene_west/32/106508_2.png) [@Eugene\_West](https://forum.bubble.io/u/Eugene_West)\
**Post date:** [March 2, 2023, 4:48pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/4 "2023-03-02T16:48:46Z")

</div>

See my API Connector in the plugin tab and jump to GTP-3.5 call (gpt-3.5)

Editor link: [Bubble-solutions | Bubble Editor](https://bubble.io/page?type=page&name=openai&id=bubble-solutions&tab=tabs-5)

Dont forget to set your API key : Bearer sk-JqKBREA8b4 …

 ![Screenshot 2023-03-02 at 19.47.20](https://us1.discourse-cdn.com/bubble/original/3X/2/8/28b4d393b6c9cbcbc69a9829d05be1d8b062d0b1.png)

---

<div class="post-metadata">

**Author:** ![Eugene\_West](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/eugene_west/32/106508_2.png) [@Eugene\_West](https://forum.bubble.io/u/Eugene_West)\
**Post date:** [March 2, 2023, 4:50pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/5 "2023-03-02T16:50:50Z")

</div>

Result:

 ![Screenshot 2023-03-02 at 19.50.22](https://us1.discourse-cdn.com/bubble/original/3X/6/d/6dbf67b578efaa8297275a4a9b5a3ee4fb50f6c5.png)

---

<div class="post-metadata">

**Author:** ![will.nft.works](https://avatars.discourse-cdn.com/v4/letter/w/3bc359/32.png) [@will.nft.works](https://forum.bubble.io/u/will.nft.works)\
**Post date:** [March 2, 2023, 5:11pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/6 "2023-03-02T17:11:07Z")

</div>

Video: [Bubble.io - OpenAI GPT-3.5-turbo & GPT-3.5-turbo-0301 API Tutorial - YouTube](https://www.youtube.com/watch?v=fcfbpH5ghSQ)

New endpoint: [https://api.openai.com/v1/chat/completions](https://api.openai.com/v1/chat/completions)

When saving to custom state: Body Choice First Item’s Message Content

They added messages so it is no longer choice text

---

<div class="post-metadata">

**Author:** ![buildingsomething](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@buildingsomething](https://forum.bubble.io/u/buildingsomething)\
**Post date:** [March 2, 2023, 9:42pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/7 "2023-03-02T21:42:40Z")

</div>

Amazing thanks! Have you managed to get the stream function working via Bubble?

> **[OpenAI API](https://platform.openai.com/docs/api-reference/chat/create#chat/create-stream)**
>
> An API for accessing new AI models developed by OpenAI

---

<div class="post-metadata">

**Author:** ![will.nft.works](https://avatars.discourse-cdn.com/v4/letter/w/3bc359/32.png) [@will.nft.works](https://forum.bubble.io/u/will.nft.works)\
**Post date:** [March 2, 2023, 10:22pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/8 "2023-03-02T22:22:44Z")

</div>

I haven’t had a chance to look at that, yet. Sorry

---

<div class="post-metadata">

**Author:** ![Eugene\_West](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/eugene_west/32/106508_2.png) [@Eugene\_West](https://forum.bubble.io/u/Eugene_West)\
**Post date:** [March 3, 2023, 12:39am UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/9 "2023-03-03T00:39:03Z")

</div>

Not yet, but sounds interesting. I’ll see later today

---

<div class="post-metadata">

**Author:** ![buildingsomething](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@buildingsomething](https://forum.bubble.io/u/buildingsomething)\
**Post date:** [March 3, 2023, 4:37pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/10 "2023-03-03T16:37:30Z")

</div>

Anyone else having trouble adding previous chats to the ChatGPT API call?

I’m pasting in the previous answers as part of the array of responses and it works fine unless the previous AI response includes anything like quotation marks etc when I get this error:

![image](https://us1.discourse-cdn.com/bubble/original/3X/8/f/8f007c98ef15d44ea56f10d5048bf3412ebdf226.png)

---

<div class="post-metadata">

**Author:** ![Buddha](https://avatars.discourse-cdn.com/v4/letter/b/a9a28c/32.png) [@Buddha](https://forum.bubble.io/u/Buddha)\
**Post date:** [March 3, 2023, 6:11pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/11 "2023-03-03T18:11:01Z")

</div>

This is because of how JSON works. An unescaped quotes within the call will break it.

Use find and replace to escape the quotes.

Here’s how I did it for user inputs sent to the OpenAI completion endpoint…

![Screenshot 2023-03-03 at 7.09.02 PM](https://us1.discourse-cdn.com/bubble/original/3X/e/9/e98e063aac71150921845face66355ffd6f52f3c.png)

 ![Screenshot 2023-03-03 at 7.08.52 PM](https://us1.discourse-cdn.com/bubble/original/3X/d/d/dd64aceaa26f74a94a2133bb06a008b3cef86631.png)

---

<div class="post-metadata">

**Author:** ![buildingsomething](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@buildingsomething](https://forum.bubble.io/u/buildingsomething)\
**Post date:** [March 3, 2023, 7:34pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/12 "2023-03-03T19:34:58Z")

</div>

Amazing, thanks!

Have you managed to get the stream function working via Bubble?

> **[OpenAI API](https://platform.openai.com/docs/api-reference/chat/create#chat/create-stream)**
>
> An API for accessing new AI models developed by OpenAI

---

<div class="post-metadata">

**Author:** ![Buddha](https://avatars.discourse-cdn.com/v4/letter/b/a9a28c/32.png) [@Buddha](https://forum.bubble.io/u/Buddha)\
**Post date:** [March 3, 2023, 8:48pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/13 "2023-03-03T20:48:04Z")

</div>

Not yet.

Was able to initialize and receive the streamed data in the API Connector. Didn’t receive the complete data when called from a workflow.

So will leave it for another day.

---

<div class="post-metadata">

**Author:** ![buildingsomething](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@buildingsomething](https://forum.bubble.io/u/buildingsomething)\
**Post date:** [March 3, 2023, 9:35pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/14 "2023-03-03T21:35:01Z")

</div>

Not sure if this helps: [How to stream response in javascript? - #4 by asabet - General API discussion - OpenAI API Community Forum](https://community.openai.com/t/how-to-stream-response-in-javascript/7310/4)

---

<div class="post-metadata">

**Author:** ![stevenrichardlevy](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@stevenrichardlevy](https://forum.bubble.io/u/stevenrichardlevy)\
**Post date:** [March 8, 2023, 8:24am UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/15 "2023-03-08T08:24:34Z")

</div>

Has anyone worked out how to feed in the message history (prompt and response) so they model can reference things from earlier in the conversation?

I’m not sure how to set this up in the API connector. Seems like you want to store the history to a variable and then feed it back into the POST request each time you ask a question but not sure how this would work.

 ![Screenshot 2023-03-08 at 15.21.42](https://us1.discourse-cdn.com/bubble/original/3X/4/e/4ecd7fe87e1a16d32840cffd5cdd9c996b03d115.png)

---

<div class="post-metadata">

**Author:** ![stevenrichardlevy](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@stevenrichardlevy](https://forum.bubble.io/u/stevenrichardlevy)\
**Post date:** [March 8, 2023, 2:52pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/16 "2023-03-08T14:52:33Z")

</div>

For anyone who stumbles on this. Here is a very inelegant solution which can certainly be tidied up but has the required functionality

I am a bit lazy to type it up but hopefully the screenshots should help but if there are any questions just ping the thread.

 ![Screenshot 2023-03-08 at 21.44.13](https://us1.discourse-cdn.com/bubble/original/3X/c/1/c1c9edd0202ef8f70e8bbd911971585b3086226f.png)

 ![Screenshot 2023-03-08 at 21.45.46](https://us1.discourse-cdn.com/bubble/original/3X/4/6/46f3c3e1a8ec4ef2666ef9014ed0463bc31ec48c.png)  
 ![Screenshot 2023-03-08 at 21.46.00](https://us1.discourse-cdn.com/bubble/original/3X/a/9/a9b69d9435f39a9ed403d255b4d34bdac5ef4303.png)

---

<div class="post-metadata">

**Author:** ![cmarchan](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/cmarchan/32/253062_2.png) [@cmarchan](https://forum.bubble.io/u/cmarchan)\
**Post date:** [March 8, 2023, 4:43pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/17 "2023-03-08T16:43:55Z")

</div>

Emulating @stevenrichardlevy spirit of sharing I would also like to share this comment on another AI thread in the forum that is about building expanded AI functionality into a Bubble app

> [@OpenAI GPT Streaming Functionality](http://forum.bubble.io/t/openai-gpt-streaming-functionality/250645/10):
>
> @Stackapp Second @keith comments as calling OpenAI’s endpoints is very straightforward. The OpenAI API endpoints have a capacity number of tokens of 4096. Think of this as a means to see a big universe through a telescope., The 4096 tokens are what the telescope allows us to be able to access the more than hundreds of thousands of tokens that their LLMs (large languagee models) currently handle. The arquitecture to build a memory to an AI app that is built conventionally or in any other way ……

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [May 11, 2023, 1:20pm UTC](https://forum.bubble.io/t/using-open-ai-chat-gpt-api/249672/19 "2023-05-11T13:20:53Z")

</div>

This topic was automatically closed after 70 days. New replies are no longer allowed.
