A FastAPI port of openai/openai-quickstart-python. Check out the examples folder to try them out.
| Example | What it shows |
|---|---|
examples/pet-name |
A form that generates superhero pet names, using the Responses API |
examples/chat |
A multi-turn chat that streams tokens as they arrive, using Chat Completions |
-
If you don’t have Python installed, install it from Python.org.
-
Clone this repository.
-
Navigate into the project directory:
$ cd openai-quickstart-fastapi -
Create a new virtual environment:
-
macOS / Linux:
$ python -m venv venv $ . venv/bin/activate -
Windows:
> python -m venv venv > .\venv\Scripts\activate
-
-
Install the requirements:
$ pip install -r requirements.txt
-
Make a copy of the example environment variables file:
$ cp .env.example .env
-
Add your API key to the newly created
.envfile. -
Run an example:
$ cd examples/pet-name $ fastapi dev app.py
You should now be able to access the app from your browser at http://localhost:8000!
Steps 4 and 5 with uv instead:
$ uv venv
$ uv pip install -r requirements.txtBoth examples read OPENAI_MODEL, so you can try another model without editing
the code:
$ OPENAI_MODEL=gpt-5-mini fastapi dev app.pyThe SDK also reads OPENAI_BASE_URL, which lets the chat example run against
any OpenAI-compatible endpoint. Note that the pet name example uses the
Responses API, which fewer providers implement.
Builds the pet name example:
$ docker build -t openai-quickstart-fastapi .
$ docker run -e OPENAI_API_KEY=<your-api-key> -p 8000:8000 openai-quickstart-fastapi