Using an AI API with Python
Now we need a convenient way for Python to communicate with the API.
Python SDK — What Is It?
Now we need a convenient way for Python to communicate with the API.
You could manually create HTTP requests. But that's annoying.
Instead, many AI providers provide an SDK.
SDK = Software Development Kit
A Python SDK gives you Python code that makes interacting with the API easier.
Instead of manually constructing HTTP requests:
Python
↓
HTTP headers
↓
Authentication
↓
JSON
↓
Endpoint
↓
Request
you can use:
client.responses.create(...)
Much easier.
Install the Python SDK
For OpenAI's Python SDK, the basic installation is:
pip install openai
Then:
from openai import OpenAI
Now Python can use the SDK.
Your First Python Program
Add an instruction:
from openai import OpenAI
client = OpenAI()
question = input("Ask AI: ")
prompt = f"""
Answer the user's question in simple English.
User question:
{question}
Give one practical example.
"""
response = client.responses.create(
model="gpt-5.6",
input=prompt
)
print("\nAI:", response.output_text)
How Does the Program Work?
User Question
↓
Python
↓
Build Prompt
↓
Python SDK
↓
AI API
↓
LLM
↓
Answer
↓
Python
↓
User
This connects directly to Lesson 4 — Prompts.