Step 1: Environment Setup
- Install Python 3.10+ from python.org.
- Create OpenAI account at platform.openai.com and generate API key at platform.openai.com/api-keys.
- Export API key:
export OPENAI_API_KEY='sk-your-key' (or use .env).
- Install library:
pip install openai.
Test with:
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role': 'user', 'content': 'Hello!'}]
)
print(response.choices<citation data-id="0"></citation>.message.content)
Run python test.py to verify.