Friday, August 8, 2025

A Practical Guide for Developers

The recent release of the GPT-5 model offers developers cutting-edge AI capabilities with advances in coding, reasoning, and creativity. The GPT-5 model has some new API features that enable you to create outputs where you have detailed control. This primer introduces GPT-5 in the context of the API, summarizes differences, and explains how you can apply it to code and automated tasks. 

GPT-5 is built for developers. The new GPT-5 uses tools that let you control verbosity, depth of reasoning, and output format. In this guide, you will learn how to begin using GPT-5, understanding some of its unique parameters, as well as review code samples from OpenAI’s Cookbook that illustrate processes providing more than prior versions of models.

What’s New in GPT-5?

GPT-5 is smarter, more controllable, and better for complex work. It’s very good at code generation, reasoning, and using tools. The model shows state-of-the-art performance on engineering benchmarks, writes beautiful frontend UIs, follows instructions well, and can behave autonomously when completing multi-step tasks. The model is designed to feel like you’re interacting with a genuine collaborator. Its main features include:

Breakthrough Capabilities

  • State-of-the-art performance on SWE-bench (74.9%) and Aider (88%)
  • Generates complex, responsive UI code while exhibiting design sense
  • Can fix hard bugs and understand large codebases
  • Plans tasks like a real AI agent as it uses APIs precisely and recovers properly from tool failures. 

Smarter reasoning and fewer hallucinations

  • Fewer factual inaccuracies and hallucinations
  • Better understanding and execution of user instructions
  • Agentic behavior and tool integration
  • Can undertake multi-step, multi-tool workflows

Why Use GPT-5 via API?

GPT-5 is purpose-built for developers and achieves an expert-level performance on real-world coding and data tasks. It has a powerful API that can unlock automation, precision, and control. Whether you are debugging or building full applications, GPT-5 is easy to integrate with your workflows, helping you to scale productivity and reliability with little overload.

  • Developer-specific: Built for coding workflows, so it is easy to integrate into development tools and IDEs.
  • Proven performance: SOTA real-world tasks (e.g. bug-fixes, code edits) with errors and tokens necessary.
  • Fine-grained control: on new parameters like verbosity, reasoning, and blueprint tool calls allows you to shape the output and develop automated pipelines.

Getting Started

In order to begin using GPT-5 in your applications, you need to configure access to the API, understand the different endpoints available, and select the right model variant for your needs. This section will walk you through how to configure your API credentials, which endpoint to select chat vs. responses, and navigate the GPT-5 models so you can use it to its full potential.

  1. Accessing GPT-5 API

First, set up your API credentials: if you want to use OPENAI_API_KEY as an environmental variable. Then install, or upgrade, the OpenAI SDK to use GPT-5. From there, you can call the GPT-5 models (gpt-5, gpt-5-mini, gpt-5-nano) like any other model through the API. Create an .env file and save api key as:

OPENAI_API_KEY=sk-abc1234567890—
  1. API Keys and Authentication

To make any GPT-5 API calls, you need a valid OpenAI API key. Either set the environment variable OPENAI_API_KEY, or pass the key directly to the client. Be sure to keep your key secure, as it will authenticate your requests.

import os

from openai import OpenAI

client = OpenAI(

   api_key=os.environ.get("OPENAI_API_KEY")

)
  1. Selecting the Correct Endpoint

GPT-5 offers the Responses API, which serves as a uniform endpoint for interactions with the model, providing reasoning traces, tool calls, and advanced controls through the same interface, making it the best option overall. OpenAI recommends this API for all new deployments.

from openai import OpenAI

import os

client = OpenAI()

response = client.responses.create(

   model="gpt‑5",

   input=[{"role": "user", "content": "Tell me a one-sentence bedtime story about a unicorn."}]

)

print(response.output_text)

Model Variants

Model Variant Best Use Case Key Advantage
gpt‑5 Complex, multi‑step reasoning and coding tasks High performance
gpt‑5‑mini Balanced tasks needing both speed and value Lower cost with decent speed
gpt‑5‑nano Real-time or resource-constrained environments Ultra-low latency, minimal cost
GPT-5
GPT-5 versions

Using GPT-5 Programmatically

To access the GPT-5,  we can use the OpenAI SDK to invoke GPT-5. For example, if you’re in Python:

from openai import OpenAI

client = OpenAI()

Then use client.responses.create to submit requests with your messages and parameters for GPT-5. The SDK will automatically use your API key to authenticate the request.

API Request Structure

A typical GPT‑5 API request includes the following fields:

  • model: The GPT‑5 variant (gpt‑5, gpt‑5‑mini, or gpt‑5‑nano).
  • input/messages:
    • For the Responses API: use an input field with a list of messages (each having a role and content)
    • For the Chat Completions API: use the messages field with the same structure
  • text: It is an optional parameter and contains a dictionary of output-styling parameters, such as:
    • verbosity: “low”, “medium”, or “high” to control the level of detail
  • reasoning: It is an optional parameter and contains a dictionary to control how much reasoning effort the model applies, such as:
    • effort: “minimal” for quicker, lightweight tasks
  • tools: It is an optional parameter and contains a list of custom tool definitions, such as for function calls or grammar constraints.
  • Key Parameters: verbosity, reasoning_effort, max_tokens

When interacting with GPT‑5, various parameters allow you to customize how the model responds. This awareness allows you to exert more control over the quality, performance, and cost associated with the responses you receive.

  • verbosity
    Administration of the level of detail provided in the model’s response.
    Acceptable families (values): “low,” “medium,” or “high”
    • “low” is usually stated in an as-yet-undisplayed area of text, and provides short, to-the-point answers
    • “high” provides thorough, detailed explanations and answers
  • reasoning_effort
    Refers to how much internal reasoning the model does before responding.
    Acceptable families (values): “minimal”, “low”, “medium”, “high”.
    • Setting “minimal” will usually return the fastest answer with little to no explanation
    • Setting “high” gives the models’ outputs more room for deeper analysis and hence, perhaps, more developed outputs relative to prior settings
  • max_tokens
    Sets an upper limit for the number of tokens in the model’s response. Max tokens are useful for controlling cost or restricting how long your expected answer might be.

Sample API Call

Here is a Python example using the OpenAI library to call GPT-5. It takes a user prompt and sends it, then prints the response of the model:

from openai import OpenAI

client = OpenAI()

response = client.responses.create(

   model="gpt-5",

   input=[{"role": "user", "content": "Hello GPT-5, what can you do?"}],

   text={"verbosity": "medium"},

   reasoning={"effort": "minimal"}

)

print(response.output)

Output:

GPT-5

Advanced Capabilities

In the following section, we will test the 4 new capabilities of GPT-5 API.

Verbosity Control

The verbosity parameter allows you to signal whether GPT‑5 should be succinct or verbose. You can set verbosity to “low”, “medium”, or “high”. The higher the verbosity, the longer and more detailed the output from the model. Contrarily, low verbosity keeps the model focused on providing shorter answers.

Example: Coding Use Case: Fibonacci Series

from openai import OpenAI

client = OpenAI(api_key="sk-proj---")

prompt = "Output a Python program for fibonacci series"

def ask_with_verbosity(verbosity: str, question: str):

   response = client.responses.create(

       model="gpt-5-mini",

       input=question,

       text={

           "verbosity": verbosity

       }

   )

   # Extract assistant's text output

   output_text = ""

   for item in response.output:

       if hasattr(item, "content"):

           for content in item.content:

               if hasattr(content, "text"):

                   output_text += content.text

   # Token usage details

   usage = response.usage

   print("--------------------------------")

   print(f"Verbosity: {verbosity}")

   print("Output:")

   print(output_text)

   print("Tokens => input: {} | output: {}".format(

       usage.input_tokens, usage.output_tokens

   ))

This use case includes code generation with varying levels of verbosity

  1. Low: Generates minimum code with very little explanation.
ask_with_verbosity("low", prompt)

Response:

Verbosity: low

Output:

```python

def fibonacci(n):

   a, b = 0, 1

   for _ in range(n):

       yield a

       a, b = b, a + b

def main():

   try:

       n = int(input("Enter how many Fibonacci numbers to print: "))

       if n <= 0:

           print("Please enter a positive integer.")

           return

   except ValueError:

       print("Invalid input.")

       return

   print(*fibonacci(n))

if __name__ == "__main__":

   main()

```

Tokens => input: 13 | output: 375

  1. Medium: Generates code with inline comments and with some structural elements.
ask_with_verbosity("medium", prompt)

Response:

Verbosity: medium

Output:

Here's a simple Python program that prints the first N Fibonacci numbers (starting with 0, 1). It validates input and uses an efficient iterative approach:

```python

def fib_series(n):

   """Return a list with the first n Fibonacci numbers (0, 1, 1, 2, ...)."""

   if n <= 0:

       return []

   if n == 1:

       return [0]

   series = [0, 1]

   for _ in range(2, n):

       series.append(series[-1] + series[-2])

   return series

def main():

   try:

       n = int(input("Enter number of Fibonacci terms to generate: ").strip())

   except ValueError:

       print("Please enter a valid integer.")

       return

   if n <= 0:

       print("Enter a positive integer.")

       return

   series = fib_series(n)

   print("Fibonacci series (first {} terms):".format(n))

   print(", ".join(map(str, series)))

if __name__ == "__main__":

   main()

```

If you want other variants (e.g., recursive version, generator that yields values indefinitely, or printing up to a maximum value instead of a count), tell me which and I can provide it.

Tokens => input: 13 | output: 590

  1. High: Generates full production scripts with arguments, validation, and detailed comments.
ask_with_verbosity("high", prompt)

Response:

Verbosity: high

Output:

Below are several Python programs/functions for generating Fibonacci numbers and the Fibonacci series. I include a short explanation for each, examples of how to use them, and notes about performance so you can choose the one that best fits your needs.

Note: the usual convention shown here is F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2.

1) Simple iterative version — recommended for generating a sequence (O(n) time, O(1) extra space)

```python

def fibonacci_list(n):

   """Return a list with the first n Fibonacci numbers: F0 .. F(n-1).

   n must be a non-negative integer."""

   if n < 0:

       raise ValueError("n must be non-negative")

   if n == 0:

       return []

   if n == 1:

       return [0]

   seq = [0, 1]

   for _ in range(2, n):

       seq.append(seq[-1] + seq[-2])

   return seq

# Example usage:

if __name__ == "__main__":

   k = int(input("Which Fibonacci index (n)? "))

   print(f"F_{k} =", fibonacci_n(k))

```

2) Generator style — iterate lazily over the sequence

```python

def fib_generator():

   """Infinite Fibonacci generator: yields 0, 1, 1, 2, 3, ..."""

   a, b = 0, 1

   while True:

       yield a

       a, b = b, a + b

# Example: print first 10 Fibonacci numbers

if __name__ == "__main__":

   import itertools

   for x in itertools.islice(fib_generator(), 10):

       print(x, end=" ")

   print()

```

```

3) Recursive with memoization (fast and simple)

```python

from functools import lru_cache

@lru_cache(maxsize=None)

def fib_memo(n):

   if n < 0:

       raise ValueError("n must be non-negative")

   if n < 2:

       return n

   return fib_memo(n-1) + fib_memo(n-2)

# Example:

if __name__ == "__main__":

   print(fib_memo(100))  # works quickly thanks to memoization

```

```

Which one should you use?

- For typical use (print the first N Fibonacci numbers or compute F_n for moderate n), use the simple iterative fibonacci_list or fibonacci_n.

- For very large n (e.g., thousands or millions of digits), use the fast doubling method (fib_fast_doubling) — it computes F_n in O(log n) arithmetic operations using Python's big integers.

- Avoid the naive recursion except for teaching/demonstration.

- Use memoized recursion for convenience if you want recursive style but still need speed.

If you tell me which variant you want (print series vs return nth value, starting indices, how you want input, or limits like very large n), I can provide a single small script tailored to that use-case.

Tokens => input: 13 | output: 1708

Free‑Form Function Calling

GPT‑5 can now send raw text payloads – anything from Python scripts to SQL queries – to your custom tool without wrapping the data in JSON using the new tool “type”: “custom”. This differs from classic structured function calls, giving you greater flexibility when interacting with external runtimes such as:

  • code_exec with sandboxes (Python, C++, Java, …)
  • SQL databases
  • Shell environments
  • Configuration generators

Note that the custom tool type does NOT support parallel tool calling.

To illustrate the use of free-form tool calling, we will ask GPT‑5 to:

  • Generate Python, C++, and Java code that multiplies 2 5×5 matrices.
  • Print only the time (in ms) taken for each iteration in the code.
  • Call all three functions, and then stop
from openai import OpenAI

from typing import List, Optional

MODEL_NAME = "gpt-5-mini"

# Tools that will be passed to every model invocation

TOOLS = [

   {

       "type": "custom",

       "name": "code_exec_python",

       "description": "Executes python code",

   },

   {

       "type": "custom",

       "name": "code_exec_cpp",

       "description": "Executes c++ code",

   },

   {

       "type": "custom",

       "name": "code_exec_java",

       "description": "Executes java code",

   },

]

client = OpenAI(api_key="ADD-YOUR-API-KEY")

def create_response(

   input_messages: List[dict],

   previous_response_id: Optional[str] = None,

):

   """Wrapper around client.responses.create."""

   kwargs = {

       "model": MODEL_NAME,

       "input": input_messages,

       "text": {"format": {"type": "text"}},

       "tools": TOOLS,

   }

   if previous_response_id:

       kwargs["previous_response_id"] = previous_response_id

   return client.responses.create(**kwargs)

def run_conversation(

   input_messages: List[dict],

   previous_response_id: Optional[str] = None,

):

   """Recursive function to handle tool calls and continue conversation."""

   response = create_response(input_messages, previous_response_id)

   # Check for tool calls in the response

   tool_calls = [output for output in response.output if output.type == "custom_tool_call"]

   if tool_calls:

       # Handle all tool calls in this response

       for tool_call in tool_calls:

           print("--- tool name ---")

           print(tool_call.name)

           print("--- tool call argument (generated code) ---")

           print(tool_call.input)

           print()  # Add spacing

           # Add synthetic tool result to continue the conversation

           input_messages.append({

               "type": "function_call_output",

               "call_id": tool_call.call_id,

               "output": "done",

           })

       # Continue the conversation recursively

       return run_conversation(input_messages, previous_response_id=response.id)

   else:

       # No more tool calls - check for final response

       if response.output and len(response.output) > 0:

           message_content = response.output[0].content

           if message_content:

               print("--- final model response ---")

               print(message_content)

           else:

               print("--- conversation completed (no final message) ---")

       return response

# Your prompt

prompt = """

Write code to multiply two 5x5 matrices in three languages: C++, Python, and Java using code_exec functions. Each language should multiply the matrices 10 times and measure the time taken for each iteration.

ALWAYS CALL THESE THREE FUNCTIONS EXACTLY ONCE: code_exec_python, code_exec_cpp, and code_exec_java tools to perform the matrix multiplication in each language once.

Print only the time it takes to multiply the matrices (in milliseconds) per iteration.

"""

# Initial developer message

messages = [

   {

       "role": "developer",

       "content": prompt,

   }

]

# Start the conversation

run_conversation(messages)

Response in all 3 Languages:

--- tool name ---

code_exec_python

--- tool call argument (generated code) ---

import time

N = 5

A = [[i + j for j in range(N)] for i in range(N)]

B = [[i * j for j in range(N)] for i in range(N)]

def matmul(A, B):

   N = len(A)

   C = [[0] * N for _ in range(N)]

   for i in range(N):

       for j in range(N):

           s = 0

           for k in range(N):

               s += A[i][k] * B[k][j]

           C[i][j] = s

   return C

for _ in range(10):

   t1 = time.perf_counter()

   C = matmul(A, B)

   t2 = time.perf_counter()

   ms = (t2 - t1) * 1000.0

   # Print only the time in milliseconds per iteration

   print(ms)

--- tool name ---

code_exec_cpp

--- tool call argument (generated code) ---

#include <bits/stdc++.h>

using namespace std;

int main() {

   const int N = 5;

   double A[N][N], B[N][N], C[N][N];

   for (int i = 0; i < N; ++i)

       for (int j = 0; j < N; ++j) {

           A[i][j] = i + j;

           B[i][j] = i * j;

       }

   for (int it = 0; it < 10; ++it) {

       for (int i = 0; i < N; ++i)

           for (int j = 0; j < N; ++j)

               C[i][j] = 0.0;

       auto t1 = chrono::high_resolution_clock::now();

       for (int i = 0; i < N; ++i) {

           for (int j = 0; j < N; ++j) {

               double s = 0.0;

               for (int k = 0; k < N; ++k)

                   s += A[i][k] * B[k][j];

               C[i][j] = s;

           }

       }

       auto t2 = chrono::high_resolution_clock::now();

       double ms = chrono::duration<double, milli>(t2 - t1).count();

       cout << ms << endl;

   }

   return 0;

}

--- tool name ---

code_exec_java

--- tool call argument (generated code) ---

public class Main {

   public static void main(String[] args) {

       int N = 5;

       double[][] A = new double[N][N];

       double[][] B = new double[N][N];

       double[][] C = new double[N][N];

       for (int i = 0; i < N; i++)

           for (int j = 0; j < N; j++) {

               A[i][j] = i + j;

               B[i][j] = i * j;

           }

       for (int it = 0; it < 10; it++) {

           for (int i = 0; i < N; i++)

               for (int j = 0; j < N; j++)

                   C[i][j] = 0.0;

           long t1 = System.nanoTime();

           for (int i = 0; i < N; i++) {

               for (int j = 0; j < N; j++) {

                   double s = 0.0;

                   for (int k = 0; k < N; k++)

                       s += A[i][k] * B[k][j];

                   C[i][j] = s;

               }

           }

           long t2 = System.nanoTime();

           double ms = (t2 - t1) / 1_000_000.0;

           System.out.println(ms);

       }

   }

}

Context-Free Grammar (CFG) Enforcement

GPT-5’s Context-Free Grammar (CFG) Enforcement feature enables developers to constrain outputs to a rigid structure, ideal if there are very precise formats, like SQL or even Regex. One example could be having a separate grammar for MS SQL (TOP) and PostgreSQL (LIMIT) and ensuring that GPT-5 generates a syntactically valid query for either of those databases.

The mssql_grammar specifies the exact structure of a valid SQL Server query for SELECT TOP, filtering, ordering, and syntax. It constrains the model to:

  • Returning a fixed number of rows (TOP N)
  • Filtering on the total_amount and order_date
  • Using proper syntax like ORDER BY … DESC and semicolons
  • Using only safe read-only queries with a fixed set of columns, keywords, and value formats

PostgreSQL Grammar

  • The postgres_grammar is analogous to mssql_grammar, but is designed to match PostgreSQL’s syntax by using LIMIT instead of TOP. It constrains the model to:
  • Using LIMIT N to limit the result size
  • Using the same filtering and ordering rules
  • Validating identifiers, numbers, and date formats
  • Limiting unsafe/unsupported SQL operations by limiting SQL structure.
import textwrap

# ----------------- grammars for MS SQL dialect -----------------

mssql_grammar = textwrap.dedent(r"""

           // ---------- Punctuation & operators ----------

           SP: " "

           COMMA: ","

           GT: ">"

           EQ: "="

           SEMI: ";"

           // ---------- Start ----------

           start: "SELECT" SP "TOP" SP NUMBER SP select_list SP "FROM" SP table SP "WHERE" SP amount_filter SP "AND" SP date_filter SP "ORDER" SP "BY" SP sort_cols SEMI

           // ---------- Projections ----------

           select_list: column (COMMA SP column)*

           column: IDENTIFIER

           // ---------- Tables ----------

           table: IDENTIFIER

           // ---------- Filters ----------

           amount_filter: "total_amount" SP GT SP NUMBER

           date_filter: "order_date" SP GT SP DATE

           // ---------- Sorting ----------

           sort_cols: "order_date" SP "DESC"

           // ---------- Terminals ----------

           IDENTIFIER: /[A-Za-z_][A-Za-z0-9_]*/

           NUMBER: /[0-9]+/

           DATE: /'[0-9]{4}-[0-9]{2}-[0-9]{2}'/

   """)

# ----------------- grammars for PostgreSQL dialect -----------------

postgres_grammar = textwrap.dedent(r"""

           // ---------- Punctuation & operators ----------

           SP: " "

           COMMA: ","

           GT: ">"

           EQ: "="

           SEMI: ";"

           // ---------- Start ----------

           start: "SELECT" SP select_list SP "FROM" SP table SP "WHERE" SP amount_filter SP "AND" SP date_filter SP "ORDER" SP "BY" SP sort_cols SP "LIMIT" SP NUMBER SEMI

           // ---------- Projections ----------

           select_list: column (COMMA SP column)*

           column: IDENTIFIER

           // ---------- Tables ----------

           table: IDENTIFIER

           // ---------- Filters ----------

           amount_filter: "total_amount" SP GT SP NUMBER

           date_filter: "order_date" SP GT SP DATE

           // ---------- Sorting ----------

           sort_cols: "order_date" SP "DESC"

           // ---------- Terminals ----------

           IDENTIFIER: /[A-Za-z_][A-Za-z0-9_]*/

           NUMBER: /[0-9]+/

           DATE: /'[0-9]{4}-[0-9]{2}-[0-9]{2}'/

   """)

The example uses GPT-5 and a custom mssql_grammar tool to produce a SQL Server query that returns high-value orders made recently, by customer. The mssql_grammar created grammar rules to enforce the SQL Server syntax and produced the correct SELECT TOP syntax for returning limited results. 

from openai import OpenAI

client = OpenAI()

sql_prompt_mssql = (

   "Call the mssql_grammar to generate a query for Microsoft SQL Server that retrieve the "

   "five most recent orders per customer, showing customer_id, order_id, order_date, and total_amount, "

   "where total_amount > 500 and order_date is after '2025-01-01'. "

)

response_mssql = client.responses.create(

   model="gpt-5",

   input=sql_prompt_mssql,

   text={"format": {"type": "text"}},

   tools=[

       {

           "type": "custom",

           "name": "mssql_grammar",

           "description": "Executes read-only Microsoft SQL Server queries limited to SELECT statements with TOP and basic WHERE/ORDER BY. YOU MUST REASON HEAVILY ABOUT THE QUERY AND MAKE SURE IT OBEYS THE GRAMMAR.",

           "format": {

               "type": "grammar",

               "syntax": "lark",

               "definition": mssql_grammar

           }

       },

   ],

   parallel_tool_calls=False

)

print("--- MS SQL Query ---")

print(response_mssql.output[1].input)

Response:

--- MS SQL Query ---

SELECT TOP 5 customer_id, order_id, order_date, total_amount FROM orders

WHERE total_amount > 500 AND order_date > '2025-01-01'

ORDER BY order_date DESC;

This version targets PostgreSQL and uses a postgres_grammar tool to help GPT-5 produce a compliant query. It follows the same logic as the previous example, but uses LIMIT for the limit of the return results, demonstrating compliant PostgreSQL syntax.

sql_prompt_pg = (

   "Call the postgres_grammar to generate a query for PostgreSQL that retrieve the "

   "five most recent orders per customer, showing customer_id, order_id, order_date, and total_amount, "

   "where total_amount > 500 and order_date is after '2025-01-01'. "

)

response_pg = client.responses.create(

   model="gpt-5",

   input=sql_prompt_pg,

   text={"format": {"type": "text"}},

   tools=[

       {

           "type": "custom",

           "name": "postgres_grammar",

           "description": "Executes read-only PostgreSQL queries limited to SELECT statements with LIMIT and basic WHERE/ORDER BY. YOU MUST REASON HEAVILY ABOUT THE QUERY AND MAKE SURE IT OBEYS THE GRAMMAR.",

           "format": {

               "type": "grammar",

               "syntax": "lark",

               "definition": postgres_grammar

           }

       },

   ],

   parallel_tool_calls=False,

)

print("--- PG SQL Query ---")

print(response_pg.output[1].input)

Response:

--- PG SQL Query ---

SELECT customer_id, order_id, order_date, total_amount FROM orders

WHERE total_amount > 500 AND order_date > '2025-01-01'

ORDER BY order_date DESC LIMIT 5;

Minimal Reasoning Effort

GPT-5 now supports a new minimal reasoning effort. When using minimal reasoning effort, the model will output very few or no reasoning tokens. This is designed for use cases where developers want a very fast time-to-first-user-visible token.

Note: If no reasoning effort is supplied, the default value is medium.

from openai import OpenAI

client = OpenAI()

prompt = "Translate the following sentence to Spanish. Return only the translated text."

response = client.responses.create(

   model="gpt-5",

   input=[

       { 'role': 'developer', 'content': prompt },

       { 'role': 'user', 'content': 'Where is the nearest train station?' }

   ],

   reasoning={ "effort": "minimal" } 

)

# Extract model's text output

output_text = ""

for item in response.output:

   if hasattr(item, "content"):

       for content in item.content:

           if hasattr(content, "text"):

               output_text += content.text

# Token usage details

usage = response.usage

print("--------------------------------")

print("Output:")

print(output_text)

Response:

--------------------------------

Output:

¿Dónde está la estación de tren más cercana?

Pricing & Token Efficiency

OpenAI has GPT-5 models in tiers to suit various performance and budget requirements. GPT-5 is suitable for complex tasks. GPT-5-mini completes tasks fast and is less expensive, and GPT-5-nano is for real-time or light use cases. Any reused tokens in short-term conversations get a 90% discount, greatly reducing the costs of multi-turn interactions.

Model Input Token Cost (per 1M) Output Token Cost (per 1M) Token Limits
GPT‑5 $1.25 $10.00 272K input / 128K output
GPT‑5-mini $0.25 $2.00 272K input / 128K output
GPT‑5-nano $0.05 $0.40 272K input / 128K output

Conclusion

GPT-5 specifies a new age of AI for developers. It combines top-level coding intelligence with greater control through its API. You can engage with its features, such as controlling verbosity, enabling custom tool calls, enforcing grammar, and performing minimal reasoning. With the help of these, you can build more intelligent and dependable applications. 

From automating complex workflows to accelerating mundane workflows, GPT-5 is designed with tremendous flexibility and performance to allow developers to create. Examine and play with the features and capabilities in your projects in order to fully benefit from GPT-5.

Frequently Asked Questions

Q1. What’s the difference between GPT-5, GPT-5-mini, and GPT-5-nano?

A. GPT‑5 is the most powerful. GPT‑5-mini balances speed and cost. GPT‑5-nano is the cheapest and fastest, ideal for lightweight or real-time use cases.

Q2. How do I control output length or detail in GPT-5?

A. Use the verbosity parameter:
"low" = short
"medium" = balanced
"high" = detailed
Useful for tuning explanations, comments, or code structure.

Q3. Which API endpoint should I use with GPT-5?

A. Use the responses endpoint. It supports tool usage, structured reasoning, and advanced parameters, all through one unified interface. Recommended for most new applications.

Hello! I’m Vipin, a passionate data science and machine learning enthusiast with a strong foundation in data analysis, machine learning algorithms, and programming. I have hands-on experience in building models, managing messy data, and solving real-world problems. My goal is to apply data-driven insights to create practical solutions that drive results. I’m eager to contribute my skills in a collaborative environment while continuing to learn and grow in the fields of Data Science, Machine Learning, and NLP.

Login to continue reading and enjoy expert-curated content.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles