Lab 2.1 – sending your first OpenAI API request using the openai Python package
With the installed Python package and the API Keys, we are all set to execute our first OpenAI API request. Note that you do not need OpenAI platform credits to complete this lab, and we will instruct you how to load credits to your account later in this chapter. If you have previously loaded credits to the OpenAI platform, this example should cost no more than a fraction of a cent to execute.
In this lab, we will start with a simple template for executing OpenAI API requests to the Chat service and printing the response output. We will have three steps:
- Create an
openai.OpenAIclass instance. - Submit a request to the Chat service with a single user prompt and a model selection such as GPT-4o-mini or GPT-3.5-turbo.
- Print the response output.
These steps are in place in our starter code, and we will walk you through completing it, running it, and analyzing the results...