5.ChatGPT Tutorial

Backend Setup

To make the LAFVIN ESP32S3 AIChatBot work properly, you need to register an OpenAI platform account and obtain an API key.

Warning

This project uses the OpenAI API, which is billed separately from ChatGPT subscriptions. You need an OpenAI account with paid API balance before you can create and use an API key. Pricing information is available at https://openai.com/api/pricing/.

Model Used in This Project

This project uses the gpt-realtime-mini model.

At the time of writing, the official pricing for this model is:

  • Input: $0.60 per 1M tokens

  • Output: $2.40 per 1M tokens

  • Cached input: $0.06 per 1M tokens

For the latest model details and pricing, see the official OpenAI model page: gpt-realtime-mini

1. Obtaining OpenAI API Key

  1. First, visit https://platform.openai.com/api-keys, then click the Create new secret key button

../_images/api1.png
  1. Select the Owner, Name, Project, and permissions as needed, and then click Create secret key.

../_images/api2.png
  1. After generation, copy this API key and save it in a secure and accessible place. For security reasons, you will not be able to view or copy this API key again after closing this page.

../_images/api3.png

Firmware Upload

Network and API Configuration

Note

The ESP32-S3 supports only 2.4 GHz Wi-Fi networks. In addition, the Wi-Fi network you choose must be able to access OpenAI’s servers.

After the firmware is flashed, press the RST button on the development board. The board will automatically restart and enter network configuration mode, displaying the configuration AP and password on the screen.

../_images/gpt_config1.png
  1. Connect your phone to the hotspot named ESP32_Config. You can manually enter http://192.168.4.1 in your browser to access the configuration interface.

../_images/gpt_config2.png
  1. Select your Wi-Fi network, enter the password, and fill in the API key. The network you use must be able to access OpenAI’s servers.

  2. The development board will automatically restart, connect to your Wi-Fi, and connect to the AI service. If it does not restart after 30 seconds, press the RST button again.

Common Setup Issues

If the device cannot complete the setup successfully, check the following common issues.

API Key Error

If the API key is invalid, missing, or entered incorrectly, the device will display an API key error message on the screen.

../_images/gpt_error1.png

Please check the following:

  1. Make sure the API key was copied completely.

  2. Make sure there are no extra spaces before or after the API key.

  3. Make sure the API key is still valid and has not been deleted.

Cannot Connect to OpenAI

If the Wi-Fi network cannot reach OpenAI’s servers, the device will display a network connection error on the screen.

../_images/gpt_error2.png

Please check the following:

  1. Make sure your Wi-Fi network can access OpenAI’s servers.

  2. Try another Wi-Fi network if the current one blocks or restricts access.

  3. Restart the device after confirming that the network is working properly.

Re-enter AP Configuration Mode

If the Wi-Fi settings or API key are entered incorrectly, you can use the following steps to enter AP configuration mode again:

  1. Open the online flasher and connect to the device by following the steps above.

  2. After the connection is successful, click Serial Monitor.

  3. Enter reset_config in the input box.

  4. After the command is sent, the device will restart and re-enter AP configuration mode.

../_images/gpt_resetconfig.png

Tip: If you want to adjust the volume, double-click the UP or DOWN button at the bottom of the expansion board. The volume will increase or decrease in 10% steps, and the change will be shown on the display.

../_images/gpt_volume.png

At this point, the basic configuration of the ChatGPT firmware is complete. You can now start talking with the device and experience the intelligent interaction powered by ChatGPT.

../_images/gpt_chat.png

For flashing help, driver troubleshooting, or alternative flashing methods, see Online Flasher.