Featured image for OpenAI API Tutorial: From Zero to Your First App (2026)
Tutorials ·
Beginner
· · 21 min read

OpenAI API Tutorial: From Zero to Your First App (2026)

Learn how to use the OpenAI API with Python step by step. Build your first AI app with GPT-5.2, understand pricing, and master best practices for 2026.

OpenAIAPI TutorialPythonGPT-5.2AI Development

I remember the first time I tried to use the OpenAI API. I had a ChatGPT Plus subscription, had been prompting for months, and thought “how hard could it be?” Turns out, there’s a bit more to it than just typing in a prompt.

That said, it’s significantly easier than most API integrations I’ve worked with. If you can write basic Python, you can build AI-powered apps today. And with GPT-5.2 now available, there’s never been a better time to start.

This tutorial will take you from “what’s an API key?” to actually building something useful. No prior API experience required, just basic Python knowledge and an OpenAI account with billing set up.

Let’s build something.

What You’ll Learn

By the end of this tutorial, you’ll be able to:

  • Set up your OpenAI API environment properly (and securely)
  • Make your first API call to GPT-5.2
  • Understand tokens, pricing, and how to manage costs
  • Build a simple but functional AI application
  • Handle errors like a pro
  • Follow best practices that’ll save you headaches later

We’ll be using Python because it’s the most popular language for AI development, but the concepts apply to any language with an OpenAI SDK.

Prerequisites

Before we start, make sure you have:

  1. Python 3.7+ installed on your machine
  2. An OpenAI account at platform.openai.com
  3. A payment method added to your OpenAI account (the API is pay-as-you-go)
  4. A text editor or IDE (VS Code, PyCharm, whatever you like)
  5. Basic Python knowledge (variables, functions, packages)

Don’t worry if you’ve never used an API before. I’ll explain everything as we go.

Step 1: Get Your API Key

First things first—you need an API key. This is like a password that identifies you to OpenAI’s servers.

Creating Your API Key

  1. Go to platform.openai.com
  2. Log in or create an account
  3. Click on your profile icon in the top right
  4. Select “View API keys”
  5. Click “Create new secret key”
  6. Give it a name (like “Tutorial Project”)
  7. Copy the key immediately—you won’t be able to see it again

Your API key looks something like this:

sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Store It Securely

Never, ever hardcode your API key in your code. I’ve seen too many developers accidentally push their keys to GitHub and wake up to a $500 bill from someone else using their account.

Instead, store it as an environment variable. Here’s how:

On Mac/Linux, add this to your ~/.bashrc or ~/.zshrc:

export OPENAI_API_KEY='sk-proj-your-key-here'

Then run source ~/.bashrc to load it.

On Windows, open PowerShell and run:

setx OPENAI_API_KEY "sk-proj-your-key-here"

You’ll need to restart your terminal for this to take effect.

Step 2: Set Up Your Python Environment

Let’s create a clean project folder and install what we need.

Create Your Project

mkdir openai-tutorial
cd openai-tutorial
python -m venv venv

Activate the Virtual Environment

Mac/Linux:

source venv/bin/activate

Windows:

venv\Scripts\activate

Install the OpenAI Package

pip install openai

As of January 2026, this installs version 1.x of the OpenAI Python library, which has a much cleaner interface than older versions. If you find tutorials from 2023 or earlier, the code will look different—stick with the patterns I show here.

Step 3: Your First API Call

Now for the exciting part. Let’s actually talk to GPT-5.2.

Create a file called hello_gpt.py:

from openai import OpenAI
import os

# The client automatically uses the OPENAI_API_KEY environment variable
client = OpenAI()

# Make a chat completion request
response = client.chat.completions.create(
    model="gpt-5.2",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What's the capital of France?"}
    ]
)

# Print the response
print(response.choices[0].message.content)

Run it:

python hello_gpt.py

If everything’s set up correctly, you’ll see something like:

The capital of France is Paris.

Congratulations! You just made your first API call. That’s genuinely it—the core of what you need to know. Everything else builds on this foundation.

Understanding the Response

Let’s unpack what we just received. The response object contains a lot of information:

# Print the full response to see what we get
print(response)

The key parts are:

FieldDescription
response.idUnique identifier for this completion
response.modelThe model that was used
response.choicesList of completion choices (usually 1)
response.choices[0].message.contentThe actual text response
response.choices[0].finish_reasonWhy the model stopped (stop, length, etc.)
response.usage.prompt_tokensTokens in your input
response.usage.completion_tokensTokens in the output
response.usage.total_tokensCombined token count

The usage information is particularly important for understanding costs—we’ll cover that shortly.

Step 4: Understanding the API Parameters

The chat.completions.create() method accepts several parameters. Here are the most important ones:

Model Selection

model="gpt-5.2"

As of January 2026, GPT-5.2 is the flagship model. Here are your options:

ModelBest ForInput Cost (per 1M tokens)Output Cost (per 1M tokens)
gpt-5.2Most tasks, balanced speed and quality$1.75$14.00
gpt-5.2-proMaximum intelligence, complex reasoning$21.00$168.00
gpt-5-miniSimple tasks, cost-sensitive applications$0.25$2.00

For tutorials and learning, gpt-5-mini is perfectly fine and much cheaper. For production apps, gpt-5.2 offers the best balance.

Messages Format

The messages array is where you provide context and user input:

messages=[
    {"role": "system", "content": "You are a helpful coding assistant."},
    {"role": "user", "content": "How do I read a file in Python?"},
    {"role": "assistant", "content": "Here's how you read a file..."},
    {"role": "user", "content": "What about writing to a file?"}
]

There are three roles:

  • system: Sets the behavior/persona of the assistant
  • user: Messages from the human
  • assistant: Previous responses from the AI (for context)

For multi-turn conversations, you include the entire conversation history. The model is stateless—it doesn’t remember previous requests.

Temperature

temperature=0.7

Controls randomness in responses:

  • 0.0: Deterministic, always picks the most likely tokens (good for factual tasks)
  • 0.7: Balanced creativity (default for most use cases)
  • 1.0+: More random, creative (good for brainstorming)

For code generation and factual questions, I typically use 0.0-0.3. For creative writing, 0.7-1.0. For a deep dive into these parameters, check our guide on temperature and top-p settings in AI.

Max Tokens

max_tokens=500

Limits the length of the response. If you don’t set this, the model will generate until it naturally stops or hits the model’s context limit.

One token is roughly 4 characters or 0.75 words. So 500 tokens ≈ 375 words.

Complete Example with All Parameters

from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-5.2",
    messages=[
        {
            "role": "system",
            "content": "You are an expert Python developer who gives concise, practical advice."
        },
        {
            "role": "user", 
            "content": "How do I handle exceptions properly in Python?"
        }
    ],
    temperature=0.3,      # Lower for more factual responses
    max_tokens=500,       # Limit response length
    top_p=1,              # Alternative to temperature (usually leave at 1)
    frequency_penalty=0,  # Reduce repetition (-2.0 to 2.0)
    presence_penalty=0    # Encourage new topics (-2.0 to 2.0)
)

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

Step 5: Understanding Tokens and Pricing

Tokens are how OpenAI measures and bills API usage. Understanding them is crucial for managing costs.

What’s a Token?

Roughly speaking:

  • 1 token ≈ 4 characters
  • 1 token ≈ 0.75 words
  • 100 tokens ≈ 75 words
  • 1,000 tokens ≈ 750 words

But it’s not exact—some words are multiple tokens, some tokens are partial words. The word “extraordinary” is 3 tokens. The word “the” is 1 token.

Current Pricing (January 2026)

ModelInput (per 1M tokens)Output (per 1M tokens)Cached Input (per 1M)
GPT-5.2$1.75$14.00$0.175
GPT-5.2 Pro$21.00$168.00
GPT-5 Mini$0.25$2.00$0.025

Note: Output tokens cost significantly more than input tokens. A response always costs more than the prompt that generated it.

Cost Example

Let’s say you’re building a chatbot:

  • Average prompt: 200 tokens
  • Average response: 300 tokens
  • Using GPT-5.2

Per message:

  • Input: 200 tokens × $1.75 / 1,000,000 = $0.00035
  • Output: 300 tokens × $14.00 / 1,000,000 = $0.0042
  • Total per message: ~$0.0046 (less than half a cent)

1,000 messages would cost about $4.60. That’s why I say “start building”—experimentation is cheap.

Checking Token Usage

You can see exactly how many tokens you used in the response:

print(f"Prompt tokens: {response.usage.prompt_tokens}")
print(f"Completion tokens: {response.usage.completion_tokens}")
print(f"Total tokens: {response.usage.total_tokens}")

Cost Optimization Tips

  1. Use the smallest model that works: GPT-5 Mini is 7x cheaper than GPT-5.2 and works fine for simple tasks
  2. Cache repeated queries: If users ask common questions, cache the responses
  3. Set max_tokens appropriately: Don’t let the model ramble if you only need a yes/no answer
  4. Trim conversation history: Don’t send 50 messages of context if the last 5 will do
  5. Use cached inputs: For repeated prompts with different queries, structure them to maximize cache hits

Step 6: Building a Real Application

Let’s build something more practical—a simple command-line assistant that remembers your conversation.

Create assistant.py:

from openai import OpenAI
import os

client = OpenAI()

def chat_with_gpt(conversation_history):
    """Send the conversation history and get a response."""
    response = client.chat.completions.create(
        model="gpt-5-mini",  # Using mini for cost savings
        messages=conversation_history,
        temperature=0.7,
        max_tokens=500
    )
    return response.choices[0].message.content

def main():
    print("🤖 AI Assistant (type 'quit' to exit)")
    print("-" * 40)
    
    # Initialize conversation with system message
    conversation = [
        {
            "role": "system",
            "content": "You are a friendly and helpful assistant. Be concise but thorough."
        }
    ]
    
    while True:
        # Get user input
        user_input = input("\nYou: ").strip()
        
        # Check for exit
        if user_input.lower() in ['quit', 'exit', 'bye']:
            print("\n👋 Goodbye!")
            break
        
        if not user_input:
            continue
        
        # Add user message to conversation
        conversation.append({
            "role": "user",
            "content": user_input
        })
        
        try:
            # Get AI response
            response = chat_with_gpt(conversation)
            
            # Add assistant response to conversation
            conversation.append({
                "role": "assistant",
                "content": response
            })
            
            print(f"\n🤖 Assistant: {response}")
            
        except Exception as e:
            print(f"\n❌ Error: {e}")
            # Remove the failed user message
            conversation.pop()

if __name__ == "__main__":
    main()

Run it:

python assistant.py

This gives you a working conversational AI that remembers context! Try asking follow-up questions like “tell me more about that” and it’ll remember what you were discussing.

How Conversation Memory Works

Notice how we append both user and assistant messages to the conversation list. Each API call sends the entire conversation history, which is how the model “remembers” context.

Here’s what the conversation array looks like after a few exchanges:

[
    {"role": "system", "content": "You are a friendly..."},
    {"role": "user", "content": "What's Python?"},
    {"role": "assistant", "content": "Python is a programming language..."},
    {"role": "user", "content": "What's it used for?"},
    {"role": "assistant", "content": "Python is used for web development..."}
]

Important caveat: This approach works but gets expensive for long conversations. Each message includes all previous messages in the token count. For production apps, you might want to summarize older messages or only include the most recent N exchanges.

Step 7: Error Handling

Things go wrong. Rate limits, network issues, invalid requests—your code needs to handle them gracefully.

Common Errors

ErrorCauseSolution
AuthenticationErrorInvalid or missing API keyCheck your key and environment variable
RateLimitErrorToo many requestsWait and retry with exponential backoff
InvalidRequestErrorBad parametersCheck your request format
APIConnectionErrorNetwork issuesRetry after a delay
APIError (500)OpenAI server issueWait and retry

Implementing Retry Logic

Here’s a robust function with proper error handling:

from openai import OpenAI
import time
import openai

client = OpenAI()

def make_api_call(messages, max_retries=3, initial_delay=1):
    """Make an API call with automatic retry logic."""
    
    for attempt in range(max_retries):
        try:
            response = client.chat.completions.create(
                model="gpt-5.2",
                messages=messages,
                temperature=0.7,
                max_tokens=500
            )
            return response.choices[0].message.content
            
        except openai.RateLimitError:
            if attempt < max_retries - 1:
                delay = initial_delay * (2 ** attempt)  # Exponential backoff
                print(f"Rate limited. Waiting {delay} seconds...")
                time.sleep(delay)
            else:
                raise
                
        except openai.APIConnectionError:
            if attempt < max_retries - 1:
                delay = initial_delay * (2 ** attempt)
                print(f"Connection error. Retrying in {delay} seconds...")
                time.sleep(delay)
            else:
                raise
                
        except openai.AuthenticationError:
            # Don't retry auth errors - they won't fix themselves
            print("Authentication failed. Check your API key.")
            raise
            
        except openai.BadRequestError as e:
            # Don't retry bad requests - need to fix the input
            print(f"Invalid request: {e}")
            raise

# Usage
messages = [
    {"role": "user", "content": "Hello!"}
]

try:
    response = make_api_call(messages)
    print(response)
except Exception as e:
    print(f"Failed after all retries: {e}")

The key insight here is exponential backoff—when you hit a rate limit, you wait 1 second, then 2, then 4. This gives the API time to recover without hammering it with requests.

Step 8: Best Practices for Production

If you’re building something that’ll see real users, here are the practices that’ll save you headaches:

Security

  1. Never expose your API key in client-side code, git repos, or logs
  2. Use environment variables or a secrets manager
  3. Rotate keys periodically and revoke compromised keys immediately
  4. Set spending limits in your OpenAI dashboard

Performance

  1. Use streaming for long responses so users see output immediately
  2. Cache common responses to reduce API calls
  3. Set appropriate timeouts (default can be 600 seconds—way too long for most UIs)
  4. Batch requests when possible for background processing

Cost Management

  1. Set up billing alerts in your OpenAI account
  2. Log all API usage to track costs per feature/user
  3. Use the cheapest model that works for each task
  4. Implement usage quotas per user if needed

Example: Streaming Responses

For better UX, stream long responses instead of waiting for the full completion:

from openai import OpenAI

client = OpenAI()

# Stream the response
stream = client.chat.completions.create(
    model="gpt-5.2",
    messages=[
        {"role": "user", "content": "Write a short poem about coding."}
    ],
    stream=True
)

# Print each chunk as it arrives
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

print()  # Newline at the end

This feels much more responsive because users see text appearing in real-time rather than waiting for the entire response.

Bonus: Advanced Features

Now that you’ve mastered the basics, let me introduce you to some advanced features that’ll really level up your applications.

Function Calling (Tools)

One of the most powerful features of the GPT models is function calling—letting the AI decide when to use external tools and providing structured data for those tools.

Here’s a simple example where the AI can “look up” the weather:

from openai import OpenAI
import json

client = OpenAI()

# Define the function that GPT can call
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Get the current weather in a given location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA"
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": "The temperature unit"
                    }
                },
                "required": ["location"]
            }
        }
    }
]

def get_current_weather(location, unit="fahrenheit"):
    """Simulated weather function - in real app, call a weather API"""
    # This would normally call a real weather API
    weather_data = {
        "location": location,
        "temperature": 72 if unit == "fahrenheit" else 22,
        "unit": unit,
        "condition": "sunny"
    }
    return json.dumps(weather_data)

# Make the API call with tools
response = client.chat.completions.create(
    model="gpt-5.2",
    messages=[
        {"role": "user", "content": "What's the weather like in San Francisco?"}
    ],
    tools=tools,
    tool_choice="auto"  # Let the model decide when to use tools
)

# Check if the model wants to call a function
message = response.choices[0].message

if message.tool_calls:
    # The model wants to use a tool
    tool_call = message.tool_calls[0]
    function_name = tool_call.function.name
    arguments = json.loads(tool_call.function.arguments)
    
    # Call the actual function
    if function_name == "get_current_weather":
        function_response = get_current_weather(**arguments)
    
    # Send the function result back to the model
    final_response = client.chat.completions.create(
        model="gpt-5.2",
        messages=[
            {"role": "user", "content": "What's the weather like in San Francisco?"},
            message,  # Include the assistant's tool call request
            {
                "role": "tool",
                "tool_call_id": tool_call.id,
                "content": function_response
            }
        ]
    )
    
    print(final_response.choices[0].message.content)
else:
    print(message.content)

This pattern is the foundation for building AI agents—systems where the AI can interact with external services, databases, and APIs to accomplish tasks. For more code examples, see our AI function calling snippets and OpenAI API code snippets. For a complete tutorial, check out our guide on building your first AI agent.

Vision: Analyzing Images

GPT-5.2 can also analyze images through the same chat completions API:

from openai import OpenAI
import base64

client = OpenAI()

# Method 1: Using a URL
response = client.chat.completions.create(
    model="gpt-5.2",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What's in this image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/image.jpg"
                    }
                }
            ]
        }
    ],
    max_tokens=500
)

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

# Method 2: Using a local file (base64 encoded)
def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.standard_b64encode(image_file.read()).decode("utf-8")

image_path = "your_image.jpg"
base64_image = encode_image(image_path)

response = client.chat.completions.create(
    model="gpt-5.2",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Describe this image in detail."},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{base64_image}"
                    }
                }
            ]
        }
    ],
    max_tokens=1000
)

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

This opens up use cases like:

  • Analyzing charts and graphs
  • Describing photos for accessibility
  • Extracting text from images (OCR)
  • Identifying products or objects
  • Reading handwritten notes

Generating Images with DALL-E

While chat completions handle text and image analysis, image generation uses a separate endpoint:

from openai import OpenAI

client = OpenAI()

response = client.images.generate(
    model="gpt-image-1.5",  # Latest DALL-E model
    prompt="A futuristic cityscape at sunset with flying cars and neon lights, digital art style",
    size="1024x1024",
    quality="standard",  # or "hd" for higher quality (costs more)
    n=1  # Number of images to generate
)

# Get the image URL
image_url = response.data[0].url
print(f"Image URL: {image_url}")

# Or save it locally
import requests
img_data = requests.get(image_url).content
with open("generated_image.png", "wb") as f:
    f.write(img_data)

Text-to-Speech

You can also generate spoken audio from text:

from openai import OpenAI
from pathlib import Path

client = OpenAI()

speech_file_path = Path("speech.mp3")

response = client.audio.speech.create(
    model="tts-1",  # or "tts-1-hd" for higher quality
    voice="alloy",  # Options: alloy, echo, fable, onyx, nova, shimmer
    input="Hello! This is a test of the OpenAI text-to-speech API."
)

# Save the audio file
response.stream_to_file(speech_file_path)
print(f"Audio saved to {speech_file_path}")

Speech-to-Text (Whisper)

And transcribe audio back to text:

from openai import OpenAI

client = OpenAI()

# Transcribe audio file
with open("audio_file.mp3", "rb") as audio_file:
    transcription = client.audio.transcriptions.create(
        model="whisper-1",
        file=audio_file,
        response_format="text"  # or "json", "srt", "vtt" for subtitles
    )

print(transcription)

# You can also translate non-English audio to English
with open("spanish_audio.mp3", "rb") as audio_file:
    translation = client.audio.translations.create(
        model="whisper-1",
        file=audio_file
    )

print(translation)

Embeddings for Search and Similarity

Embeddings convert text into numerical vectors, which is useful for semantic search, recommendations, and clustering:

from openai import OpenAI

client = OpenAI()

# Generate embeddings for text
response = client.embeddings.create(
    model="text-embedding-3-small",  # Fast and cheap
    # or "text-embedding-3-large" for higher quality
    input="The quick brown fox jumps over the lazy dog"
)

embedding = response.data[0].embedding
print(f"Embedding dimension: {len(embedding)}")  # 1536 for small, 3072 for large

# Compare similarity between texts
def get_embedding(text):
    response = client.embeddings.create(
        model="text-embedding-3-small",
        input=text
    )
    return response.data[0].embedding

def cosine_similarity(a, b):
    import math
    dot_product = sum(x * y for x, y in zip(a, b))
    norm_a = math.sqrt(sum(x ** 2 for x in a))
    norm_b = math.sqrt(sum(x ** 2 for x in b))
    return dot_product / (norm_a * norm_b)

# Compare two texts
text1 = "I love programming in Python"
text2 = "Python is my favorite coding language"
text3 = "The weather is nice today"

emb1 = get_embedding(text1)
emb2 = get_embedding(text2)
emb3 = get_embedding(text3)

print(f"Similarity (1 vs 2): {cosine_similarity(emb1, emb2):.3f}")  # High - similar topics
print(f"Similarity (1 vs 3): {cosine_similarity(emb1, emb3):.3f}")  # Low - different topics

Embeddings are the foundation for building RAG (Retrieval-Augmented Generation) systems that can answer questions about your own documents.

What to Build Next

Now that you’ve got both the basics and some advanced features, here are project ideas organized by complexity:

Beginner Projects

  • Summarizer: Paste in long text, get a summary
  • Translator: Convert between languages with context awareness
  • Code explainer: Paste code, get a plain-English explanation
  • Email writer: Generate professional emails from bullet points

Intermediate Projects

  • Document Q&A: Upload PDFs and ask questions (combine with embeddings and RAG techniques)
  • Writing assistant: Help with emails, blog posts, and other content
  • Study buddy: Generate flashcards or quiz questions from notes
  • Meeting summarizer: Transcribe audio with Whisper, summarize with GPT
  • Image analyzer: Upload images and get detailed descriptions

Advanced Projects

  • Multi-agent systems: Multiple AI agents working together on complex tasks
  • Tool-using agents: AI that can browse the web, run code, query databases
  • Custom chatbot: Trained on your own data using fine-tuning
  • Voice assistant: Combine speech-to-text, GPT, and text-to-speech
  • Semantic search engine: Use embeddings to search through documents by meaning

For building more complex AI applications, check out our guide on AI agent frameworks which covers LangChain, CrewAI, and other tools that make advanced AI apps easier to build.

Frequently Asked Questions

How much does the OpenAI API cost?

The OpenAI API uses pay-as-you-go pricing based on tokens. GPT-5.2 costs $1.75 per million input tokens and $14.00 per million output tokens. A typical conversation message costs less than half a cent. For learning and prototyping, you can do a lot with just a few dollars.

What’s the difference between the API and ChatGPT?

ChatGPT is OpenAI’s consumer product—a web interface with a subscription model. The API lets you build ChatGPT-like functionality into your own applications. The API gives you more control (parameters, system prompts, integration) but requires programming knowledge.

Do I need to pay for ChatGPT Plus to use the API?

No, they’re completely separate. API access has its own billing based on usage. You don’t need any ChatGPT subscription to use the API, and having ChatGPT Plus doesn’t give you free API credits.

What model should I use?

For most use cases, GPT-5.2 offers the best balance of capability and cost. Use GPT-5 Mini for simple tasks like classification or translation. Use GPT-5.2 Pro only when you need maximum intelligence for complex reasoning tasks.

How do I avoid unexpected charges?

Set up billing alerts in your OpenAI dashboard, set a monthly spending limit, and monitor your usage regularly. Use the cheapest model that works for your use case, and implement caching for frequent queries.

Can I use the API in production applications?

Absolutely. Many companies use the OpenAI API in production, from startups to enterprises. For production use, focus on proper error handling with retry logic, set up monitoring and alerting, implement rate limiting on your end, and have fallback behavior for API outages. OpenAI offers enterprise tiers with higher rate limits and dedicated support for high-volume applications.

What are the rate limits?

Rate limits vary by your usage tier and the model you’re using. New free-tier accounts have lower limits that increase as you use the API and build payment history. For GPT-5.2, typical limits are around 10,000 tokens per minute for new accounts, scaling significantly higher as your account matures. You can check your current limits in the OpenAI dashboard under “Rate limits.” If you hit limits frequently, implement exponential backoff and consider requesting a limit increase.

Is my data used for training?

By default, data sent through the API is not used to train OpenAI’s models. This is different from ChatGPT, where conversations may be used for training unless you opt out. Enterprise and Team accounts have additional data handling agreements. Always review OpenAI’s current data usage policies for your specific use case, especially for sensitive applications.

Conclusion

You’ve just learned everything you need to start building with the OpenAI API. We covered:

  • Setting up your environment securely
  • Making API calls with proper error handling
  • Understanding tokens and managing costs
  • Building a real conversational application
  • Production best practices

The API is surprisingly accessible once you understand the basics. The hardest part is usually coming up with ideas for what to build—but with GPT-5.2’s capabilities, the possibilities are genuinely endless.

My advice? Start small. Build something that solves a problem you personally have. Then iterate from there.

The best way to learn is by doing. Go build something.


Want to explore more AI development topics? Check out how AI agents work or learn about building your first AI agent with Python.

Found this helpful? Share it with others.

Vibe Coder avatar

Vibe Coder

AI Engineer & Technical Writer
5+ years experience

AI Engineer with 5+ years of experience building production AI systems. Specialized in AI agents, LLMs, and developer tools. Previously built AI solutions processing millions of requests daily. Passionate about making AI accessible to every developer.

AI Agents LLMs Prompt Engineering Python TypeScript