Skip to main content
Prerequisite You should have an API key from OpenAI and have it stored in a .env file.

Introduction

This guide demonstrates how to fetch and log company information using the OpenAI API. You’ll learn how to set up your environment, configure your API key, and make a request to the OpenAI API.
openai-hello-world.py

Setup

Step 1: Install Required Packages

First, install the necessary packages using pip:

Step 2: Create a .env File

Create a .env file in the project root with your OpenAI API key:

Fetching Company Information

Step 3: Create the Python Script

Create a Python script named openai-hello-world.py with the following content:
openai-hello-world.py

Step 4: Run the Script

Ensure you have the .env file in the same directory as the script. Then, execute the script:

Conclusion

You have successfully fetched and logged company information using the OpenAI API! This guide provided a basic example to get you started. You can now expand on this by customizing the request and handling different types of information.