Module 3 · Files, tools and your own data Lesson 10 of 15
The OpenAI API and your first script
OpenAI serves the same models over an API that is billed per token, with a Responses endpoint for text and tool calling, and a separate images endpoint. You do not need this to finish the course, and you do not need it for a fresher job either — but an afternoon here is what turns "I have used ChatGPT" into "I have built with it", which is a different sentence in an interview.
The concept
OpenAI serves the same models over an API that is billed per token, with a Responses endpoint for text and tool calling, and a separate images endpoint. The idea is simple: the same model you have been chatting with also answers a web request, so you can put it inside a script, a spreadsheet or a page. A key identifies you; a request sends the text; a response comes back as data.
The reason to try it once, even if you never build anything: it makes the chat version less mysterious. You see that the whole conversation is text in and text out, that your instructions are literally lines of a request, and that "the model" is one parameter among several.
A first call looks like this:
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY from your environment
r = client.responses.create(
model="gpt-5-mini",
input="In one sentence, what does a data analyst do?",
)
print(r.output_text)Common mistakes
The mistake is pasting a key into a file you then commit. Keys go in environment variables, never in code, and a key that has ever been in a public repository is a key to throw away.
Worked example
Fifty lines of Python that read a CSV of job titles and return a one-line summary of each is a realistic first script — and describes a real productivity gain rather than a demo.
Your practice task
Get a key, run one request that works, and change one word in it to see the answer change. That is the whole of the first afternoon.
Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.
Key takeaway
OpenAI serves the same models over an API that is billed per token, with a Responses endpoint for text and tool calling, and a separate images endpoint.
Keep your place in this course
A free account saves which lessons you have finished and unlocks the certificate. The lesson itself stays free to read.
Create free account or sign inCourse complete
You finished every lesson.
Your certificate is ready, and the projects you built are the proof to attach to an application.
Almost there
15 lessons left of 15
Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.
