Loading lesson…
The Responses API is OpenAI's modern surface. One call, text and tools. Learn the shape you'll use most.
OpenAI ships chat.completions (classic) and responses (modern). New code should prefer responses — it unifies text, tools, and structured output.
from openai import OpenAI client = OpenAI() def ask(prompt: str) -> str: try: r = client.responses.create( model="gpt-5", input=[ {"role": "system", "content": "Be concise."}, {"role": "user", "content": prompt}, ], ) return r.output_text except Exception as e: print(f"OpenAI call failed: {e}") raise print(ask("Explain recursion in one sentence."))output_text is a convenience accessor that concatenates all text in the response.def ask_stream(prompt: str) -> None: with client.responses.stream( model="gpt-5", input=[{"role": "user", "content": prompt}], ) as stream: for event in stream: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True) stream.until_done() print()Context manager ensures the stream closes. Event types are strings — filter for the text delta.Understanding "Calling the OpenAI API" in practice: AI-assisted coding shifts work from syntax recall to design thinking — models handle boilerplate so you focus on architecture. The Responses API is OpenAI's modern surface. One call, text and tools. Learn the shape you'll use most — and knowing how to apply this gives you a concrete advantage.
The big idea: responses.create for the modern path, stream for UIs, and centralize model ids so provider swaps are painless.
8 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-progx-openai-api-creators
What is the main idea of "Calling the OpenAI API"?
Which concept is most central to "Calling the OpenAI API"?
Which use of AI fits this topic best?
What should a careful learner remember about "Model ids change"?
You want to use AI after this lesson. What is the safest next step?
How should AI output about Responses API be treated?
Name one way to verify an AI answer about Responses API.
Which action would help you apply "Calling the OpenAI API" responsibly?