📊 We use cookies & analytics to improve your experience. Learn more
Latest

ChatGPT Mastery — From First Prompt to Advanced Workflows Module 3 · Lesson 10 of 15

0% Exit to course

Module 3 · Files, tools and your own data Lesson 10 of 15

The OpenAI API and your first script

Learning objective

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:

Python
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.

Create free account or sign in

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.