Saltar al contenido

Lección 26 · Projects and Reference

OpenAI API Glossary and Cheat Sheet

A quick OpenAI API reference: Responses API calls, parameters, output types, tools, error handling, retired features and a glossary of key terms.

This page is your quick reference. The code is read-only and uses the Python SDK. Model names, features and prices are as of December 2026. Check the official documentation before you rely on details.

Setup

Terminal
pip install openai
export OPENAI_API_KEY="your key"     # PowerShell: setx OPENAI_API_KEY "your key"
Python
from openai import OpenAI
client = OpenAI(timeout=60.0, max_retries=2)

Core calls

Python
# Text
r = client.responses.create(model=MODEL, input="Hello")
r.output_text

# Roles
input=[{"role": "developer", "content": "Be brief."},
       {"role": "user", "content": "Hi"}]

# Continue a conversation
client.responses.create(model=MODEL, previous_response_id=r.id, input="More")

# Stream
for event in client.responses.create(model=MODEL, input="Hi", stream=True):
    if event.type == "response.output_text.delta":
        print(event.delta, end="")

# Structured output
client.responses.parse(model=MODEL, input=text, text_format=MyModel).output_parsed

# Count input tokens
client.responses.input_tokens.count(model=MODEL, input=text).input_tokens

# Embeddings
client.embeddings.create(model="text-embedding-3-small", input=["text"])

# Moderation
client.moderations.create(model="omni-moderation-latest", input=text)

Useful request settings

Setting Purpose
instructions Guidance for this request only
max_output_tokens Cap on output, including reasoning
reasoning={"effort": ...} Depth of reasoning; values depend on the model
text={"format": ...} Structured Outputs or JSON mode
tools, tool_choice Which tools and whether to use them
parallel_tool_calls Allow several calls in one turn
previous_response_id Chain turns on the server
conversation Use a durable conversation object
store Opt out of storing the response with False
background Run a slow response asynchronously
safety_identifier Hashed end-user ID

For GPT-6.2 models, the migration guide says to omit temperature and top_p.

Response checklist

TEXT
1. Did the call raise an exception?
2. status == "completed"? If incomplete, read incomplete_details.reason.
3. Any refusal parts?
4. Any function_call items to run?
5. Validate values before using them.
6. Log usage and request ID.

Function calling shapes

Python
tool = {"type": "function", "name": "lookup", "description": "...",
        "parameters": {...}, "strict": True}

# reply with the same call_id
{"type": "function_call_output", "call_id": item.call_id, "output": "..."}

General models (as of December 2026)

Model ID Input / output per 1M tokens (standard, short context)
gpt-6.2-astra $8.00 / $40.00
gpt-6.2-sol $2.00 / $10.00
gpt-6.1-terra $1.00 / $5.00
gpt-6-luna $0.10 / $0.50

Cached input, cache writes, long context, tools, batch and background windows are priced separately.

Retired or retiring: avoid in new code

Item Status as of December 2026
Assistants API Shut down August 26, 2026
Videos API and Sora models Shut down September 24, 2026
Reusable prompt objects Shutdown date November 30, 2026
Evals API, datasets, prompt optimizer Shutdown date November 30, 2026
Agent Builder Shutdown date November 30, 2026
New self-serve fine-tuning jobs End December 15, 2026
Older speech output models January 6, 2027
Older transcription models February 26, 2027

Many older models also have retirement dates. Check the official deprecations page.

A tiny helper to build requests

This runnable helper builds a request dictionary and catches mistakes before you call anything. It is plain code with no network access.

Python Check request settings before sending

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.

Glossary

Term Meaning
API key Secret that authenticates your requests
Responses API Main interface for generating output
Chat Completions Older message-based interface, still supported
Token A small piece of text used for limits and billing
Context window Maximum tokens in one request, including output
Reasoning tokens Internal tokens billed as output
Output item One element of output: message, tool call and more
Structured Outputs Output that follows your JSON Schema
Function calling The model asks your code to run a function
Built-in tool A tool hosted by OpenAI, such as web search
MCP Open protocol for connecting tools to AI apps
Agent Model plus instructions and tools in a loop
Handoff One agent passes work to another
Embedding Vector of numbers that represents content
Vector store Hosted searchable index of your files
RAG Retrieve passages, then generate an answer from them
Prompt caching Reuse of a repeated prompt prefix
Rate limit Cap on requests or tokens in a time period
Batch Many requests processed later at a discount
Webhook HTTP message sent to you when an event happens
Moderation Classifying content for safety categories
Prompt injection Text that tries to override the model's instructions
Hallucination A confident but false or unsupported statement

Where to go next

Learn more about model behavior in large language models, practice instructions in prompt engineering, and study agent design in AI agents. Return to the official documentation, changelog and deprecations pages when you build.

When a code sample fails, compare it with the current API reference and your installed SDK version before you change your logic.

Choose the right feature

You want to Start with
Generate or rewrite text A Responses request
Get data your program can read Structured Outputs plus validation
Let the model fetch data or request an action Function calling
Use current web information Web search, with visible citations
Answer from your documents File search or your own retrieval
Find similar texts Embeddings
Process many items overnight Batch API
Run one very long task Background mode
Talk by voice in real time The Realtime API
Check content for safety categories The moderation endpoint

Troubleshooting guide

Symptom First thing to check
Authentication error The environment variable and whether the key was revoked
Unsupported parameter error Whether that model accepts the setting
Empty text Status, output item types and refusals
Incomplete response The output token limit
Schema rejected Closed objects and the required list
Tool result ignored or rejected Matching call_id and complete history items
Low cache use Changing content near the start of the prompt
Repeated 429 errors The error code: rate limit, or credit and spend limit
Search misses documents Processing status, filters and the file's text

Habits worth keeping

Keep the key on your server. Keep model IDs and prompts in your repository. Treat all output as untrusted until it is checked. Bound every loop and retry. Ask a person before important actions. Run your evaluation set before you ship a change, and read the deprecations page often enough that no shutdown surprises you.

Common mistakes

  • Copying a snippet without replacing placeholders such as the model name or the schema.
  • Treating the tables on this page as permanent. Prices, limits and dates change.

Keep your own notes beside this page: the models you use, the date you last checked them and who owns each integration.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Which interface was shut down in August 2026?

    Use the Responses API, with the Conversations API if you need stored conversations.
  2. 2. What does max_output_tokens limit?

    Leave room for reasoning as well as visible text.
  3. 3. What should you check first after a call returns?

    A response can be incomplete, refused or contain tool calls.

Summary

  • Use responses.create and responses.parse as your main tools.
  • Check status, refusals and tool calls before using output.
  • Avoid retired features and watch the deprecations page.
  • Keep the glossary and tables handy, and verify current facts.

You have finished the course. Go back to the OpenAI API tutorial.

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