Skip to main content
Lesson 5 of 22 · Responses API: OpenAI Fundamentals

Your First API Call

Lesson 5 of 22 Updated November 3, 2026 Developer
On this page
  1. Your First API Call
  2. The Simplest Call
  3. What the Response Really Contains
  4. The Parameters That Matter
  5. Moving to Structured Input
  6. Never Leave a Call Unprotected
  7. Key Takeaways

Lesson updated November 3, 2026 based on OpenAI documentation: temperature and top_p are only accepted with a reasoning effort of none, whereas GPT-5.6 models reason by default (medium). Calls that set these parameters must therefore specify reasoning={"effort": "none"} (Responses API) or reasoning_effort="none" (Chat Completions). Sources: Using GPT-6 · GPT-5.6 Terra.

Your First API Call

Your environment is ready: let’s get to work. You’re about to make your first call to the Responses API, dissect the object it returns, and then manipulate the parameters that separate a generic response from a useful one.

The Simplest Call

Two parameters are all you need: model, the identifier of the model to query, and input, your prompt—either a text string or a list of messages, as we’ll see shortly.

from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-5.6-terra",
    input="What is the difference between Python and JavaScript?"
)

print(response.output_text)
# Result: Python is a versatile language oriented toward data science
# and backend development, while JavaScript is primarily used for
# frontend and backend web development (via Node.js)...

What the Response Really Contains

output_text is just a convenience shortcut. The response object also carries its unique ID—essential for chaining exchanges and looking up calls in your logs—the actual model used, and a breakdown of token consumption. Make it a habit to log these three pieces of information from your very first scripts. This is what will allow you to answer the question later: “Why did the bill double this month?”

response = client.responses.create(
    model="gpt-5.6-terra",
    input="Hello, how are you?"
)

# The response text (shortcut)
print(response.output_text)

# The unique ID of the response
print(f"ID: {response.id}")

# The model used
print(f"Model: {response.model}")

# Tokens consumed
print(f"Input tokens: {response.usage.input_tokens}")
print(f"Output tokens: {response.usage.output_tokens}")
print(f"Total tokens: {response.usage.total_tokens}")

# Result:
# Hello! I'm doing very well, thank you. How can I help you?
# ID: resp_abc123xyz
# Model: gpt-5.6-terra
# Input tokens: 14
# Output tokens: 19
# Total tokens: 33

The Parameters That Matter

temperature governs the variability of the generation. At 0.0, the model systematically chooses the most probable continuation: this is the setting for factual questions, data extraction, and anything you need to reproduce identically. At 1.0, it explores more, which is what you want for naming, creative writing, or generating variants.

# Low temperature (0.0) = deterministic, factual
response_factual = client.responses.create(
    model="gpt-5.6-terra",
    reasoning={"effort": "none"},  # temperature requires effort none
    input="What is the capital of Germany?",
    temperature=0.0
)
print(response_factual.output_text)
# Result: The capital of Germany is Berlin.

# High temperature (1.0) = creative, varied
response_creative = client.responses.create(
    model="gpt-5.6-terra",
    reasoning={"effort": "none"},  # temperature requires effort none
    input="Invent a name for a literary café.",
    temperature=1.0
)
print(response_creative.output_text)
# Result: "The Wandering Pages"—a café where every table bears
# the name of a famous chapter.

The instructions parameter fills the role of the old system message: it defines the role, tone, and constraints the model must maintain throughout the exchange, regardless of the question asked. In the example below, the same question asked without instructions would produce a list of general tips; with them, it produces recipes.

response = client.responses.create(
    model="gpt-5.6-terra",
    instructions="You are an expert in French cuisine. "
                 "Always respond with recipe suggestions.",
    input="I don't know what to do with zucchini."
)
print(response.output_text)
# Result: Here are three ideas for your zucchini:
# 1. Zucchini gratin with goat cheese...
# 2. Provençal ratatouille...
# 3. Cold zucchini velouté with mint...

Finally, max_output_tokens caps the length of the response. This is a budgetary safeguard, not a writing instruction: the response is cut off abruptly once the limit is reached. If you want a short, well-formed answer, ask for that in the prompt as well.

response = client.responses.create(
    model="gpt-5.6-terra",
    input="Explain general relativity.",
    max_output_tokens=100
)
print(response.output_text)
print(f"Tokens used: {response.usage.output_tokens}")
# The response will be truncated at approximately 100 tokens

Moving to Structured Input

When a simple string isn’t enough, input accepts a list of messages. The minimal form contains a single turn, but the benefit appears as soon as you provide history: the model then has access to what has already been said and responds accordingly. Here, “progress” is understood in the context of Python, not in the abstract.

response = client.responses.create(
    model="gpt-5.6-terra",
    input=[
        {
            "role": "user",
            "content": "Translate to English: Hello world"
        }
    ]
)
print(response.output_text)
# Result: Hello world

# With conversation context
response = client.responses.create(
    model="gpt-5.6-terra",
    input=[
        {
            "role": "user",
            "content": "My favorite language is Python."
        },
        {
            "role": "assistant",
            "content": "Python is an excellent choice! It is very versatile."
        },
        {
            "role": "user",
            "content": "Give me a tip to improve."
        }
    ]
)
print(response.output_text)
# Result: To improve in Python, I recommend that you...

Never Leave a Call Unprotected

Network calls fail, and keys expire. Three exceptions cover most cases when starting out: AuthenticationError for a missing or invalid key, RateLimitError when you exceed your allowed throughput, and APIError as a generic safety net. An entire lesson will return to the full strategy, but starting today, wrap your calls.

from openai import OpenAI, APIError, AuthenticationError, RateLimitError

client = OpenAI()

try:
    response = client.responses.create(
        model="gpt-5.6-terra",
        input="Hello!"
    )
    print(response.output_text)
except AuthenticationError:
    print("Error: Invalid or missing API key")
except RateLimitError:
    print("Error: Too many requests, wait a moment")
except APIError as e:
    print(f"API Error: {e.message}")

To consolidate all of this, write a script that asks three questions and accumulates the tokens consumed. You will combine the call loop, a temperature of 0.0 for stable responses, and reading usage—the three basic reflexes.

from openai import OpenAI

client = OpenAI()

questions = [
    "What is the largest ocean in the world?",
    "Who painted the Mona Lisa?",
    "How many planets are in the solar system?"
]

total_tokens = 0

for question in questions:
    response = client.responses.create(
        model="gpt-5.6-terra",
        reasoning={"effort": "none"},  # temperature requires effort none
        input=question,
        temperature=0.0
    )
    tokens = response.usage.total_tokens
    total_tokens += tokens
    print(f"Q: {question}")
    print(f"A: {response.output_text}")
    print(f"   ({tokens} tokens)\n")

print(f"Total: {total_tokens} tokens consumed")

Key Takeaways

  • A basic call requires only model and input
  • response.output_text provides the response text
  • response.usage details token consumption
  • temperature controls creativity (0.0 = factual, 1.0 = creative)
  • instructions replace the system message from Chat Completions
  • Always handle errors with try/except blocks