Skip to content
Projects

openai/openai-quickstart-python

View on GitHub

openai/openai-quickstart-python has 1,831 GitHub stars and 1,352 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-08 01:12 UTC. Last push 2024-06-14.

How these counts are measured

Python example app from the OpenAI API quickstart tutorial

Measured star growth

in 24h
0
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

OpenAI API Quickstart - Python

This repository hosts multiple quickstart apps for different OpenAI API endpoints (chat, assistants, etc). Check out the examples folder to try out different examples and get started using the OpenAI API.

Basic request

To send your first API request with the OpenAI Python SDK, make sure you have the right dependencies installed and then run the following code:

from openai import OpenAI
client = OpenAI()

completion = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message)

Setup

  1. If you don’t have Python installed, install it from Python.org.

  2. Clone this repository.

  3. Navigate into the project directory:

    $ cd openai-quickstart-python
    
  4. Create a new virtual environment:

    • macOS:

      $ python -m venv venv
      $ . venv/bin/activate
      
    • Windows:

      > python -m venv venv
      > .\venv\Scripts\activate
      
  5. Install the requirements:

    $ pip install -r requirements.txt
    
  6. Make a copy of the example environment variables file:

    $ cp .env.example .env
    
  7. Add your API key to the newly created .env file.

  8. Run the app:

This step depends on the app itself. If the code uses flask (like the chat-basic example), you can run:

$ flask run

You should now be able to access the app from your browser at the following URL: http://localhost:5000!

If the code is just a simple Python script, you can run it with:

$ python my_file.py

Explore related projects