Saltar al contenido

Lección 1 · Getting Started

What Is the OpenAI API?

Learn what the OpenAI API is, how it differs from ChatGPT, what you need before you start, what this tutorial can run, and how the course is organized.

The OpenAI API lets your own program send input to OpenAI's models and get output back. A web shop can use it to draft replies to customers. A script can use it to sort thousands of emails. A mobile app can use it to describe a photo. Your code is in charge: it decides what to send, what to do with the answer, and when a person must check it.

This tutorial is for developers and technical learners who can write basic code. It is independent: it is not made, reviewed or endorsed by OpenAI. Product details change often, so every fact about models, prices and features here is stated as of December 2026. Check the official documentation before you rely on one.

The API is not the ChatGPT app

ChatGPT is a finished product that people use in a browser or an app. The API is a building block for programmers. The two are billed and managed separately: a ChatGPT subscription is a different thing from an API account that pays for usage.

Question ChatGPT app OpenAI API
Who uses it? A person, by typing Your program, over HTTPS
Who builds the interface? OpenAI You
Where does conversation history live? In the app You choose: your code or a server-side feature
How do you pay? Plan Usage, mostly measured in tokens

A token is a small piece of text, often part of a word. Models read and write tokens, and most API prices are per token. If the idea is new, read tokenization basics.

How a request works

Every call follows the same pattern.

  1. Your server builds a request: the model name, the input, and optional settings.
  2. It sends the request over HTTPS, signed with a secret API key.
  3. The model generates output.
  4. The API returns a structured response with the output, a status and a usage report.
  5. Your code checks the response and decides what happens next.

The main endpoint for generating output is the Responses API. OpenAI's documentation recommends it for new text applications. An older interface called Chat Completions still exists, and you will meet it in older code. This course teaches the Responses API.

What you need

  • Basic programming in Python or JavaScript. Examples are mostly in Python.
  • Some comfort with JSON, because requests, schemas and tool arguments use it.
  • To run real calls: an OpenAI API account, an API key and a way to pay for usage.
  • To follow the course: only your browser.

It also helps to know what a large language model is, and a little prompt engineering.

What this tutorial can and cannot run

The site cannot call OpenAI. There is no network access in the code runners and no API key. So you will see two kinds of code.

  • Read-only code shows the real SDK calls. Copy it to your own computer to run it with your own key.
  • Runnable blocks are titled Stand-in, or are plain helper code such as a cost calculator. A stand-in is a small hand-written imitation. It shows the logic your program needs, but no AI model is involved.

A stand-in prints text that a person wrote in advance. Never read it as proof of how a real model behaves. Only your own tests with the real API can show that.

Here is a first stand-in. The function fake_create returns a dictionary shaped loosely like a real response, with made-up values.

Python Stand-in: send input, read a response

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Even this toy shows two good habits: check the status before you use the text, and look at the usage numbers.

Course map

Foundations

Getting started Keys and first call
Generating text Roles, state, streaming
Structured outputs JSON you can trust
1 / 3

Safe habits from day one

Model output can be wrong while sounding sure. Treat it as a draft or a suggestion until something checks it. Decide early which data you are allowed to send: personal data, passwords and company secrets need a deliberate decision, not an accident. And when a model's output can change something in the real world, such as sending money or deleting a record, put a person or a strict rule in between.

A common beginner mistake is to call the API straight from a web page or mobile app with your secret key inside. Anyone can extract it and spend your money. Calls with your key belong on a server you control.

Is the API the right tool?

Before you add a model to a product, ask what the task needs. Use ordinary code when the rules are exact, such as adding up a bill or checking that a date is in the past. Code is cheaper, faster and gives the same answer every time. A model is a good fit when the input is messy language or images, and a reasonable draft or classification is useful even though it is sometimes wrong.

Three questions help. What happens if the answer is wrong? Who or what will notice? Can the action be undone? A weak draft that a person edits is low risk. An automatic decision about someone's money or job is not. Start with the low-risk version, measure how well it works, and only then give it more responsibility.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. What is the main difference between ChatGPT and the OpenAI API?

    With the API, your code builds the interface and decides what to do with the output.
  2. 2. Which API does this course use for generating text?

    The Responses API is the one OpenAI's documentation recommends for new applications. The Assistants API has been shut down.
  3. 3. What does a runnable Stand-in block on this site do?

    Stand-ins teach program logic. They cannot tell you how a real model will answer.
  4. 4. Where should your secret API key be used?

    Anything shipped to users can be extracted, so keyed requests belong on your server.

Summary

  • The OpenAI API lets your program use OpenAI's models; it is separate from the ChatGPT app.
  • A request has a model, input and settings; a response has output, a status and usage.
  • This course uses the Responses API and is independent of OpenAI.
  • The site cannot call the real API, so runnable examples are stand-ins or helpers.
  • Check outputs, protect data and keep your key on the server.

Next: API Keys, Projects and Setup

Tu progreso se guarda en este navegador. No necesitas una cuenta.