Use this repo as a template to deploy a Python FastAPI service on Render that includes OpenAI endpoints.
📌 Includes two endpoints: /prompt
and /prompt/stream
📡 /prompt/stream
streams responses from OpenAI → FastAPI → Client
🚀 Deploy with one click
✅ Includes Pytest - Modify tests in test_main.py
and run tests with the command pytest
Clone or fork repository
git clone https://github.com/waseemhnyc/fastapi-openai-render.git
Create a virutalenv and source the environment
python3 -m venv venv
source venv/bin/activate
Install the necessary libraries
pip install -r requirements.txt
Create a .env file and input your OpenAI API Key in the file
cp .env.example .env
Run local server
uvicorn main:app --host 0.0.0.0
pytest
-
You may use this repository directly or create your own repository from this template if you'd like to customize the code.
-
Create a new Web Service on Render.
-
Specify the URL to your new repository or this repository.
-
Render will automatically detect that you are deploying a Python service and use
pip
to download the dependencies. -
Specify the following as the Start Command.
uvicorn main:app --host 0.0.0.0 --port $PORT
-
Add
OPENAI_API_KEY
as an environment variable. -
Click Create Web Service.
Question: How can I customize the Click to Deploy
button to point to my forked repository?
By updating the URL to your forked repository in this README file.
Question: How can I change the name of my web service?
You can change the name of your web service by modifying the `name` key in the `render.yaml` file.
- type: web
name: your-custom-service-name
runtime: python