Stop 16 · AI APIs & Cloud AI PlatformsTopics · 1/9

OpenAI API

Part of the AI Engineer Roadmap

In short

Most AI features you'll build start with one HTTP call to a hosted model. The OpenAI API is the one most tutorials use, so learning it well makes every other provider easier.

The API powering GPT models — one of the most widely integrated LLM APIs, with chat completions, function calling, embeddings and structured outputs.

The blob talks happily on a phone inside a small roadside phone booth while a meter ticks beside it.

Think of it like this

The old PCO booth

At a PCO booth you didn't own the phone line. You walked in, made your call and paid by the minute on the meter. The OpenAI API works the same way: you don't own the model, you send a request and pay for the tokens you use.

Watch it happen

One request to the Responses API

Your app
OpenAI API

POST /v1/responses

1/4Your app sends the model name, instructions and input, with your API key in the Authorization header.

The big ideas

What you need to know

API keys are secrets

Keep the key in an environment variable on the server. Never ship it inside a frontend or mobile app.

Instructions plus input

Instructions set the model's behaviour. Input is the user's request. Keep them separate so users can't easily override your rules.

You pay per token

Both input and output tokens cost money, and output usually costs more. Short prompts and length limits save real money.

Pick the smallest model that works

Smaller models are cheaper and faster. Test on your real task before reaching for the biggest one.

See it in code

Walk through the code

python
1from openai import OpenAI2 3client = OpenAI()  # reads OPENAI_API_KEY from the environment4 5response = client.responses.create(6    model="gpt-5-mini",7    instructions="You are a friendly tutor for Indian college students.",8    input="Explain Big O notation with a chai stall example.",9)10print(response.output_text)11print(response.usage.input_tokens, response.usage.output_tokens)

1/3The client picks up your key from the environment. No key in the code.

A basic call with the official Python SDK. Model names change often, so check the docs for the current list.

Save yourself the pain

Common mistakes

Oops

Putting the API key in React code so the browser calls OpenAI directly.

Do this instead

Call the API from your own backend. Anyone can read a key shipped to a browser and spend your money.

Oops

Never looking at usage until the bill arrives.

Do this instead

Log input and output tokens for every call and set a monthly budget alert in the dashboard.

Your mission

Your first metered call

~20 min

Quick check

Where should your OpenAI API key live in a web app?

Go deeper

  1. 1Work through OpenAI's API quickstart and make calls for chat, embeddings and function calling.
  2. 2Learn the request/response structure and how message roles (system/user/assistant) work.
  3. 3Track token usage per request to understand cost implications early.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge