Curious what it’s like to build your own AI chatbot using Flutter? In this article, we will walk you through the process of building a simple chatbot. We’ll be using OpenAI models with code snippets included. We will focus on using OpenAI’s Text Completion API. Also we’ll demonstrate how to create a basic chatbot that can respond to user prompts. We’ll also discuss some considerations when selecting the best platform client for OpenAI. And how to set up the OpenAI token needed to access the API. Whether you are a beginner or an experienced developer, this article will provide you with valuable insights into creating a chatbot that can be expanded for many different use cases in the future. So, here we go! Artificial Intelligence application in chats: what it takes.

Simple Chatbot 

We used Flutter to create our own AI chatbot. Here’s how it was done. To create a demo application that will show the capabilities of OpenAI models, it is primarily needed to decide how it will be used: using the REST API directly or via platform client. 

A quick glance on available Flutter clients for OpenAI indicates that there are plenty of available options. However, many of them are not updating recently and, taking into account one of the most influential open source packages’ disadvantages, they might be discontinued. It is fair enough to use the top-most relevant variant. It might be quite raw, but it has a good popularity and it has already started gaining likes on

Flutter clients for OpenAI

To create an object, that will be used to access OpenAI’s API it is necessary to specify OpenAI Token (may be obtained in OpenAI Dashboard via this link):

This will create an instance of the class that represents a client connection to the OpenAI API, that has the following accessible resources:

a client connection to the OpenAI API

Artificial Intelligence Application in Chats. OpenAI Text Completion API

Since we are only interested in showing basic text processing examples in the scope of the current article, let’s focus on OpenAI Text Completion API, which is present in our client connection object as `completions` getter.

Once you open the documentation, you will notice that a simple enough API, that should return a text completion given the user’s input, is complex enough to have 10+ parameters!

Luckily, it is possible to start this endpoint’s usage with all default parameters except the `maxTokens` – a parameter that restricts a maximum response length in so-called “tokens”. OpenAI models use the concept of a token as a sequence of characters. It is possible to check the text for a length in tokens using OpenAI’s Tokenizer

To get a response for a simple text user prompt, it is needed to call the only one available method `create` on `completions` object:

method `create`

It is possible to design a simple variant of a chatbot. Given the ability to respond in a human-like manner to the custom user prompt. To cover an explanatory gap on different OpenAI text models, let’s develop an application. And expand it for many different use cases in future. The cases will be simple enough to reply to users prompt using OpenAI Text Completions.

Omitting boilerplate localization setup, dependency injection configuration, decidement for an app architecture and picking a proper Git VCS hosting, here is a short demonstration of a simple chat between the user and the OpenAI Text Completion about planning weekly ration:

The source code is available in openai_gadget repository on GitHub: 


Building a simple chatbot using OpenAI models and Flutter is a great way to demonstrate the capabilities of AI. As well as its potential applications. Besides,  developers can create a chatbot that can respond to user prompts in a human-like manner. All they need is the OpenAI Text Completion API. This article provided a step-by-step guide on how to create a simple chatbot using Flutter and OpenAI. Starting from creating an object to access OpenAI’s API to designing a chatbot that can respond to users’ prompt. While this chatbot may be simple, many different use cases in the future will expand. As AI technology continues to evolve, we can expect more advanced chatbots. Those that will perform more complex tasks and provide better user experience. Finally, for a complete guide on this ChatGPT check out this article: A Complete Guide on ChatGPT from OpenAI


Created by Mykhailo Temnokhud