[F/OS] 🧠 Artificial Intelligence and OpenAI!

:computer: Introduction

Do you want to chat with AI? Generate an image from your command? Well, this is the extension for you!

This is an extension that allows you to integrate OpenAI and GPT-3 with AppInventor. You can ask OpenAI questions, chat with it, and even generate images!

:chart_with_upwards_trend: Stats

:hammer_and_wrench: Built with: Extension Template

:calendar: Released on: 2023-01-14T16:00:00Z

:clock1: Version: 2

:books: Documentation

Method blocks



Chats with OpenAI. The prompt parameter specifies what the query/question is, such as “What color is the sky?” or even better questions.

  • The prompt parameter tells the extension the question that you want to ask.

  • OpenAI provides different “models” for you. Consider them as people you ask and chat in real life, they have different “personalities” and “opinions”. Their pricings differ, please check the Pricing page in the FAQ.

  • The apiKey parameter tells the extension the API key of your OpenAI account.

  • The maxTokens parameter limit the length of the answer that you will get. For example, in order to get an answer of around one or two sentences, set this as 250 to be safe. You may get a short or imcomplete answer if you set this too low. All free users can spend 150K tokens every minute.

  • Do you want an informative or a creative answer? If the informative parameter is false, the bot will give a creative response. This is useful for questions requiring imagination. Otherwise, if you are asking for facts, set this as true.

Parameters: prompt = text, apiKey = text, maxTokens = text, informative = boolean



Generates an image according to the prompt. The prompt tells the extension what the image is about, such as “Monkey holding a banana”. The apiKey tells the extension your OpenAI API key.

Parameters: prompt = text, apiKey = text

Event blocks



This event is fired when an error has occurred.

Parameters: error = text



This event is fired when the extension has generated an image! You can feed an Image component directly with this URL.

Parameters: imageURL = text



This event is fired when the extension has responded to your question. The tokensSpent parameter indicates how many tokens you have spent from your OpenAI account in order to ask this question.

Parameters: response = text, tokensSpent = number (int)

:inbox_tray: Downloads

com.gordonlu.openai.aix (114.2 KB)

OpenAIKodular.aia (173.8 KB)

:green_book: FAQ

Q1: Why is my answer incomplete? Is this a bug in the extension?

A1: No, this is not a bug. Try to increase your maxTokens parameter for this. The maxTokens parameter judges how long the response should be, and with lower tokens, you get shorter, or maybe incomplete, answers.

Q2: How do I obtain an API key?

A2: @Dayron_Miranda was generous enough to give us a few steps. Not all countries support OpenAI though, for example, we Chinese do not get to use OpenAI.

  1. Go to the OpenAI website (https://openai.com/).

  2. Click on the “Developers” button in the top right corner of the page.

  3. Click on the “API” button in the top right corner of the page.

  4. Click on the “Get API Key” button in the top right corner of the page.

  5. Fill in the required information and click on the “Create API Key” button.

  6. Once you have your API key, you can test GPT chat by using one of the many libraries or sample codes available on the OpenAI website, or by making a call to the API endpoint directly with the API key. In this instance, copy the API key for this extension to work.

Q3: Is there a quota for this?

A3: Yes, unfortunately. Please see Pricing for details.

Q4: Why do I get a “No value for choices” error?

A4: This is caused maybe because you include a special character. Do not use double quotes in your prompts ("), use single quotes (’). Also check if you completed the setup correctly.

Q5: Where is the source code?

A5: It’s in this repository in GitHub.

:white_check_mark: Compatibility

Verified on AppInventor and Kodular. This extension may (not) work on other derivatives, so stick to those two builders if you would like to use this extension.

:+1: Credits

Thanks again to @Xoma for guidance and help in creating the extension, also @Shreyash for his tutorials in creating the extension! (it’s here: Learn how to create extensions)

Also, special thanks to @Dayron_Miranda, who provided an API key for me to test this extension, and also participating in the beta-test program himself. Shoutout to him! Without his help, this extension would not be possible. (OpenAI is not supported in Hong Kong)

Thanks to @Hands_of_Change, @Didyme_Apps, @Alencar_Rodrigues and @Narongporn_Laosrisin for confirming that this extension is working in Kodular!

Please, if you like this extension or if you want to support me, click the beautiful :heart: Like button of this extension, this took two whole mornings and one whole afternoon to make, and I genuinely appreciate your kindness. Have a nice day!


Thank you for the great contribution…


Nice work :+1:
I’m releasing a simple GPT Chat App based on your Extension, I will credit you once is on Store.
Do you have any plan to integrate a block for increasing “temperature”?

Best :v:

1 Like

Thank you for your comments. Of course I do, in fact, I have already included it in the next release and I am refining the work.

1 Like

Thanks for the great contribution! Is there a way to limit gpt chat to only answering questions on a specific topic?

1 Like

Can you please update your extension to add Chat GPT api as well? Thanks


The official ChatGPT docs redirect me to the same website as GPT-3, and I’ve tried a lot of times before I posted this extension. So probably not; however if you can find a REST API that does this, do let me know.

1 Like

token means?

Please read the documentation, everything is explained.

i m not getting api .please help me

Would be helpful if you can elaborate your problem more specificly. Your question is too vague. :slight_smile:

  1. You cannot get an API key?
  1. You cannot access the OpenAI service in your country?

  2. You cannot obtain a copy of the OpenAI extension?

  3. You do not get a response? Post your blocks if so.

where is my personal account and where is log in /sign up ?

How about trying Product and try to click on Get Started?

i already tested the chatgpt api. can you add this on your extension so that it will be easier? i just want the response content to be easier to use like the one you made already. having troubles decoding coz i dont know this json and decoding thing much. but here is the api example for chat gpt.

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
     "model": "gpt-3.5-turbo",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7

I was almost done with the update (except for the helper blocks part, I had to figure out how to avoid using dots in helper blocks since they don’t work), but I ended up in the hospital because of respiratory infection for two weeks. I’m sorry.

Hospital sucks. I’ll post the extension once I recover and get back home.

1 Like

I am really sorry to hear this

Get well soon Koder!

and… this is how i use it currently

1 Like


Oh My God!!!

Sad to hear you that you were not well.

We will pray for you to get well soon dear @Gordon_Lu

1 Like

Hello everyone,

Just an update of what I’m doing.

:white_check_mark: Updated the Chat block to GPT 3.5 and GPT 4. You can choose from different 3.5 and 4 models.

:white_check_mark: Fixed the GenerateImage error!

:white_check_mark: Checked the EditText block, still working.

All I have to do is to add a moderation block that allows you to check if there are any issues with a piece of text, such as offensive language.

1 Like

Please make it support response streaming. stream=true parameter so that we don’t have to wait for full response.

im currently using web component but got.text event only seems to fire after complete response. idk why.

Well, this would be complicated as for each response, the RespondedToChat event should only be fired once. This wouldn’t work for some components, especially ChatView.

1 Like