This repository demonstrates:
- How to connect to OpenAI APIs using Python.
- How REST APIs work with JSON payloads.
- How to send and receive JSON responses.
- Python 3.8+
- OpenAI API key (from https://platform.openai.com)
requestslibrary
-
Clone the repo:
git clone https://github.com/genzerstech/openai-rest-api-demo.git
cd openai-rest-api-demo -
Install dependencies:
pip install -r requirements.txt -
Create a .env file:
OPENAI_API_KEY=your_api_key_here
Run the demo: python app.py
Example REST Payload { "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Write a haiku about AI"}] }
Expected Output { "role": "assistant", "content": "Neural minds awake\nPatterns dance through endless streams\nMachine dreams unfold" }