1. Getting Your API Key

Sign up at platform.openai.com, navigate to API Keys, and create a new secret key. Store it securely—you won't be able to see it again. Set up billing to enable API access beyond the free trial.

2. Making Your First Request

The Chat Completions endpoint is the most commonly used. Send a POST request with your messages array and receive the model's response.

python
from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is automation?"}
    ]
)

print(response.choices[0].message.content)

3. Understanding the Response

The response includes the generated text, token usage (for billing), and metadata. Pay attention to finish_reason—it tells you if the response was complete or cut off by token limits.

Wrap-up

You're now ready to integrate AI into your applications. Explore parameters like temperature (creativity) and max_tokens (response length) to fine-tune outputs.