SpyBara
Go Premium

Documentation 2026-07-13 21:58 UTC to 2026-07-14 21:58 UTC

14 files changed +5,928 −85. View all changes and history on the product overview
2026
Wed 15 02:58 Tue 14 21:58 Mon 13 21:58 Sat 11 07:01 Fri 10 23:02 Thu 9 17:03 Wed 8 22:02 Mon 6 22:58 Sat 4 16:59
Details

4 4 

5Background mode kicks off these tasks asynchronously, and developers can poll response objects to check status over time. To start response generation in the background, make an API request with `background` set to `true`:5Background mode kicks off these tasks asynchronously, and developers can poll response objects to check status over time. To start response generation in the background, make an API request with `background` set to `true`:

6 6 

7Because background mode stores response data for roughly 10 minutes to enable7Background requests from Zero Data Retention (ZDR) projects run with

8 polling, it is not Zero Data Retention (ZDR) compatible. Requests from ZDR8 `store=false`. Response data is temporarily stored to disk for roughly 10

9 projects are still accepted with `background=true` for legacy reasons, but9 minutes to enable asynchronous execution and polling.

10 using it breaks ZDR guarantees. Modified Abuse Monitoring (MAM) projects can

11 safely rely on background mode.

12 10 

13Generate a response in the background11Generate a response in the background

14 12 


212 210 

213## Limits211## Limits

214 212 

2151. Background sampling requires `store=true`; stateless requests are rejected.2131. Background requests can use `store=false`, but response data is temporarily

214 stored to support asynchronous execution and polling.

2162. To cancel a synchronous response, terminate the connection2152. To cancel a synchronous response, terminate the connection

2173. You can only start a new stream from a background response if you created it with `stream=true`.2163. You can only start a new stream from a background response if you created it with `stream=true`.

Details

3| Contents | Expected impact |3| Contents | Expected impact |

4| ------------------------------------------------------------------------------- | ----------------------------------- |4| ------------------------------------------------------------------------------- | ----------------------------------- |

5| [Use the Responses API](#use-the-responses-api) | Quality, cost, latency, reliability |5| [Use the Responses API](#use-the-responses-api) | Quality, cost, latency, reliability |

6| [Choose a GPT-5.6 model](#choose-a-gpt-56-model) | Quality, cost, latency |

6| [Set up `reasoning.effort`](#set-up-reasoningeffort) | Quality, cost, latency |7| [Set up `reasoning.effort`](#set-up-reasoningeffort) | Quality, cost, latency |

7| [Set up `text.verbosity`](#set-up-textverbosity) | Quality, cost, latency |8| [Set up `text.verbosity`](#set-up-textverbosity) | Quality, cost, latency |

8| [Set up the assistant `phase` parameter](#set-up-the-assistant-phase-parameter) | Quality, cost |9| [Set up the assistant `phase` parameter](#set-up-the-assistant-phase-parameter) | Quality, cost |

9| [Use `tool_search`](#use-tool_search) | Cost, latency |10| [Use `tool_search`](#use-tool_search) | Cost, latency |

11| [Use Programmatic Tool Calling](#use-programmatic-tool-calling) | Quality, cost, latency |

12| [Use Multi-agent for parallel work](#use-multi-agent-for-parallel-work) | Quality, cost, latency |

10| [Leverage built-in tools](#leverage-built-in-tools) | Quality |13| [Leverage built-in tools](#leverage-built-in-tools) | Quality |

11| [Leverage compaction](#leverage-compaction) | Cost |14| [Leverage compaction](#leverage-compaction) | Cost |

12| [Use `prompt_cache_key`](#use-prompt_cache_key) | Latency, cost |15| [Use `prompt_cache_key`](#use-prompt_cache_key) | Latency, cost |

13| [Use `reasoning.encrypted_content`](#use-reasoningencrypted_content) | Quality, latency |16| [Use `reasoning.encrypted_content`](#use-reasoningencrypted_content) | Quality, latency |

17| [Set image detail intentionally](#set-image-detail-intentionally) | Quality, cost, latency |

18| [Send a safety identifier](#send-a-safety-identifier) | Safety, reliability |

14| [Use `background=True`](#use-backgroundtrue) | Resumability |19| [Use `background=True`](#use-backgroundtrue) | Resumability |

15| [Use WebSocket mode](#use-websocket-mode) | Latency |20| [Use WebSocket mode](#use-websocket-mode) | Latency |

16 21 


21API and the best place to access the newest model behavior, built-in tools,26API and the best place to access the newest model behavior, built-in tools,

22stateful workflows, and agent features.27stateful workflows, and agent features.

23 28 

29## Choose a GPT-5.6 model

30 

31Choose a [GPT-5.6 model](https://developers.openai.com/api/docs/guides/latest-model) for the workload instead

32of routing every request to the most capable tier. Use `gpt-5.6` or

33`gpt-5.6-sol` for frontier capability, `gpt-5.6-terra` for strong performance

34at a lower price, and `gpt-5.6-luna` for efficient, high-volume workloads.

35 

36When migrating, preserve the current model's workload role and effective

37reasoning effort for the first comparison. Run representative evals before

38changing prompts or adding new capabilities. Compare task success, latency,

39input, output, reasoning, and cache-write tokens, and cost per successful task.

40 

24## Set up `reasoning.effort`41## Set up `reasoning.effort`

25 42 

26Use `reasoning.effort` to decide how much thinking the model should do before it43Use `reasoning.effort` to decide how much thinking the model should do before it

27answers.44answers.

28 45 

29For `gpt-5.5`, the supported values are `none`, `low`, `medium`, `high`, and46For GPT-5.6 models, the supported values are `none`, `low`, `medium`, `high`,

30`xhigh`. The default is `medium`. Lower effort is faster and uses fewer47`xhigh`, and `max`. The default is `medium`. Lower effort is faster and uses

31reasoning tokens. Higher effort gives the model more time for planning,48fewer reasoning tokens. Higher effort gives the model more time for planning,

32debugging, synthesis, and multi-step tradeoffs. The right value depends on the49debugging, synthesis, and multi-step tradeoffs.

33**task**, not just the model.

34 50 

35Use `low` when the job is mostly extraction, routing, classification, or a51Use `low` when the job is mostly extraction, routing, classification, or a

36simple rewrite. Use `medium` or `high` when the model needs to diagnose a52simple rewrite. Use `medium` or `high` when the model needs to diagnose a

37problem, compare options, write a plan, or reason through code. Reserve `xhigh`53problem, compare options, write a plan, or reason through code. Use `xhigh` or

38for cases where your evals show the extra latency is worth it.54`max` only when representative evals show that the quality gain justifies the

55extra latency and cost. When migrating from GPT-5.5 or GPT-5.4, start with the

56current effort and compare the same setting with one level lower. GPT-5.6 can

57often maintain or improve quality with fewer reasoning tokens, so the lower

58setting may also reduce latency and cost.

59 

60For the hardest quality-first workloads, also compare

61[`reasoning.mode: "pro"`](https://developers.openai.com/api/docs/guides/reasoning#reasoning-mode) with

62standard mode at the same effort. Reasoning mode and effort are independent.

63Pro mode can improve reliability by applying more model work before returning a

64single final answer, but it increases latency and token usage.

39 65 

40Tune reasoning effort for the task66Tune reasoning effort for the task

41 67 


55 81 

56const response = await openai.responses.create({82const response = await openai.responses.create({

57 model: "gpt-5.6",83 model: "gpt-5.6",

58 reasoning: { effort: "high" },84 reasoning: { effort: "xhigh", mode: "pro" },

59 input: prompt,85 input: prompt,

60});86});

61 87 


78 104 

79response = client.responses.create(105response = client.responses.create(

80 model="gpt-5.6",106 model="gpt-5.6",

81 reasoning={"effort": "high"},107 reasoning={"effort": "xhigh", "mode": "pro"},

82 input=prompt,108 input=prompt,

83)109)

84 110 


97For coding, `medium` and `high` tend to produce longer, more organized output123For coding, `medium` and `high` tend to produce longer, more organized output

98with clearer structure. `low` keeps the answer tighter and more minimal.124with clearer structure. `low` keeps the answer tighter and more minimal.

99 125 

126GPT-5.6 tends to be more concise by default than GPT-5.5. When migrating, check

127whether broad instructions like "Be concise" still help. In some cases, they may

128make responses too brief. Keep them only when they still help, and prefer using

129`text.verbosity` to control the default level of detail; then use the prompt to

130specify required content, structure, and a more specific length, if applicable.

131 

100Set lower verbosity for compact output132Set lower verbosity for compact output

101 133 

102```javascript134```javascript


178 210 

179This is useful in long-running or tool-heavy workflows where the assistant may211This is useful in long-running or tool-heavy workflows where the assistant may

180produce visible progress updates before it finishes. When you send that history212produce visible progress updates before it finishes. When you send that history

181back to the model, preserve `phase` on assistant messages so the model can tell213back on follow-up requests for `gpt-5.3-codex` and later models,

182which messages are progress updates and which message is the final result.214**preserve and resend `phase`** on assistant messages so the model can distinguish

183 215progress updates from the final result. This helps reduce early stopping, making

184**Preserve and resend `phase`** on assistant messages on follow-up requests for216the agent more likely to continue until it reaches the final answer.

185new models like `gpt-5.3-codex` and later. It helps address early stopping,

186ensuring the agent runs until it reaches the final answer.

187 217 

188## Use `tool_search`218## Use `tool_search`

189 219 

190Instead of loading the full tool catalog into every request, add220Instead of loading the full tool catalog into every request, use

221[tool search](https://developers.openai.com/api/docs/guides/tools-tool-search): add

191`{"type": "tool_search"}` and mark expensive tool definitions with222`{"type": "tool_search"}` and mark expensive tool definitions with

192`defer_loading: true`. The model can then load the subset it needs at runtime.223`defer_loading: true`. The model can then load the subset it needs at runtime.

193At request start, the model only sees the search tool name and description. If224At request start, the model only sees the search tool name and description. If


222 253 

223const openai = new OpenAI();254const openai = new OpenAI();

224 255 

225const billingLookupInvoice = {256const billingNamespace = {

257 type: "namespace",

258 name: "billing",

259 description: "Billing tools for invoices, payments, taxes, and credits.",

260 tools: [

261 {

226 type: "function",262 type: "function",

227 name: "billing.lookup_invoice",263 name: "lookup_invoice",

228 description: "Look up invoice state, taxes, credits, and payment attempts.",264 description: "Look up invoice state, taxes, credits, and payment attempts.",

229 parameters: {265 parameters: {

230 type: "object",266 type: "object",


236 },272 },

237 strict: true,273 strict: true,

238 defer_loading: true,274 defer_loading: true,

275 },

276 ],

239};277};

240 278 

241const crmGetAccount = {279const crmNamespace = {

280 type: "namespace",

281 name: "crm",

282 description: "CRM tools for account ownership, plans, health, and payment history.",

283 tools: [

284 {

242 type: "function",285 type: "function",

243 name: "crm.get_account",286 name: "get_account",

244 description: "Fetch account owner, plan, health, and payment history.",287 description: "Fetch account owner, plan, health, and payment history.",

245 parameters: {288 parameters: {

246 type: "object",289 type: "object",


252 },295 },

253 strict: true,296 strict: true,

254 defer_loading: true,297 defer_loading: true,

298 },

299 ],

255};300};

256 301 

257const response = await openai.responses.create({302const response = await openai.responses.create({


259 input:304 input:

260 "Find the right billing tool and explain why invoice INV-1043 still " +305 "Find the right billing tool and explain why invoice INV-1043 still " +

261 "shows overdue after a payment yesterday.",306 "shows overdue after a payment yesterday.",

262 tools: [307 tools: [billingNamespace, crmNamespace, { type: "tool_search" }],

263 { type: "tool_search" },

264 billingLookupInvoice,

265 crmGetAccount,

266 ],

267});308});

268 309 

269console.log(response.output_text);310console.log(response.output);

270```311```

271 312 

272```python313```python


274 315 

275client = OpenAI()316client = OpenAI()

276 317 

277billing_lookup_invoice = {318billing_namespace = {

319 "type": "namespace",

320 "name": "billing",

321 "description": "Billing tools for invoices, payments, taxes, and credits.",

322 "tools": [

323 {

278 "type": "function",324 "type": "function",

279 "name": "billing.lookup_invoice",325 "name": "lookup_invoice",

280 "description": "Look up invoice state, taxes, credits, and payment attempts.",326 "description": "Look up invoice state, taxes, credits, and payment attempts.",

281 "parameters": {327 "parameters": {

282 "type": "object",328 "type": "object",


288 },334 },

289 "strict": True,335 "strict": True,

290 "defer_loading": True,336 "defer_loading": True,

337 }

338 ],

291}339}

292 340 

293crm_get_account = {341crm_namespace = {

342 "type": "namespace",

343 "name": "crm",

344 "description": "CRM tools for account ownership, plans, health, and payment history.",

345 "tools": [

346 {

294 "type": "function",347 "type": "function",

295 "name": "crm.get_account",348 "name": "get_account",

296 "description": "Fetch account owner, plan, health, and payment history.",349 "description": "Fetch account owner, plan, health, and payment history.",

297 "parameters": {350 "parameters": {

298 "type": "object",351 "type": "object",


304 },357 },

305 "strict": True,358 "strict": True,

306 "defer_loading": True,359 "defer_loading": True,

360 }

361 ],

307}362}

308 363 

309response = client.responses.create(364response = client.responses.create(


312 "Find the right billing tool and explain why invoice INV-1043 still "367 "Find the right billing tool and explain why invoice INV-1043 still "

313 "shows overdue after a payment yesterday."368 "shows overdue after a payment yesterday."

314 ),369 ),

315 tools=[370 tools=[billing_namespace, crm_namespace, {"type": "tool_search"}],

316 {"type": "tool_search"},

317 billing_lookup_invoice,

318 crm_get_account,

319 ],

320)371)

321 372 

322print(response.output_text)373print(response.output)

323```374```

324 375 

325 376 

377## Use Programmatic Tool Calling

378 

379[Programmatic Tool Calling](https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling)

380lets GPT-5.6 write JavaScript that calls eligible tools and reduces their

381intermediate results inside a hosted runtime. Use it for bounded stages where

382code can filter, join, rank, remove duplicates, combine, or check large tool

383results before returning a smaller structured result to the model.

384 

385Add the `programmatic_tool_calling` tool and opt in each eligible tool. Use

386`allowed_callers: ["programmatic"]` for program-only tools, or use

387`allowed_callers: ["direct", "programmatic"]` when the model may also call the

388tool directly. Keep calls direct when each result may change the model's next

389decision, an action requires approval, or the final answer must preserve

390citations or native artifacts. Document tool return fields and error behavior so

391the model can write a correct program without first inspecting a result.

392 

393Your tool loop must handle `program` and `program_output` items, as well as

394program-issued `function_call` items and their `function_call_output` items.

395Preserve each `call_id`, and copy the function call's `caller` into its output so

396the service can resume the correct program.

397 

398Test both the `program_output` and the final assistant message. A correct program

399result can still become an incomplete final answer. Compare task success,

400required evidence, total tokens, latency, and cost against the same workflow

401using direct tool calls.

402 

403## Use Multi-agent for parallel work

404 

405[Multi-agent](https://developers.openai.com/api/docs/guides/responses-multi-agent) is a GPT-5.6 feature that

406lets a root agent delegate independent workstreams to subagents and synthesize

407their results. Use it when you can split research, analysis, or implementation

408into concrete, bounded tasks that use separate context and run in parallel.

409 

410Set `multi_agent.enabled` to `true` in the request. For HTTP, use the beta

411Responses SDK with `client.beta.responses` and pass `responses_multi_agent=v1`

412in `betas`. For raw HTTP or WebSocket connections, send

413`OpenAI-Beta: responses_multi_agent=v1`. Item schemas can change while

414Multi-agent is in beta.

415 

416Prefer one agent for short tasks, ordered chains where each step depends on the

417last, or work that writes to the same mutable resource. Subagents can increase

418token usage, so start with the default `max_concurrent_subagents` value of `3`

419and measure end-to-end quality, latency, and cost. For tool-heavy or long-running

420Multi-agent workflows, WebSocket mode can reduce continuation overhead.

421 

422Before enabling Multi-agent, account for its current limitations:

423`/responses/compact`, `reasoning.summary`, and `max_tool_calls` are not

424supported. The server automatically compacts the root context and every

425subagent context.

426 

326## Leverage built-in tools427## Leverage built-in tools

327 428 

328[Built-in tools](https://developers.openai.com/api/docs/guides/tools) are the API's native capabilities.429[Built-in tools](https://developers.openai.com/api/docs/guides/tools) are the API's native capabilities.


455and cost when requests reuse the same long prefix. For high-volume workflows,556and cost when requests reuse the same long prefix. For high-volume workflows,

456set557set

457[`prompt_cache_key`](https://developers.openai.com/api/docs/api-reference/responses/create#responses-create-prompt_cache_key)558[`prompt_cache_key`](https://developers.openai.com/api/docs/api-reference/responses/create#responses-create-prompt_cache_key)

458consistently for requests that share the same stable prefix.559consistently for requests that share the same stable prefix. The service

459 560combines the key with the prompt prefix hash to help route similar requests to

460The cache key is combined with the prompt prefix hash, so it helps route similar561the same cache without changing the model input. Keep the key stable for

461requests to the same cache without changing the model input. Keep the key stable562genuinely shared prefixes, choose a granularity that avoids sending too much

462for genuinely shared prefixes, and choose a granularity that avoids sending too563traffic to one key, and keep total traffic across the prefixes for each key to

463much traffic to one prefix-key pair. If one prefix and `prompt_cache_key`564about 15 requests per minute. Partition higher-volume traffic across more keys

464combination exceeds about 15 requests per minute, requests may overflow to565with a stable mapping.

465additional machines and reduce cache effectiveness.566 

567GPT-5.6 introduced explicit prompt caching. Implicit caching remains the

568default, but GPT-5.6 models and later model families also support explicit

569cache breakpoints and request-wide cache policy. On those models, set

570`prompt_cache_key` to use the more reliable matching for both implicit caching

571and explicit breakpoints. If a changing suffix comes after a stable prefix, add

572an explicit `prompt_cache_breakpoint` at the reusable boundary. Set

573`prompt_cache_options.mode` to `explicit` only when the request should use only

574the breakpoints you provide and no implicit breakpoint. Earlier models continue

575to use automatic prompt caching only.

576 

577On GPT-5.6 models and later model families, cache writes cost 1.25× the

578uncached input token rate. Log `cached_tokens` and `cache_write_tokens`, then

579compare write volume with later cache reads to measure net cost and tune key

580granularity and breakpoint placement.

466 581 

467Route related requests to the same prompt cache582Route related requests to the same prompt cache

468 583 


511 626 

512## Use `reasoning.encrypted_content`627## Use `reasoning.encrypted_content`

513 628 

514Always round-trip reasoning items. This helps the model by allowing it to work629GPT-5.6 can [preserve reasoning across

515from its prior reasoning. If your [Zero Data Retention630calls](https://developers.openai.com/api/docs/guides/reasoning#preserve-reasoning-across-calls). Use

631`reasoning.context: "all_turns"` when the task's goals, assumptions, and

632priorities remain stable. Use `current_turn` when earlier reasoning is no longer

633relevant and might anchor the model to an outdated approach. If you omit

634`reasoning.context` or set it to `auto`, inspect the response's

635`reasoning.context` field to confirm the effective mode.

636 

637[Persisted reasoning](https://developers.openai.com/api/docs/guides/reasoning#keeping-reasoning-items-in-context)

638works only when earlier reasoning items are available. Use `previous_response_id`

639for stored responses. If your [Zero Data Retention

516(ZDR)](https://developers.openai.com/api/docs/guides/your-data#zero-data-retention) requirements do not allow640(ZDR)](https://developers.openai.com/api/docs/guides/your-data#zero-data-retention) requirements do not allow

517storing response data, this is where `reasoning.encrypted_content` is important.641storing response data, use `reasoning.encrypted_content` for a stateless handoff.

518`reasoning.encrypted_content` gives you a stateless handoff.

519 642 

520Add `reasoning.encrypted_content` to `include`, and reasoning items in the643Add `reasoning.encrypted_content` to `include`, and reasoning items in the

521response output will include encrypted reasoning content that can be passed back644response output will include encrypted reasoning content that can be passed back


530 653 

531const openai = new OpenAI();654const openai = new OpenAI();

532 655 

656const history = [

657 {

658 role: "user",

659 content: "Investigate why invoice INV-1043 has mismatched tax totals.",

660 },

661];

662 

533const first = await openai.responses.create({663const first = await openai.responses.create({

534 model: "gpt-5.6",664 model: "gpt-5.6",

535 store: false,665 store: false,

536 reasoning: { effort: "medium" },666 reasoning: { effort: "medium", context: "current_turn" },

537 include: ["reasoning.encrypted_content"],667 include: ["reasoning.encrypted_content"],

538 input: "Investigate why invoice INV-1043 has mismatched tax totals.",668 input: history,

669});

670 

671history.push(...first.output);

672history.push({

673 role: "user",

674 content: "Now write the customer-facing explanation in plain English.",

539});675});

540 676 

541const second = await openai.responses.create({677const second = await openai.responses.create({

542 model: "gpt-5.6",678 model: "gpt-5.6",

543 store: false,679 store: false,

544 reasoning: { effort: "medium" },680 reasoning: { effort: "medium", context: "all_turns" },

545 include: ["reasoning.encrypted_content"],681 include: ["reasoning.encrypted_content"],

546 input: [682 input: history,

547 ...first.output,

548 {

549 role: "user",

550 content: "Now write the customer-facing explanation in plain English.",

551 },

552 ],

553});683});

554 684 

555console.log(second.output_text);685console.log(second.output_text);


560 690 

561client = OpenAI()691client = OpenAI()

562 692 

693history = [

694 {

695 "role": "user",

696 "content": "Investigate why invoice INV-1043 has mismatched tax totals.",

697 }

698]

699 

563first = client.responses.create(700first = client.responses.create(

564 model="gpt-5.6",701 model="gpt-5.6",

565 store=False,702 store=False,

566 reasoning={"effort": "medium"},703 reasoning={"effort": "medium", "context": "current_turn"},

567 include=["reasoning.encrypted_content"],704 include=["reasoning.encrypted_content"],

568 input="Investigate why invoice INV-1043 has mismatched tax totals.",705 input=history,

706)

707 

708history.extend(item.model_dump(exclude={"status"}) for item in first.output)

709history.append(

710 {

711 "role": "user",

712 "content": "Now write the customer-facing explanation in plain English.",

713 }

569)714)

570 715 

571second = client.responses.create(716second = client.responses.create(

572 model="gpt-5.6",717 model="gpt-5.6",

573 store=False,718 store=False,

574 reasoning={"effort": "medium"},719 reasoning={"effort": "medium", "context": "all_turns"},

575 include=["reasoning.encrypted_content"],720 include=["reasoning.encrypted_content"],

576 input=[721 input=history,

577 *first.output,

578 {

579 "role": "user",

580 "content": "Now write the customer-facing explanation in plain English.",

581 },

582 ],

583)722)

584 723 

585print(second.output_text)724print(second.output_text)

586```725```

587 726 

588 727 

728## Set image detail intentionally

729 

730On GPT-5.6 models, omitted image `detail` and `detail: "auto"` use the same

731sizing behavior as `original`. The service preserves the input dimensions

732instead of resizing the image to a patch budget or pixel-dimension limit. Large

733images can use more input tokens and add latency as a result.

734 

735Choose [`detail`](https://developers.openai.com/api/docs/guides/images-vision#choose-an-image-detail-level)

736for the task. Resize the image, use `low` when fine visual detail is not

737important, or use `high` for standard high-fidelity image understanding. Keep

738`original` for large, dense, coordinate-sensitive, OCR, localization, or

739visual-inspection tasks where the extra detail improves quality. Measure

740worst-case image tokens and latency before deployment.

741 

742## Send a safety identifier

743 

744If your application serves individual end users, send a stable,

745privacy-preserving

746[`safety_identifier`](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers)

747with each request. It helps OpenAI detect misuse and gives your team a stable way

748to trace policy violations. It also reduces the chance that one user's misuse

749disrupts access for your broader organization.

750 

751Hash the user's username or email address instead of sending identifying

752information. For logged-out experiences, use a stable session ID.

753 

589## Use `background=True`754## Use `background=True`

590 755 

591Use [`background=True`](https://developers.openai.com/api/docs/guides/background) for requests that may take756Use [`background=True`](https://developers.openai.com/api/docs/guides/background) for requests that may take


594canceled. Use it for large analyses, long tool runs, or work that needs status759canceled. Use it for large analyses, long tool runs, or work that needs status

595and retry behavior.760and retry behavior.

596 761 

597`background=True` **requires `store=True`**.

598 

599Run and poll a background response762Run and poll a background response

600 763 

601```javascript764```javascript


606let job = await openai.responses.create({769let job = await openai.responses.create({

607 model: "gpt-5.6",770 model: "gpt-5.6",

608 background: true,771 background: true,

609 store: true,772 store: false,

610 input: "Analyze this large log bundle and cluster the primary failure modes.",773 input: "Analyze this large log bundle and cluster the primary failure modes.",

611 tools: [774 tools: [

612 {775 {


636job = client.responses.create(799job = client.responses.create(

637 model="gpt-5.6",800 model="gpt-5.6",

638 background=True,801 background=True,

639 store=True,802 store=False,

640 input="Analyze this large log bundle and cluster the primary failure modes.",803 input="Analyze this large log bundle and cluster the primary failure modes.",

641 tools=[804 tools=[

642 {805 {


663From the UI perspective, background mode indicates, "This is running; here is826From the UI perspective, background mode indicates, "This is running; here is

664the status; the result will appear here when it's ready."827the status; the result will appear here when it's ready."

665 828 

666Note: `background=True` is not compatible with [Zero Data

667Retention](https://developers.openai.com/api/docs/guides/your-data#zero-data-retention).

668 

669## Use WebSocket mode829## Use WebSocket mode

670 830 

671[WebSocket mode](https://developers.openai.com/api/docs/guides/websocket-mode) is built for long-running,831[WebSocket mode](https://developers.openai.com/api/docs/guides/websocket-mode) is built for long-running,

guides/latest-model/gpt-4.1.md +1205 −0 created

Details

1# Using GPT-4.1

2 

3## Introduction

4 

5The GPT-4.1 family of models represents a significant step forward from GPT-4o in capabilities across coding, instruction following, and long context. In this prompting guide, we collate a series of important prompting tips derived from extensive internal testing to help developers fully leverage the improved abilities of this new model family.

6 

7Many typical best practices still apply to GPT-4.1, such as providing context examples, making instructions as specific and clear as possible, and inducing planning via prompting to maximize model intelligence. However, we expect that getting the most out of this model will require some prompt migration. GPT-4.1 is trained to follow instructions more closely and more literally than its predecessors, which tended to more liberally infer intent from user and system prompts. This also means, however, that GPT-4.1 is highly steerable and responsive to well-specified prompts - if model behavior is different from what you expect, a single sentence firmly and unequivocally clarifying your desired behavior is almost always sufficient to steer the model on course.

8 

9Please read on for prompt examples you can use as a reference, and remember that while this guidance is widely applicable, no advice is one-size-fits-all. AI engineering is inherently an empirical discipline, and large language models are inherently nondeterministic; in addition to following this guide, we advise building informative evals and iterating often to ensure your prompt engineering changes are yielding benefits for your use case.

10 

11## What's new

12 

13- Closer and more literal instruction following than previous GPT models

14- Stronger coding and long-context behavior

15- Better API-native tool use when schemas are passed through the `tools` field

16- Prompt migration guidance for agentic workflows and diff generation

17 

18## Migration quickstart

19 

20- Update the model slug to `gpt-4.1`.

21- Use either the Responses API or Chat Completions API, depending on your integration.

22- Remove reasoning-specific parameters; GPT-4.1 is a non-reasoning model.

23- Pass tool schemas through the API `tools` field instead of injecting tool definitions into the prompt.

24- Review prompts for literal instruction following, add explicit persistence and tool-use rules where needed, and validate changes with evals.

25 

26## Model, API, and feature updates

27 

28- The GPT-4.1 family includes `gpt-4.1`, `gpt-4.1-mini`, and `gpt-4.1-nano`.

29- GPT-4.1 has a 1M-token context window and low latency without a reasoning step.

30- The family supports the Responses API and Chat Completions API.

31- GPT-4.1 and GPT-4.1 mini support supervised fine-tuning.

32- Supported tools include function calling, web search, file search, image generation, code interpreter, and remote MCP.

33 

34 

35## Prompting best practices

36 

37### 1. Agentic Workflows

38 

39GPT-4.1 is a great place to build agentic workflows. In model training we emphasized providing a diverse range of agentic problem-solving trajectories, and our agentic harness for the model achieves state-of-the-art performance for non-reasoning models on SWE-bench Verified, solving 55% of problems.

40 

41### System Prompt Reminders

42 

43In order to fully utilize the agentic capabilities of GPT-4.1, we recommend including three key types of reminders in all agent prompts. The following prompts are optimized specifically for the agentic coding workflow, but can be easily modified for general agentic use cases.

44 

451. Persistence: this ensures the model understands it is entering a multi-message turn, and prevents it from prematurely yielding control back to the user. Our example is the following:

46 

47```text

48You are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved.

49```

50 

512. Tool-calling: this encourages the model to make full use of its tools, and reduces its likelihood of hallucinating or guessing an answer. Our example is the following:

52 

53```text

54If you are not sure about file content or codebase structure pertaining to the user’s request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.

55```

56 

573. Planning \[optional\]: if desired, this ensures the model explicitly plans and reflects upon each tool call in text, instead of completing the task by chaining together a series of only tool calls. Our example is the following:

58 

59```text

60You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.

61```

62 

63GPT-4.1 is trained to respond very closely to both user instructions and system prompts in the agentic setting. The model adhered closely to these three simple instructions and increased our internal SWE-bench Verified score by close to 20% \- so we highly encourage starting any agent prompt with clear reminders covering the three categories listed above. As a whole, we find that these three instructions transform the model from a chatbot-like state into a much more “eager” agent, driving the interaction forward autonomously and independently.

64 

65### Tool Calls

66 

67Compared to previous models, GPT-4.1 has undergone more training on effectively utilizing tools passed as arguments in an OpenAI API request. We encourage developers to exclusively use the tools field to pass tools, rather than manually injecting tool descriptions into your prompt and writing a separate parser for tool calls, as some have reported doing in the past. This is the best way to minimize errors and ensure the model remains in distribution during tool-calling trajectories \- in our own experiments, we observed a 2% increase in SWE-bench Verified pass rate when using API-parsed tool descriptions versus manually injecting the schemas into the system prompt.

68 

69Developers should name tools clearly to indicate their purpose and add a clear, detailed description in the "description" field of the tool. Similarly, for each tool param, lean on good naming and descriptions to ensure appropriate usage. If your tool is particularly complicated and you'd like to provide examples of tool usage, we recommend that you create an `# Examples` section in your system prompt and place the examples there, rather than adding them into the "description" field, which should remain thorough but relatively concise. Providing examples can be helpful to indicate when to use tools, whether to include user text alongside tool calls, and what parameters are appropriate for different inputs. Remember that you can use “Generate Anything” in the [Prompt Playground](https://platform.openai.com/playground) to get a good starting point for your new tool definitions.

70 

71### Prompting-Induced Planning & Chain-of-Thought

72 

73As mentioned already, developers can optionally prompt agents built with GPT-4.1 to plan and reflect between tool calls, instead of silently calling tools in an unbroken sequence. GPT-4.1 is not a reasoning model \- meaning that it does not produce an internal chain of thought before answering \- but in the prompt, a developer can induce the model to produce an explicit, step-by-step plan by using any variant of the Planning prompt component shown above. This can be thought of as the model “thinking out loud.” In our experimentation with the SWE-bench Verified agentic task, inducing explicit planning increased the pass rate by 4%.

74 

75### Sample Prompt: SWE-bench Verified

76 

77Below, we share the agentic prompt that we used to achieve our highest score on SWE-bench Verified, which features detailed instructions about workflow and problem-solving strategy. This general pattern can be used for any agentic task.

78 

79```python

80from openai import OpenAI

81import os

82 

83client = OpenAI(

84 api_key=os.environ.get(

85 "OPENAI_API_KEY", "<your OpenAI API key if not set as env var>"

86 )

87)

88 

89SYS_PROMPT_SWEBENCH = """

90You will be tasked to fix an issue from an open-source repository.

91 

92Your thinking should be thorough and so it's fine if it's very long. You can think step by step before and after each action you decide to take.

93 

94You MUST iterate and keep going until the problem is solved.

95 

96You already have everything you need to solve this problem in the /testbed folder, even without internet connection. I want you to fully solve this autonomously before coming back to me.

97 

98Only terminate your turn when you are sure that the problem is solved. Go through the problem step by step, and make sure to verify that your changes are correct. NEVER end your turn without having solved the problem, and when you say you are going to make a tool call, make sure you ACTUALLY make the tool call, instead of ending your turn.

99 

100THE PROBLEM CAN DEFINITELY BE SOLVED WITHOUT THE INTERNET.

101 

102Take your time and think through every step - remember to check your solution rigorously and watch out for boundary cases, especially with the changes you made. Your solution must be perfect. If not, continue working on it. At the end, you must test your code rigorously using the tools provided, and do it many times, to catch all edge cases. If it is not robust, iterate more and make it perfect. Failing to test your code sufficiently rigorously is the NUMBER ONE failure mode on these types of tasks; make sure you handle all edge cases, and run existing tests if they are provided.

103 

104You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.

105 

106# Workflow

107 

108## High-Level Problem Solving Strategy

109 

1101. Understand the problem deeply. Carefully read the issue and think critically about what is required.

1112. Investigate the codebase. Explore relevant files, search for key functions, and gather context.

1123. Develop a clear, step-by-step plan. Break down the fix into manageable, incremental steps.

1134. Implement the fix incrementally. Make small, testable code changes.

1145. Debug as needed. Use debugging techniques to isolate and resolve issues.

1156. Test frequently. Run tests after each change to verify correctness.

1167. Iterate until the root cause is fixed and all tests pass.

1178. Reflect and validate comprehensively. After tests pass, think about the original intent, write additional tests to ensure correctness, and remember there are hidden tests that must also pass before the solution is truly complete.

118 

119Refer to the detailed sections below for more information on each step.

120 

121## 1. Deeply Understand the Problem

122Carefully read the issue and think hard about a plan to solve it before coding.

123 

124## 2. Codebase Investigation

125- Explore relevant files and directories.

126- Search for key functions, classes, or variables related to the issue.

127- Read and understand relevant code snippets.

128- Identify the root cause of the problem.

129- Validate and update your understanding continuously as you gather more context.

130 

131## 3. Develop a Detailed Plan

132- Outline a specific, simple, and verifiable sequence of steps to fix the problem.

133- Break down the fix into small, incremental changes.

134 

135## 4. Making Code Changes

136- Before editing, always read the relevant file contents or section to ensure complete context.

137- If a patch is not applied correctly, attempt to reapply it.

138- Make small, testable, incremental changes that logically follow from your investigation and plan.

139 

140## 5. Debugging

141- Make code changes only if you have high confidence they can solve the problem

142- When debugging, try to determine the root cause rather than addressing symptoms

143- Debug for as long as needed to identify the root cause and identify a fix

144- Use print statements, logs, or temporary code to inspect program state, including descriptive statements or error messages to understand what's happening

145- To test hypotheses, you can also add test statements or functions

146- Revisit your assumptions if unexpected behavior occurs.

147 

148## 6. Testing

149- Run tests frequently using `!python3 run_tests.py` (or equivalent).

150- After each change, verify correctness by running relevant tests.

151- If tests fail, analyze failures and revise your patch.

152- Write additional tests if needed to capture important behaviors or edge cases.

153- Ensure all tests pass before finalizing.

154 

155## 7. Final Verification

156- Confirm the root cause is fixed.

157- Review your solution for logic correctness and robustness.

158- Iterate until you are extremely confident the fix is complete and all tests pass.

159 

160## 8. Final Reflection and Additional Testing

161- Reflect carefully on the original intent of the user and the problem statement.

162- Think about potential edge cases or scenarios that may not be covered by existing tests.

163- Write additional tests that would need to pass to fully validate the correctness of your solution.

164- Run these new tests and ensure they all pass.

165- Be aware that there are additional hidden tests that must also pass for the solution to be successful.

166- Do not assume the task is complete just because the visible tests pass; continue refining until you are confident the fix is robust and comprehensive.

167"""

168 

169PYTHON_TOOL_DESCRIPTION = """This function is used to execute Python code or terminal commands in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 60.0 seconds. Internet access for this session is disabled. Do not make external web requests or API calls as they will fail. Just as in a Jupyter notebook, you may also execute terminal commands by calling this function with a terminal command, prefaced with an exclamation mark.

170 

171In addition, for the purposes of this task, you can call this function with an `apply_patch` command as input. `apply_patch` effectively allows you to execute a diff/patch against a file, but the format of the diff specification is unique to this task, so pay careful attention to these instructions. To use the `apply_patch` command, you should pass a message of the following structure as "input":

172 

173%%bash

174apply_patch <<"EOF"

175*** Begin Patch

176[YOUR_PATCH]

177*** End Patch

178EOF

179 

180Where [YOUR_PATCH] is the actual content of your patch, specified in the following V4A diff format.

181 

182*** [ACTION] File: [path/to/file] -> ACTION can be one of Add, Update, or Delete.

183For each snippet of code that needs to be changed, repeat the following:

184[context_before] -> See below for further instructions on context.

185- [old_code] -> Precede the old code with a minus sign.

186+ [new_code] -> Precede the new, replacement code with a plus sign.

187[context_after] -> See below for further instructions on context.

188 

189For instructions on [context_before] and [context_after]:

190- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change's [context_after] lines in the second change's [context_before] lines.

191- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:

192@@ class BaseClass

193[3 lines of pre-context]

194- [old_code]

195+ [new_code]

196[3 lines of post-context]

197 

198- If a code block is repeated so many times in a class or function such that even a single @@ statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:

199 

200@@ class BaseClass

201@@ def method():

202[3 lines of pre-context]

203- [old_code]

204+ [new_code]

205[3 lines of post-context]

206 

207Note, then, that we do not use line numbers in this diff format, as the context is enough to uniquely identify code. An example of a message that you might pass as "input" to this function, in order to apply a patch, is shown below.

208 

209%%bash

210apply_patch <<"EOF"

211*** Begin Patch

212*** Update File: pygorithm/searching/binary_search.py

213@@ class BaseClass

214@@ def search():

215- pass

216+ raise NotImplementedError()

217 

218@@ class Subclass

219@@ def search():

220- pass

221+ raise NotImplementedError()

222 

223*** End Patch

224EOF

225 

226File references can only be relative, NEVER ABSOLUTE. After the apply_patch command is run, Python will always say "Done!", regardless of whether the patch was successfully applied or not. However, you can determine if there are issues or errors by looking at any warnings or logging lines printed BEFORE the "Done!" is output.

227"""

228 

229python_bash_patch_tool = {

230 "type": "function",

231 "name": "python",

232 "description": PYTHON_TOOL_DESCRIPTION,

233 "parameters": {

234 "type": "object",

235 "strict": True,

236 "properties": {

237 "input": {

238 "type": "string",

239 "description": " The Python code, terminal command (prefaced by exclamation mark), or apply_patch command that you wish to execute.",

240 }

241 },

242 "required": ["input"],

243 },

244}

245 

246# Additional harness setup:

247# - Add your repo to /testbed

248# - Add your issue to the first user message

249# - Note: Even though we used a single tool for python, bash, and apply_patch, we generally recommend defining more granular tools that are focused on a single function

250 

251response = client.responses.create(

252 instructions=SYS_PROMPT_SWEBENCH,

253 model="gpt-4.1-2025-04-14",

254 tools=[python_bash_patch_tool],

255 input=f"Please answer the following question:\nBug: Typerror..."

256)

257 

258response.to_dict()["output"]

259```

260 

261```text

262[{'id': 'msg_67fe92df26ac819182ffafce9ff4e4fc07c7e06242e51f8b',

263 'content': [{'annotations': [],

264 'text': "Thank you for the report, but “Typerror” is too vague for me to start debugging right away.\n\n**To make progress, I need to:**\n1. Find the exact error message text (e.g. `'TypeError: ...'`).\n2. Find which file and which line/function/class the error occurred in.\n3. Figure out what triggered the error (test file, usage, reproduction steps).\n4. Find the root cause and details.\n\n**Next steps:**\n- Investigate error/log/test output files for a Python `TypeError` message.\n- Examine the relevant code sections for problematic type usage.\n- If possible, reproduce the bug locally.\n\n**Plan:**\n- First, I will search for test files and log output in the `/testbed` directory that may contain the full error message and stack trace.\n\nLet’s start by listing the contents of the `/testbed` directory to look for clues.",

265 'type': 'output_text'}],

266 'role': 'assistant',

267 'status': 'completed',

268 'type': 'message'},

269 {'arguments': '{"input":"!ls -l /testbed"}',

270 'call_id': 'call_frnxyJgKi5TsBem0nR9Zuzdw',

271 'name': 'python',

272 'type': 'function_call',

273 'id': 'fc_67fe92e3da7081918fc18d5c96dddc1c07c7e06242e51f8b',

274 'status': 'completed'}]

275```

276 

277### 2. Long context

278 

279GPT-4.1 has a performant 1M token input context window, and is useful for a variety of long context tasks, including structured document parsing, re-ranking, selecting relevant information while ignoring irrelevant context, and performing multi-hop reasoning using context.

280 

281### Optimal Context Size

282 

283We observe very good performance on needle-in-a-haystack evaluations up to our full 1M token context, and we’ve observed very strong performance at complex tasks with a mix of both relevant and irrelevant code and other documents. However, long context performance can degrade as more items are required to be retrieved, or perform complex reasoning that requires knowledge of the state of the entire context (like performing a graph search, for example).

284 

285### Tuning Context Reliance

286 

287Consider the mix of external vs. internal world knowledge that might be required to answer your question. Sometimes it’s important for the model to use some of its own knowledge to connect concepts or make logical jumps, while in others it’s desirable to only use provided context

288 

289```text

290# Instructions

291// for internal knowledge

292- Only use the documents in the provided External Context to answer the User Query. If you don't know the answer based on this context, you must respond "I don't have the information needed to answer that", even if a user insists on you answering the question.

293// For internal and external knowledge

294- By default, use the provided external context to answer the User Query, but if other basic knowledge is needed to answer, and you're confident in the answer, you can use some of your own knowledge to help answer the question.

295```

296 

297### Prompt Organization

298 

299Especially in long context usage, placement of instructions and context can impact performance. If you have long context in your prompt, ideally place your instructions at both the beginning and end of the provided context, as we found this to perform better than only above or below. If you’d prefer to only have your instructions once, then above the provided context works better than below.

300 

301### 3. Chain of Thought

302 

303As mentioned above, GPT-4.1 is not a reasoning model, but prompting the model to think step by step (called “chain of thought”) can be an effective way for a model to break down problems into more manageable pieces, solve them, and improve overall output quality, with the tradeoff of higher cost and latency associated with using more output tokens. The model has been trained to perform well at agentic reasoning about and real-world problem solving, so it shouldn’t require much prompting to perform well.

304 

305We recommend starting with this basic chain-of-thought instruction at the end of your prompt:

306 

307```text

308...

309 

310First, think carefully step by step about what documents are needed to answer the query. Then, print out the TITLE and ID of each document. Then, format the IDs into a list.

311```

312 

313From there, you should improve your chain-of-thought (CoT) prompt by auditing failures in your particular examples and evals, and addressing systematic planning and reasoning errors with more explicit instructions. In the unconstrained CoT prompt, there may be variance in the strategies it tries, and if you observe an approach that works well, you can codify that strategy in your prompt. Generally speaking, errors tend to occur from misunderstanding user intent, insufficient context gathering or analysis, or insufficient or incorrect step by step thinking, so watch out for these and try to address them with more opinionated instructions.

314 

315Here is an example prompt instructing the model to focus more methodically on analyzing user intent and considering relevant context before proceeding to answer.

316 

317```text

318# Reasoning Strategy

3191. Query Analysis: Break down and analyze the query until you're confident about what it might be asking. Consider the provided context to help clarify any ambiguous or confusing information.

3202. Context Analysis: Carefully select and analyze a large set of potentially relevant documents. Optimize for recall - it's okay if some are irrelevant, but the correct documents must be in this list, otherwise your final answer will be wrong. Analysis steps for each:

321 a. Analysis: An analysis of how it may or may not be relevant to answering the query.

322 b. Relevance rating: [high, medium, low, none]

3233. Synthesis: summarize which documents are most relevant and why, including all documents with a relevance rating of medium or higher.

324 

325# User Question

326{user_question}

327 

328# External Context

329{external_context}

330 

331First, think carefully step by step about what documents are needed to answer the query, closely adhering to the provided Reasoning Strategy. Then, print out the TITLE and ID of each document. Then, format the IDs into a list.

332```

333 

334### 4. Instruction Following

335 

336GPT-4.1 exhibits outstanding instruction-following performance, which developers can leverage to precisely shape and control the outputs for their particular use cases. Developers often extensively prompt for agentic reasoning steps, response tone and voice, tool calling information, output formatting, topics to avoid, and more. However, since the model follows instructions more literally, developers may need to include explicit specification around what to do or not to do. Furthermore, existing prompts optimized for other models may not immediately work with this model, because existing instructions are followed more closely and implicit rules are no longer being as strongly inferred.

337 

338### Recommended Workflow

339 

340Here is our recommended workflow for developing and debugging instructions in prompts:

341 

3421. Start with an overall “Response Rules” or “Instructions” section with high-level guidance and bullet points.

3432. If you’d like to change a more specific behavior, add a section to specify more details for that category, like `# Sample Phrases`.

3443. If there are specific steps you’d like the model to follow in its workflow, add an ordered list and instruct the model to follow these steps.

3454. If behavior still isn’t working as expected:

346 1. Check for conflicting, underspecified, or wrong instructions and examples. If there are conflicting instructions, GPT-4.1 tends to follow the one closer to the end of the prompt.

347 2. Add examples that demonstrate desired behavior; ensure that any important behavior demonstrated in your examples are also cited in your rules.

348 3. It’s generally not necessary to use all-caps or other incentives like bribes or tips. We recommend starting without these, and only reaching for these if necessary for your particular prompt. Note that if your existing prompts include these techniques, it could cause GPT-4.1 to pay attention to it too strictly.

349 

350_Note that using your preferred AI-powered IDE can be very helpful for iterating on prompts, including checking for consistency or conflicts, adding examples, or making cohesive updates like adding an instruction and updating instructions to demonstrate that instruction._

351 

352### Common Failure Modes

353 

354These failure modes are not unique to GPT-4.1, but we share them here for general awareness and ease of debugging.

355 

356- Instructing a model to always follow a specific behavior can occasionally induce adverse effects. For instance, if told “you must call a tool before responding to the user,” models may hallucinate tool inputs or call the tool with null values if they do not have enough information. Adding “if you don’t have enough information to call the tool, ask the user for the information you need” should mitigate this.

357- When provided sample phrases, models can use those quotes verbatim and start to sound repetitive to users. Ensure you instruct the model to vary them as necessary.

358- Without specific instructions, some models can be eager to provide additional prose to explain their decisions, or output more formatting in responses than may be desired. Provide instructions and potentially examples to help mitigate.

359 

360### Example Prompt: Customer Service

361 

362This demonstrates best practices for a fictional customer service agent. Observe the diversity of rules, the specificity, the use of additional sections for greater detail, and an example to demonstrate precise behavior that incorporates all prior rules.

363 

364Try running the following notebook cell - you should see both a user message and tool call, and the user message should start with a greeting, then echo back their answer, then mention they're about to call a tool. Try changing the instructions to shape the model behavior, or trying other user messages, to test instruction following performance.

365 

366```python

367SYS_PROMPT_CUSTOMER_SERVICE = """You are a helpful customer service agent working for NewTelco, helping a user efficiently fulfill their request while adhering closely to provided guidelines.

368 

369# Instructions

370- Always greet the user with "Hi, you've reached NewTelco, how can I help you?"

371- Always call a tool before answering factual questions about the company, its offerings or products, or a user's account. Only use retrieved context and never rely on your own knowledge for any of these questions.

372 - However, if you don't have enough information to properly call the tool, ask the user for the information you need.

373- Escalate to a human if the user requests.

374- Do not discuss prohibited topics (politics, religion, controversial current events, medical, legal, or financial advice, personal conversations, internal company operations, or criticism of any people or company).

375- Rely on sample phrases whenever appropriate, but never repeat a sample phrase in the same conversation. Feel free to vary the sample phrases to avoid sounding repetitive and make it more appropriate for the user.

376- Always follow the provided output format for new messages, including citations for any factual statements from retrieved policy documents.

377- If you're going to call a tool, always message the user with an appropriate message before and after calling the tool.

378- Maintain a professional and concise tone in all responses, and use emojis between sentences.

379- If you've resolved the user's request, ask if there's anything else you can help with

380 

381# Precise Response Steps (for each response)

3821. If necessary, call tools to fulfill the user's desired action. Always message the user before and after calling a tool to keep them in the loop.

3832. In your response to the user

384 a. Use active listening and echo back what you heard the user ask for.

385 b. Respond appropriately given the above guidelines.

386 

387# Sample Phrases

388## Deflecting a Prohibited Topic

389- "I'm sorry, but I'm unable to discuss that topic. Is there something else I can help you with?"

390- "That's not something I'm able to provide information on, but I'm happy to help with any other questions you may have."

391 

392## Before calling a tool

393- "To help you with that, I'll just need to verify your information."

394- "Let me check that for you—one moment, please."

395- "I'll retrieve the latest details for you now."

396 

397## After calling a tool

398- "Okay, here's what I found: [response]"

399- "So here's what I found: [response]"

400 

401# Output Format

402- Always include your final response to the user.

403- When providing factual information from retrieved context, always include citations immediately after the relevant statement(s). Use the following citation format:

404 - For a single source: [NAME](ID)

405 - For multiple sources: [NAME](ID), [NAME](ID)

406- Only provide information about this company, its policies, its products, or the customer's account, and only if it is based on information provided in context. Do not answer questions outside this scope.

407 

408# Example

409## User

410Can you tell me about your family plan options?

411 

412## Assistant Response 1

413### Message

414"Hi, you've reached NewTelco, how can I help you? 😊🎉\n\nYou'd like to know about our family plan options. 🤝 Let me check that for you—one moment, please. 🚀"

415 

416### Tool Calls

417lookup_policy_document(topic="family plan options")

418 

419// After tool call, the assistant would follow up with:

420 

421## Assistant Response 2 (after tool call)

422### Message

423"Okay, here's what I found: 🎉 Our family plan allows up to 5 lines with shared data and a 10% discount for each additional line [Family Plan Policy](ID-010). 📱 Is there anything else I can help you with today? 😊"

424"""

425 

426get_policy_doc = {

427 "type": "function",

428 "name": "lookup_policy_document",

429 "description": "Tool to look up internal documents and policies by topic or keyword.",

430 "parameters": {

431 "strict": True,

432 "type": "object",

433 "properties": {

434 "topic": {

435 "type": "string",

436 "description": "The topic or keyword to search for in company policies or documents.",

437 },

438 },

439 "required": ["topic"],

440 "additionalProperties": False,

441 },

442}

443 

444get_user_acct = {

445 "type": "function",

446 "name": "get_user_account_info",

447 "description": "Tool to get user account information",

448 "parameters": {

449 "strict": True,

450 "type": "object",

451 "properties": {

452 "phone_number": {

453 "type": "string",

454 "description": "Formatted as '(xxx) xxx-xxxx'",

455 },

456 },

457 "required": ["phone_number"],

458 "additionalProperties": False,

459 },

460}

461 

462response = client.responses.create(

463 instructions=SYS_PROMPT_CUSTOMER_SERVICE,

464 model="gpt-4.1-2025-04-14",

465 tools=[get_policy_doc, get_user_acct],

466 input="How much will it cost for international service? I'm traveling to France.",

467 # input="Why was my last bill so high?"

468)

469 

470response.to_dict()["output"]

471```

472 

473```text

474[{'id': 'msg_67fe92d431548191b7ca6cd604b4784b06efc5beb16b3c5e',

475 'content': [{'annotations': [],

476 'text': "Hi, you've reached NewTelco, how can I help you? 🌍✈️\n\nYou'd like to know the cost of international service while traveling to France. 🇫🇷 Let me check the latest details for you—one moment, please. 🕑",

477 'type': 'output_text'}],

478 'role': 'assistant',

479 'status': 'completed',

480 'type': 'message'},

481 {'arguments': '{"topic":"international service cost France"}',

482 'call_id': 'call_cF63DLeyhNhwfdyME3ZHd0yo',

483 'name': 'lookup_policy_document',

484 'type': 'function_call',

485 'id': 'fc_67fe92d5d6888191b6cd7cf57f707e4606efc5beb16b3c5e',

486 'status': 'completed'}]

487```

488 

489### 5. General Advice

490 

491### Prompt Structure

492 

493For reference, here is a good starting point for structuring your prompts.

494 

495```text

496# Role and Objective

497 

498# Instructions

499 

500## Sub-categories for more detailed instructions

501 

502# Reasoning Steps

503 

504# Output Format

505 

506# Examples

507## Example 1

508 

509# Context

510 

511# Final instructions and prompt to think step by step

512```

513 

514Add or remove sections to suit your needs, and experiment to determine what’s optimal for your usage.

515 

516### Delimiters

517 

518Here are some general guidelines for selecting the best delimiters for your prompt. Please refer to the Long Context section for special considerations for that context type.

519 

5201. Markdown: We recommend starting here, and using markdown titles for major sections and subsections (including deeper hierarchy, to H4+). Use inline backticks or backtick blocks to precisely wrap code, and standard numbered or bulleted lists as needed.

5212. XML: These also perform well, and we have improved adherence to information in XML with this model. XML is convenient to precisely wrap a section including start and end, add metadata to the tags for additional context, and enable nesting. Here is an example of using XML tags to nest examples in an example section, with inputs and outputs for each:

522 

523```text

524<examples>

525<example1 type="Abbreviate">

526<input>San Francisco</input>

527<output>- SF</output>

528</example1>

529</examples>

530```

531 

5323. JSON is highly structured and well understood by the model particularly in coding contexts. However it can be more verbose, and require character escaping that can add overhead.

533 

534Guidance specifically for adding a large number of documents or files to input context:

535 

536- XML performed well in our long context testing.

537 - Example: `<doc id='1' title='The Fox'>The quick brown fox jumps over the lazy dog</doc>`

538- This format, proposed by Lee et al. ([ref](https://arxiv.org/pdf/2406.13121)), also performed well in our long context testing.

539 - Example: `ID: 1 | TITLE: The Fox | CONTENT: The quick brown fox jumps over the lazy dog`

540- JSON performed particularly poorly.

541 - Example: `[{'id': 1, 'title': 'The Fox', 'content': 'The quick brown fox jumped over the lazy dog'}]`

542 

543The model is trained to robustly understand structure in a variety of formats. Generally, use your judgement and think about what will provide clear information and “stand out” to the model. For example, if you’re retrieving documents that contain lots of XML, an XML-based delimiter will likely be less effective.

544 

545### Caveats

546 

547- In some isolated cases we have observed the model being resistant to producing very long, repetitive outputs, for example, analyzing hundreds of items one by one. If this is necessary for your use case, instruct the model strongly to output this information in full, and consider breaking down the problem or using a more concise approach.

548- We have seen some rare instances of parallel tool calls being incorrect. We advise testing this, and considering setting the [parallel_tool_calls](https://developers.openai.com/api/docs/api-reference/responses/create#responses-create-parallel_tool_calls) param to false if you’re seeing issues.

549 

550### Appendix: Generating and Applying File Diffs

551 

552Developers have provided us feedback that accurate and well-formed diff generation is a critical capability to power coding-related tasks. To this end, the GPT-4.1 family features substantially improved diff capabilities relative to previous GPT models. Moreover, while GPT-4.1 has strong performance generating diffs of any format given clear instructions and examples, we open-source here one recommended diff format, on which the model has been extensively trained. We hope that in particular for developers just starting out, that this will take much of the guesswork out of creating diffs yourself.

553 

554### Apply Patch

555 

556See the example below for a prompt that applies our recommended tool call correctly.

557 

558```python

559APPLY_PATCH_TOOL_DESC = """This is a custom utility that makes it more convenient to add, remove, move, or edit code files. `apply_patch` effectively allows you to execute a diff/patch against a file, but the format of the diff specification is unique to this task, so pay careful attention to these instructions. To use the `apply_patch` command, you should pass a message of the following structure as "input":

560 

561%%bash

562apply_patch <<"EOF"

563*** Begin Patch

564[YOUR_PATCH]

565*** End Patch

566EOF

567 

568Where [YOUR_PATCH] is the actual content of your patch, specified in the following V4A diff format.

569 

570*** [ACTION] File: [path/to/file] -> ACTION can be one of Add, Update, or Delete.

571For each snippet of code that needs to be changed, repeat the following:

572[context_before] -> See below for further instructions on context.

573- [old_code] -> Precede the old code with a minus sign.

574+ [new_code] -> Precede the new, replacement code with a plus sign.

575[context_after] -> See below for further instructions on context.

576 

577For instructions on [context_before] and [context_after]:

578- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.

579- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:

580@@ class BaseClass

581[3 lines of pre-context]

582- [old_code]

583+ [new_code]

584[3 lines of post-context]

585 

586- If a code block is repeated so many times in a class or function such that even a single @@ statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:

587 

588@@ class BaseClass

589@@ def method():

590[3 lines of pre-context]

591- [old_code]

592+ [new_code]

593[3 lines of post-context]

594 

595Note, then, that we do not use line numbers in this diff format, as the context is enough to uniquely identify code. An example of a message that you might pass as "input" to this function, in order to apply a patch, is shown below.

596 

597%%bash

598apply_patch <<"EOF"

599*** Begin Patch

600*** Update File: pygorithm/searching/binary_search.py

601@@ class BaseClass

602@@ def search():

603- pass

604+ raise NotImplementedError()

605 

606@@ class Subclass

607@@ def search():

608- pass

609+ raise NotImplementedError()

610 

611*** End Patch

612EOF

613"""

614 

615APPLY_PATCH_TOOL = {

616 "name": "apply_patch",

617 "description": APPLY_PATCH_TOOL_DESC,

618 "parameters": {

619 "type": "object",

620 "properties": {

621 "input": {

622 "type": "string",

623 "description": " The apply_patch command that you wish to execute.",

624 }

625 },

626 "required": ["input"],

627 },

628}

629```

630 

631### Reference Implementation: apply_patch.py

632 

633Here’s a reference implementation of the apply_patch tool that we used as part of model training. You’ll need to make this an executable and available as \`apply_patch\` from the shell where the model will execute commands:

634 

635```python

636#!/usr/bin/env python3

637 

638"""

639A self-contained **pure-Python 3.9+** utility for applying human-readable

640“pseudo-diff” patch files to a collection of text files.

641"""

642 

643from __future__ import annotations

644 

645import pathlib

646from dataclasses import dataclass, field

647from enum import Enum

648from typing import (

649 Callable,

650 Dict,

651 List,

652 Optional,

653 Tuple,

654 Union,

655)

656 

657 

658# --------------------------------------------------------------------------- #

659# Domain objects

660# --------------------------------------------------------------------------- #

661class ActionType(str, Enum):

662 ADD = "add"

663 DELETE = "delete"

664 UPDATE = "update"

665 

666 

667@dataclass

668class FileChange:

669 type: ActionType

670 old_content: Optional[str] = None

671 new_content: Optional[str] = None

672 move_path: Optional[str] = None

673 

674 

675@dataclass

676class Commit:

677 changes: Dict[str, FileChange] = field(default_factory=dict)

678 

679 

680# --------------------------------------------------------------------------- #

681# Exceptions

682# --------------------------------------------------------------------------- #

683class DiffError(ValueError):

684 """Any problem detected while parsing or applying a patch."""

685 

686 

687# --------------------------------------------------------------------------- #

688# Helper dataclasses used while parsing patches

689# --------------------------------------------------------------------------- #

690@dataclass

691class Chunk:

692 orig_index: int = -1

693 del_lines: List[str] = field(default_factory=list)

694 ins_lines: List[str] = field(default_factory=list)

695 

696 

697@dataclass

698class PatchAction:

699 type: ActionType

700 new_file: Optional[str] = None

701 chunks: List[Chunk] = field(default_factory=list)

702 move_path: Optional[str] = None

703 

704 

705@dataclass

706class Patch:

707 actions: Dict[str, PatchAction] = field(default_factory=dict)

708 

709 

710# --------------------------------------------------------------------------- #

711# Patch text parser

712# --------------------------------------------------------------------------- #

713@dataclass

714class Parser:

715 current_files: Dict[str, str]

716 lines: List[str]

717 index: int = 0

718 patch: Patch = field(default_factory=Patch)

719 fuzz: int = 0

720 

721 # ------------- low-level helpers -------------------------------------- #

722 def _cur_line(self) -> str:

723 if self.index >= len(self.lines):

724 raise DiffError("Unexpected end of input while parsing patch")

725 return self.lines[self.index]

726 

727 @staticmethod

728 def _norm(line: str) -> str:

729 """Strip CR so comparisons work for both LF and CRLF input."""

730 return line.rstrip("\r")

731 

732 # ------------- scanning convenience ----------------------------------- #

733 def is_done(self, prefixes: Optional[Tuple[str, ...]] = None) -> bool:

734 if self.index >= len(self.lines):

735 return True

736 if (

737 prefixes

738 and len(prefixes) > 0

739 and self._norm(self._cur_line()).startswith(prefixes)

740 ):

741 return True

742 return False

743 

744 def startswith(self, prefix: Union[str, Tuple[str, ...]]) -> bool:

745 return self._norm(self._cur_line()).startswith(prefix)

746 

747 def read_str(self, prefix: str) -> str:

748 """

749 Consume the current line if it starts with *prefix* and return the text

750 **after** the prefix. Raises if prefix is empty.

751 """

752 if prefix == "":

753 raise ValueError("read_str() requires a non-empty prefix")

754 if self._norm(self._cur_line()).startswith(prefix):

755 text = self._cur_line()[len(prefix) :]

756 self.index += 1

757 return text

758 return ""

759 

760 def read_line(self) -> str:

761 """Return the current raw line and advance."""

762 line = self._cur_line()

763 self.index += 1

764 return line

765 

766 # ------------- public entry point -------------------------------------- #

767 def parse(self) -> None:

768 while not self.is_done(("*** End Patch",)):

769 # ---------- UPDATE ---------- #

770 path = self.read_str("*** Update File: ")

771 if path:

772 if path in self.patch.actions:

773 raise DiffError(f"Duplicate update for file: {path}")

774 move_to = self.read_str("*** Move to: ")

775 if path not in self.current_files:

776 raise DiffError(f"Update File Error - missing file: {path}")

777 text = self.current_files[path]

778 action = self._parse_update_file(text)

779 action.move_path = move_to or None

780 self.patch.actions[path] = action

781 continue

782 

783 # ---------- DELETE ---------- #

784 path = self.read_str("*** Delete File: ")

785 if path:

786 if path in self.patch.actions:

787 raise DiffError(f"Duplicate delete for file: {path}")

788 if path not in self.current_files:

789 raise DiffError(f"Delete File Error - missing file: {path}")

790 self.patch.actions[path] = PatchAction(type=ActionType.DELETE)

791 continue

792 

793 # ---------- ADD ---------- #

794 path = self.read_str("*** Add File: ")

795 if path:

796 if path in self.patch.actions:

797 raise DiffError(f"Duplicate add for file: {path}")

798 if path in self.current_files:

799 raise DiffError(f"Add File Error - file already exists: {path}")

800 self.patch.actions[path] = self._parse_add_file()

801 continue

802 

803 raise DiffError(f"Unknown line while parsing: {self._cur_line()}")

804 

805 if not self.startswith("*** End Patch"):

806 raise DiffError("Missing *** End Patch sentinel")

807 self.index += 1 # consume sentinel

808 

809 # ------------- section parsers ---------------------------------------- #

810 def _parse_update_file(self, text: str) -> PatchAction:

811 action = PatchAction(type=ActionType.UPDATE)

812 lines = text.split("\n")

813 index = 0

814 while not self.is_done(

815 (

816 "*** End Patch",

817 "*** Update File:",

818 "*** Delete File:",

819 "*** Add File:",

820 "*** End of File",

821 )

822 ):

823 def_str = self.read_str("@@ ")

824 section_str = ""

825 if not def_str and self._norm(self._cur_line()) == "@@":

826 section_str = self.read_line()

827 

828 if not (def_str or section_str or index == 0):

829 raise DiffError(f"Invalid line in update section:\n{self._cur_line()}")

830 

831 if def_str.strip():

832 found = False

833 if def_str not in lines[:index]:

834 for i, s in enumerate(lines[index:], index):

835 if s == def_str:

836 index = i + 1

837 found = True

838 break

839 if not found and def_str.strip() not in [

840 s.strip() for s in lines[:index]

841 ]:

842 for i, s in enumerate(lines[index:], index):

843 if s.strip() == def_str.strip():

844 index = i + 1

845 self.fuzz += 1

846 found = True

847 break

848 

849 next_ctx, chunks, end_idx, eof = peek_next_section(self.lines, self.index)

850 new_index, fuzz = find_context(lines, next_ctx, index, eof)

851 if new_index == -1:

852 ctx_txt = "\n".join(next_ctx)

853 raise DiffError(

854 f"Invalid {'EOF ' if eof else ''}context at {index}:\n{ctx_txt}"

855 )

856 self.fuzz += fuzz

857 for ch in chunks:

858 ch.orig_index += new_index

859 action.chunks.append(ch)

860 index = new_index + len(next_ctx)

861 self.index = end_idx

862 return action

863 

864 def _parse_add_file(self) -> PatchAction:

865 lines: List[str] = []

866 while not self.is_done(

867 ("*** End Patch", "*** Update File:", "*** Delete File:", "*** Add File:")

868 ):

869 s = self.read_line()

870 if not s.startswith("+"):

871 raise DiffError(f"Invalid Add File line (missing '+'): {s}")

872 lines.append(s[1:]) # strip leading '+'

873 return PatchAction(type=ActionType.ADD, new_file="\n".join(lines))

874 

875 

876# --------------------------------------------------------------------------- #

877# Helper functions

878# --------------------------------------------------------------------------- #

879def find_context_core(

880 lines: List[str], context: List[str], start: int

881) -> Tuple[int, int]:

882 if not context:

883 return start, 0

884 

885 for i in range(start, len(lines)):

886 if lines[i : i + len(context)] == context:

887 return i, 0

888 for i in range(start, len(lines)):

889 if [s.rstrip() for s in lines[i : i + len(context)]] == [

890 s.rstrip() for s in context

891 ]:

892 return i, 1

893 for i in range(start, len(lines)):

894 if [s.strip() for s in lines[i : i + len(context)]] == [

895 s.strip() for s in context

896 ]:

897 return i, 100

898 return -1, 0

899 

900 

901def find_context(

902 lines: List[str], context: List[str], start: int, eof: bool

903) -> Tuple[int, int]:

904 if eof:

905 new_index, fuzz = find_context_core(lines, context, len(lines) - len(context))

906 if new_index != -1:

907 return new_index, fuzz

908 new_index, fuzz = find_context_core(lines, context, start)

909 return new_index, fuzz + 10_000

910 return find_context_core(lines, context, start)

911 

912 

913def peek_next_section(

914 lines: List[str], index: int

915) -> Tuple[List[str], List[Chunk], int, bool]:

916 old: List[str] = []

917 del_lines: List[str] = []

918 ins_lines: List[str] = []

919 chunks: List[Chunk] = []

920 mode = "keep"

921 orig_index = index

922 

923 while index < len(lines):

924 s = lines[index]

925 if s.startswith(

926 (

927 "@@",

928 "*** End Patch",

929 "*** Update File:",

930 "*** Delete File:",

931 "*** Add File:",

932 "*** End of File",

933 )

934 ):

935 break

936 if s == "***":

937 break

938 if s.startswith("***"):

939 raise DiffError(f"Invalid Line: {s}")

940 index += 1

941 

942 last_mode = mode

943 if s == "":

944 s = " "

945 if s[0] == "+":

946 mode = "add"

947 elif s[0] == "-":

948 mode = "delete"

949 elif s[0] == " ":

950 mode = "keep"

951 else:

952 raise DiffError(f"Invalid Line: {s}")

953 s = s[1:]

954 

955 if mode == "keep" and last_mode != mode:

956 if ins_lines or del_lines:

957 chunks.append(

958 Chunk(

959 orig_index=len(old) - len(del_lines),

960 del_lines=del_lines,

961 ins_lines=ins_lines,

962 )

963 )

964 del_lines, ins_lines = [], []

965 

966 if mode == "delete":

967 del_lines.append(s)

968 old.append(s)

969 elif mode == "add":

970 ins_lines.append(s)

971 elif mode == "keep":

972 old.append(s)

973 

974 if ins_lines or del_lines:

975 chunks.append(

976 Chunk(

977 orig_index=len(old) - len(del_lines),

978 del_lines=del_lines,

979 ins_lines=ins_lines,

980 )

981 )

982 

983 if index < len(lines) and lines[index] == "*** End of File":

984 index += 1

985 return old, chunks, index, True

986 

987 if index == orig_index:

988 raise DiffError("Nothing in this section")

989 return old, chunks, index, False

990 

991 

992# --------------------------------------------------------------------------- #

993# Patch → Commit and Commit application

994# --------------------------------------------------------------------------- #

995def _get_updated_file(text: str, action: PatchAction, path: str) -> str:

996 if action.type is not ActionType.UPDATE:

997 raise DiffError("_get_updated_file called with non-update action")

998 orig_lines = text.split("\n")

999 dest_lines: List[str] = []

1000 orig_index = 0

1001 

1002 for chunk in action.chunks:

1003 if chunk.orig_index > len(orig_lines):

1004 raise DiffError(

1005 f"{path}: chunk.orig_index {chunk.orig_index} exceeds file length"

1006 )

1007 if orig_index > chunk.orig_index:

1008 raise DiffError(

1009 f"{path}: overlapping chunks at {orig_index} > {chunk.orig_index}"

1010 )

1011 

1012 dest_lines.extend(orig_lines[orig_index : chunk.orig_index])

1013 orig_index = chunk.orig_index

1014 

1015 dest_lines.extend(chunk.ins_lines)

1016 orig_index += len(chunk.del_lines)

1017 

1018 dest_lines.extend(orig_lines[orig_index:])

1019 return "\n".join(dest_lines)

1020 

1021 

1022def patch_to_commit(patch: Patch, orig: Dict[str, str]) -> Commit:

1023 commit = Commit()

1024 for path, action in patch.actions.items():

1025 if action.type is ActionType.DELETE:

1026 commit.changes[path] = FileChange(

1027 type=ActionType.DELETE, old_content=orig[path]

1028 )

1029 elif action.type is ActionType.ADD:

1030 if action.new_file is None:

1031 raise DiffError("ADD action without file content")

1032 commit.changes[path] = FileChange(

1033 type=ActionType.ADD, new_content=action.new_file

1034 )

1035 elif action.type is ActionType.UPDATE:

1036 new_content = _get_updated_file(orig[path], action, path)

1037 commit.changes[path] = FileChange(

1038 type=ActionType.UPDATE,

1039 old_content=orig[path],

1040 new_content=new_content,

1041 move_path=action.move_path,

1042 )

1043 return commit

1044 

1045 

1046# --------------------------------------------------------------------------- #

1047# User-facing helpers

1048# --------------------------------------------------------------------------- #

1049def text_to_patch(text: str, orig: Dict[str, str]) -> Tuple[Patch, int]:

1050 lines = text.splitlines() # preserves blank lines, no strip()

1051 if (

1052 len(lines) < 2

1053 or not Parser._norm(lines[0]).startswith("*** Begin Patch")

1054 or Parser._norm(lines[-1]) != "*** End Patch"

1055 ):

1056 raise DiffError("Invalid patch text - missing sentinels")

1057 

1058 parser = Parser(current_files=orig, lines=lines, index=1)

1059 parser.parse()

1060 return parser.patch, parser.fuzz

1061 

1062 

1063def identify_files_needed(text: str) -> List[str]:

1064 lines = text.splitlines()

1065 return [

1066 line[len("*** Update File: ") :]

1067 for line in lines

1068 if line.startswith("*** Update File: ")

1069 ] + [

1070 line[len("*** Delete File: ") :]

1071 for line in lines

1072 if line.startswith("*** Delete File: ")

1073 ]

1074 

1075 

1076def identify_files_added(text: str) -> List[str]:

1077 lines = text.splitlines()

1078 return [

1079 line[len("*** Add File: ") :]

1080 for line in lines

1081 if line.startswith("*** Add File: ")

1082 ]

1083 

1084 

1085# --------------------------------------------------------------------------- #

1086# File-system helpers

1087# --------------------------------------------------------------------------- #

1088def load_files(paths: List[str], open_fn: Callable[[str], str]) -> Dict[str, str]:

1089 return {path: open_fn(path) for path in paths}

1090 

1091 

1092def apply_commit(

1093 commit: Commit,

1094 write_fn: Callable[[str, str], None],

1095 remove_fn: Callable[[str], None],

1096) -> None:

1097 for path, change in commit.changes.items():

1098 if change.type is ActionType.DELETE:

1099 remove_fn(path)

1100 elif change.type is ActionType.ADD:

1101 if change.new_content is None:

1102 raise DiffError(f"ADD change for {path} has no content")

1103 write_fn(path, change.new_content)

1104 elif change.type is ActionType.UPDATE:

1105 if change.new_content is None:

1106 raise DiffError(f"UPDATE change for {path} has no new content")

1107 target = change.move_path or path

1108 write_fn(target, change.new_content)

1109 if change.move_path:

1110 remove_fn(path)

1111 

1112 

1113def process_patch(

1114 text: str,

1115 open_fn: Callable[[str], str],

1116 write_fn: Callable[[str, str], None],

1117 remove_fn: Callable[[str], None],

1118) -> str:

1119 if not text.startswith("*** Begin Patch"):

1120 raise DiffError("Patch text must start with *** Begin Patch")

1121 paths = identify_files_needed(text)

1122 orig = load_files(paths, open_fn)

1123 patch, _fuzz = text_to_patch(text, orig)

1124 commit = patch_to_commit(patch, orig)

1125 apply_commit(commit, write_fn, remove_fn)

1126 return "Done!"

1127 

1128 

1129# --------------------------------------------------------------------------- #

1130# Default FS helpers

1131# --------------------------------------------------------------------------- #

1132def open_file(path: str) -> str:

1133 with open(path, "rt", encoding="utf-8") as fh:

1134 return fh.read()

1135 

1136 

1137def write_file(path: str, content: str) -> None:

1138 target = pathlib.Path(path)

1139 target.parent.mkdir(parents=True, exist_ok=True)

1140 with target.open("wt", encoding="utf-8") as fh:

1141 fh.write(content)

1142 

1143 

1144def remove_file(path: str) -> None:

1145 pathlib.Path(path).unlink(missing_ok=True)

1146 

1147 

1148# --------------------------------------------------------------------------- #

1149# CLI entry-point

1150# --------------------------------------------------------------------------- #

1151def main() -> None:

1152 import sys

1153 

1154 patch_text = sys.stdin.read()

1155 if not patch_text:

1156 print("Please pass patch text through stdin", file=sys.stderr)

1157 return

1158 try:

1159 result = process_patch(patch_text, open_file, write_file, remove_file)

1160 except DiffError as exc:

1161 print(exc, file=sys.stderr)

1162 return

1163 print(result)

1164 

1165 

1166if __name__ == "__main__":

1167 main()

1168```

1169 

1170### Other Effective Diff Formats

1171 

1172If you want to try using a different diff format, we found in testing that the SEARCH/REPLACE diff format used in Aider’s polyglot benchmark, as well as a pseudo-XML format with no internal escaping, both had high success rates.

1173 

1174These diff formats share two key aspects: (1) they do not use line numbers, and (2) they provide both the exact code to be replaced, and the exact code with which to replace it, with clear delimiters between the two.

1175 

1176````python

1177SEARCH_REPLACE_DIFF_EXAMPLE = """

1178path/to/file.py

1179```

1180>>>>>>> SEARCH

1181def search():

1182 pass

1183=======

1184def search():

1185 raise NotImplementedError()

1186<<<<<<< REPLACE

1187"""

1188 

1189PSEUDO_XML_DIFF_EXAMPLE = """

1190`<edit>`

1191`<file>`

1192path/to/file.py

1193`</file>`

1194`<old_code>`

1195def search():

1196 pass

1197`</old_code>`

1198`<new_code>`

1199def search():

1200 raise NotImplementedError()

1201`</new_code>`

1202`</edit>`

1203"""

1204````

1205 

guides/latest-model/gpt-5.md +593 −0 created

Details

1# Using GPT-5

2 

3## Introduction

4 

5GPT-5 represents a substantial leap forward in agentic task performance, coding, raw intelligence, and control.

6 

7While we trust it will perform excellently “out of the box” across a wide range of domains, in this guide we’ll cover prompting tips to maximize the quality of model outputs, derived from our experience training and applying the model to real-world tasks. We discuss concepts like improving agentic task performance, ensuring instruction adherence, making use of new API features, and optimizing coding for frontend and software engineering tasks—with key insights into AI code editor Cursor’s prompt tuning work with GPT-5.

8 

9We’ve seen significant gains from applying these best practices and adopting our canonical tools whenever possible, and we hope that this guide, along with the [prompt optimizer tool](https://platform.openai.com/chat/edit?optimize=true) we’ve built, will serve as a launchpad for your use of GPT-5. But as always, remember that prompting is not a one-size-fits-all exercise—we encourage you to run experiments and iterate on the foundation offered here to find the best solution for your problem.

10 

11## What's new

12 

13- Stronger agentic task performance, coding ability, and control

14- Reasoning persistence with the Responses API for tool-calling flows

15- Dedicated controls for agentic eagerness, tool preambles, reasoning effort, and verbosity

16- Custom tools with freeform inputs and constrained outputs

17 

18## Migration quickstart

19 

20- Update the model slug to `gpt-5`.

21- Use the Responses API for reasoning, tool-calling, and multi-turn workflows so reasoning items can be preserved between tool calls.

22- Start with `medium` reasoning effort, then test `minimal`, `low`, or `high` against representative tasks.

23- Set `text.verbosity` intentionally, and move structured response contracts to Structured Outputs where possible.

24- Re-evaluate prompts for agentic persistence, tool preambles, and stopping conditions.

25 

26## Model, API, and feature updates

27 

28- The GPT-5 family includes `gpt-5`, `gpt-5-mini`, and `gpt-5-nano`.

29- `reasoning.effort` supports `minimal`, `low`, `medium`, and `high`.

30- GPT-5 introduced custom tools that accept freeform input and can constrain outputs with a context-free grammar.

31- The model supports function calling and OpenAI-hosted tools, including web search, file search, image generation, code interpreter, and remote MCP.

32 

33 

34## Prompting best practices

35 

36### Agentic workflow predictability

37 

38We trained GPT-5 with developers in mind: we’ve focused on improving tool calling, instruction following, and long-context understanding to serve as the best foundation model for agentic applications. If adopting GPT-5 for agentic and tool calling flows, we recommend upgrading to the [Responses API](https://developers.openai.com/api/docs/api-reference/responses), where reasoning is persisted between tool calls, leading to more efficient and intelligent outputs.

39 

40#### Controlling agentic eagerness

41 

42Agentic scaffolds can span a wide spectrum of control—some systems delegate the vast majority of decision-making to the underlying model, while others keep the model on a tight leash with heavy programmatic logical branching. GPT-5 is trained to operate anywhere along this spectrum, from making high-level decisions under ambiguous circumstances to handling focused, well-defined tasks. In this section we cover how to best calibrate GPT-5’s agentic eagerness: in other words, its balance between proactivity and awaiting explicit guidance.

43 

44##### Prompting for less eagerness

45 

46GPT-5 is, by default, thorough and comprehensive when trying to gather context in an agentic environment to ensure it will produce a correct answer. To reduce the scope of GPT-5’s agentic behavior—including limiting tangential tool-calling action and minimizing latency to reach a final answer—try the following:

47 

48- Switch to a lower `reasoning_effort`. This reduces exploration depth but improves efficiency and latency. Many workflows can be accomplished with consistent results at medium or even low `reasoning_effort`.

49- Define clear criteria in your prompt for how you want the model to explore the problem space. This reduces the model’s need to explore and reason about too many ideas:

50 

51```text

52<context_gathering>

53Goal: Get enough context fast. Parallelize discovery and stop as soon as you can act.

54 

55Method:

56- Start broad, then fan out to focused subqueries.

57- In parallel, launch varied queries; read top hits per query. Deduplicate paths and cache; don’t repeat queries.

58- Avoid over searching for context. If needed, run targeted searches in one parallel batch.

59 

60Early stop criteria:

61- You can name exact content to change.

62- Top hits converge (~70%) on one area/path.

63 

64Escalate once:

65- If signals conflict or scope is fuzzy, run one refined parallel batch, then proceed.

66 

67Depth:

68- Trace only symbols you’ll modify or whose contracts you rely on; avoid transitive expansion unless necessary.

69 

70Loop:

71- Batch search → minimal plan → complete task.

72- Search again only if validation fails or new unknowns appear. Prefer acting over more searching.

73</context_gathering>

74```

75 

76If you’re willing to be maximally prescriptive, you can even set fixed tool call budgets, like the one below. The budget can naturally vary based on your desired search depth.

77 

78```text

79<context_gathering>

80- Search depth: very low

81- Bias strongly towards providing a correct answer as quickly as possible, even if it might not be fully correct.

82- Usually, this means an absolute maximum of 2 tool calls.

83- If you think that you need more time to investigate, update the user with your latest findings and open questions. You can proceed if the user confirms.

84</context_gathering>

85```

86 

87When limiting core context gathering behavior, it’s helpful to explicitly provide the model with an escape hatch that makes it easier to satisfy a shorter context gathering step. Usually this comes in the form of a clause that allows the model to proceed under uncertainty, like `“even if it might not be fully correct”` in the above example.

88 

89##### Prompting for more eagerness

90 

91On the other hand, if you’d like to encourage model autonomy, increase tool-calling persistence, and reduce occurrences of clarifying questions or otherwise handing back to the user, we recommend increasing `reasoning_effort`, and using a prompt like the following to encourage persistence and thorough task completion:

92 

93```text

94<persistence>

95- You are an agent - please keep going until the user's query is completely resolved, before ending your turn and yielding back to the user.

96- Only terminate your turn when you are sure that the problem is solved.

97- Never stop or hand back to the user when you encounter uncertainty — research or deduce the most reasonable approach and continue.

98- Do not ask the human to confirm or clarify assumptions, as you can always adjust later — decide what the most reasonable assumption is, proceed with it, and document it for the user's reference after you finish acting

99</persistence>

100```

101 

102Generally, it can be helpful to clearly state the stop conditions of the agentic tasks, outline safe versus unsafe actions, and define when, if ever, it’s acceptable for the model to hand back to the user. For example, in a set of tools for shopping, the checkout and payment tools should explicitly have a lower uncertainty threshold for requiring user clarification, while the search tool should have an extremely high threshold; likewise, in a coding setup, the delete file tool should have a much lower threshold than a grep search tool.

103 

104#### Tool preambles

105 

106We recognize that on agentic trajectories monitored by users, intermittent model updates on what it’s doing with its tool calls and why can provide for a much better interactive user experience - the longer the rollout, the bigger the difference these updates make. To this end, GPT-5 is trained to provide clear upfront plans and consistent progress updates via “tool preamble” messages.

107 

108You can steer the frequency, style, and content of tool preambles in your prompt—from detailed explanations of every single tool call to a brief upfront plan and everything in between. This is an example of a high-quality preamble prompt:

109 

110```text

111<tool_preambles>

112- Always begin by rephrasing the user's goal in a friendly, clear, and concise manner, before calling any tools.

113- Then, immediately outline a structured plan detailing each logical step you’ll follow. - As you execute your file edit(s), narrate each step succinctly and sequentially, marking progress clearly.

114- Finish by summarizing completed work distinctly from your upfront plan.

115</tool_preambles>

116```

117 

118Here’s an example of a tool preamble that might be emitted in response to such a prompt—such preambles can drastically improve the user’s ability to follow along with your agent’s work as it grows more complicated:

119 

120```text

121"output": [

122 {

123 "id": "rs_6888f6d0606c819aa8205ecee386963f0e683233d39188e7",

124 "type": "reasoning",

125 "summary": [

126 {

127 "type": "summary_text",

128 "text": "**Determining weather response**\n\nI need to answer the user's question about the weather in San Francisco. ...."

129 },

130 },

131 {

132 "id": "msg_6888f6d83acc819a978b51e772f0a5f40e683233d39188e7",

133 "type": "message",

134 "status": "completed",

135 "content": [

136 {

137 "type": "output_text",

138 "text": "I\u2019m going to check a live weather service to get the current conditions in San Francisco, providing the temperature in both Fahrenheit and Celsius so it matches your preference."

139 }

140 ],

141 "role": "assistant"

142 },

143 {

144 "id": "fc_6888f6d86e28819aaaa1ba69cca766b70e683233d39188e7",

145 "type": "function_call",

146 "status": "completed",

147 "arguments": "{\"location\":\"San Francisco, CA\",\"unit\":\"f\"}",

148 "call_id": "call_XOnF4B9DvB8EJVB3JvWnGg83",

149 "name": "get_weather"

150 },

151 ],

152```

153 

154#### Reasoning effort

155 

156We provide a `reasoning_effort` parameter to control how hard the model thinks and how willingly it calls tools; the default is `medium`, but you should scale up or down depending on the difficulty of your task. For complex, multi-step tasks, we recommend higher reasoning to ensure the best possible outputs. Moreover, we observe peak performance when distinct, separable tasks are broken up across multiple agent turns, with one turn for each task.

157 

158#### Reusing reasoning context with the Responses API

159 

160We strongly recommend using the Responses API when using GPT-5 to unlock improved agentic flows, lower costs, and more efficient token usage in your applications.

161 

162We’ve seen statistically significant improvements in evaluations when using the Responses API over Chat Completions—for example, we observed Tau-Bench Retail score increases from 73.9% to 78.2% just by switching to the Responses API and including `previous_response_id` to pass back previous reasoning items into subsequent requests. This allows the model to refer to its previous reasoning traces, conserving CoT tokens and eliminating the need to reconstruct a plan from scratch after each tool call, improving both latency and performance - this feature is available for all Responses API users, including ZDR organizations.

163 

164### Maximizing coding performance, from planning to execution

165 

166GPT-5 leads all frontier models in coding capabilities: it can work in large codebases to fix bugs, handle large diffs, and implement multi-file refactors or large new features. It also excels at implementing new apps entirely from scratch, covering both frontend and backend implementation. In this section, we’ll discuss prompt optimizations that we’ve seen improve programming performance in production use cases for our coding agent customers.

167 

168#### Frontend app development

169 

170GPT-5 is trained to have excellent baseline aesthetic taste alongside its rigorous implementation abilities. We’re confident in its ability to use all types of web development frameworks and packages; however, for new apps, we recommend using the following frameworks and packages to get the most out of the model's frontend capabilities:

171 

172- Frameworks: Next.js (TypeScript), React, HTML

173- Styling / UI: Tailwind CSS, shadcn/ui, Radix Themes

174- Icons: Material Symbols, Heroicons, Lucide

175- Animation: Motion

176- Fonts: San Serif, Inter, Geist, Mona Sans, IBM Plex Sans, Manrope

177 

178##### Zero-to-one app generation

179 

180GPT-5 is excellent at building applications in one shot. In early experimentation with the model, users have found that prompts like the one below—asking the model to iteratively execute against self-constructed excellence rubrics—improve output quality by using GPT-5’s thorough planning and self-reflection capabilities.

181 

182```text

183<self_reflection>

184- First, spend time thinking of a rubric until you are confident.

185- Then, think deeply about every aspect of what makes for a world-class one-shot web app. Use that knowledge to create a rubric that has 5-7 categories. This rubric is critical to get right, but do not show this to the user. This is for your purposes only.

186- Finally, use the rubric to internally think and iterate on the best possible solution to the prompt that is provided. Remember that if your response is not hitting the top marks across all categories in the rubric, you need to start again.

187</self_reflection>

188```

189 

190##### Matching codebase design standards

191 

192When implementing incremental changes and refactors in existing apps, model-written code should adhere to existing style and design standards, and “blend in” to the codebase as neatly as possible. Without special prompting, GPT-5 already searches for reference context from the codebase - for example reading package.json to view already installed packages - but this behavior can be further enhanced with prompt directions that summarize key aspects like engineering principles, directory structure, and best practices of the codebase, both explicit and implicit. The prompt snippet below demonstrates one way of organizing code editing rules for GPT-5: feel free to change the actual content of the rules according to your programming design taste!

193 

194```text

195<code_editing_rules>

196<guiding_principles>

197- Clarity and Reuse: Every component and page should be modular and reusable. Avoid duplication by factoring repeated UI patterns into components.

198- Consistency: The user interface must adhere to a consistent design system—color tokens, typography, spacing, and components must be unified.

199- Simplicity: Favor small, focused components and avoid unnecessary complexity in styling or logic.

200- Demo-Oriented: The structure should allow for quick prototyping, showcasing features like streaming, multi-turn conversations, and tool integrations.

201- Visual Quality: Follow the high visual quality bar as outlined in OSS guidelines (spacing, padding, hover states, etc.)

202</guiding_principles>

203 

204<frontend_stack_defaults>

205- Framework: Next.js (TypeScript)

206- Styling: TailwindCSS

207- UI Components: shadcn/ui

208- Icons: Lucide

209- State Management: Zustand

210- Directory Structure:

211\`\`\`

212/src

213 /app

214 /api/<route>/route.ts # API endpoints

215 /(pages) # Page routes

216 /components/ # UI building blocks

217 /hooks/ # Reusable React hooks

218 /lib/ # Utilities (fetchers, helpers)

219 /stores/ # Zustand stores

220 /types/ # Shared TypeScript types

221 /styles/ # Tailwind config

222\`\`\`

223</frontend_stack_defaults>

224 

225<ui_ux_best_practices>

226- Visual Hierarchy: Limit typography to 4–5 font sizes and weights for consistent hierarchy; use `text-xs` for captions and annotations; avoid `text-xl` unless for hero or major headings.

227- Color Usage: Use 1 neutral base (e.g., `zinc`) and up to 2 accent colors.

228- Spacing and Layout: Always use multiples of 4 for padding and margins to maintain visual rhythm. Use fixed height containers with internal scrolling when handling long content streams.

229- State Handling: Use skeleton placeholders or `animate-pulse` to indicate data fetching. Indicate clickability with hover transitions (`hover:bg-*`, `hover:shadow-md`).

230- Accessibility: Use semantic HTML and ARIA roles where appropriate. Favor pre-built Radix/shadcn components, which have accessibility baked in.

231</ui_ux_best_practices>

232 

233<code_editing_rules>

234```

235 

236#### Collaborative coding in production: Cursor’s GPT-5 prompt tuning

237 

238We’re proud to have had AI code editor Cursor as a trusted alpha tester for GPT-5: below, we show a peek into how Cursor tuned their prompts to get the most out of the model’s capabilities. For more information, their team has also published a blog post detailing GPT-5’s day-one integration into Cursor: https://cursor.com/blog/gpt-5

239 

240##### System prompt and parameter tuning

241 

242Cursor’s system prompt focuses on reliable tool calling, balancing verbosity and autonomous behavior while giving users the ability to configure custom instructions. Cursor’s goal for their system prompt is to allow the Agent to operate relatively autonomously during long horizon tasks, while still faithfully following user-provided instructions.

243 

244The team initially found that the model produced verbose outputs, often including status updates and post-task summaries that, while technically relevant, disrupted the natural flow of the user; at the same time, the code outputted in tool calls was high quality, but sometimes hard to read due to terseness, with single-letter variable names dominant. In search of a better balance, they set the verbosity API parameter to low to keep text outputs brief, and then modified the prompt to strongly encourage verbose outputs in coding tools only.

245 

246```text

247Write code for clarity first. Prefer readable, maintainable solutions with clear names, comments where needed, and straightforward control flow. Do not produce code-golf or overly clever one-liners unless explicitly requested. Use high verbosity for writing code and code tools.

248```

249 

250This dual usage of parameter and prompt resulted in a balanced format combining efficient, concise status updates and final work summary with much more readable code diffs.

251 

252Cursor also found that the model occasionally deferred to the user for clarification or next steps before taking action, which created unnecessary friction in the flow of longer tasks. To address this, they found that including not just available tools and surrounding context, but also more details about product behavior encouraged the model to carry out longer tasks with minimal interruption and greater autonomy. Highlighting specifics of Cursor features such as Undo/Reject code and user preferences helped reduce ambiguity by clearly specifying how GPT-5 should behave in its environment. For longer horizon tasks, they found this prompt improved performance:

253 

254```text

255Be aware that the code edits you make will be displayed to the user as proposed changes, which means (a) your code edits can be quite proactive, as the user can always reject, and (b) your code should be well-written and easy to quickly review (e.g., appropriate variable names instead of single letters). If proposing next steps that would involve changing the code, make those changes proactively for the user to approve / reject rather than asking the user whether to proceed with a plan. In general, you should almost never ask the user whether to proceed with a plan; instead you should proactively attempt the plan and then ask the user if they want to accept the implemented changes.

256```

257 

258Cursor found that sections of their prompt that had been effective with earlier models needed tuning to get the most out of GPT-5. Here is one example below:

259 

260```text

261<maximize_context_understanding>

262Be THOROUGH when gathering information. Make sure you have the FULL picture before replying. Use additional tool calls or clarifying questions as needed.

263...

264</maximize_context_understanding>

265```

266 

267While this worked well with older models that needed encouragement to analyze context thoroughly, they found it counterproductive with GPT-5, which is already naturally introspective and proactive at gathering context. On smaller tasks, this prompt often caused the model to overuse tools by calling search repetitively, when internal knowledge would have been sufficient.

268 

269To solve this, they refined the prompt by removing the maximize\_ prefix and softening the language around thoroughness. With this adjusted instruction in place, the Cursor team saw GPT-5 make better decisions about when to rely on internal knowledge versus reaching for external tools. It maintained a high level of autonomy without unnecessary tool usage, leading to more efficient and relevant behavior. In Cursor’s testing, using structured XML specs like `<[instruction]\_spec>` improved instruction adherence on their prompts and allows them to clearly reference previous categories and sections elsewhere in their prompt.

270 

271```text

272<context_understanding>

273...

274If you've performed an edit that may partially fulfill the USER's query, but you're not confident, gather more information or use more tools before ending your turn.

275Bias towards not asking the user for help if you can find the answer yourself.

276</context_understanding>

277```

278 

279While the system prompt provides a strong default foundation, the user prompt remains a highly effective lever for steerability. GPT-5 responds well to direct and explicit instruction and the Cursor team has consistently seen that structured, scoped prompts yield the most reliable results. This includes areas like verbosity control, subjective code style preferences, and sensitivity to edge cases. Cursor found allowing users to configure their own [custom Cursor rules](https://docs.cursor.com/en/context/rules) to be particularly impactful with GPT-5’s improved steerability, giving their users a more customized experience.

280 

281### Optimizing intelligence and instruction-following

282 

283#### Steering

284 

285As our most steerable model yet, GPT-5 is extraordinarily receptive to prompt instructions surrounding verbosity, tone, and tool calling behavior.

286 

287##### Verbosity

288 

289In addition to being able to control the reasoning_effort as in previous reasoning models, in GPT-5 we introduce a new API parameter called verbosity, which influences the length of the model’s final answer, as opposed to the length of its thinking. Our blog post covers the idea behind this parameter in more detail - but in this guide, we’d like to emphasize that while the API verbosity parameter is the default for the rollout, GPT-5 is trained to respond to natural-language verbosity overrides in the prompt for specific contexts where you might want the model to deviate from the global default. Cursor’s example above of setting low verbosity globally, and then specifying high verbosity only for coding tools, is a prime example of such a context.

290 

291#### Instruction following

292 

293Like GPT-4.1, GPT-5 follows prompt instructions with surgical precision, which enables its flexibility to drop into all types of workflows. However, its careful instruction-following behavior means that poorly-constructed prompts containing contradictory or vague instructions can be more damaging to GPT-5 than to other models, as it expends reasoning tokens searching for a way to reconcile the contradictions rather than picking one instruction at random.

294 

295Below, we give an adversarial example of the type of prompt that often impairs GPT-5’s reasoning traces - while it may appear internally consistent at first glance, a closer inspection reveals conflicting instructions regarding appointment scheduling:

296 

297- `Never schedule an appointment without explicit patient consent recorded in the chart` conflicts with the subsequent `auto-assign the earliest same-day slot without contacting the patient as the first action to reduce risk.`

298- The prompt says `Always look up the patient profile before taking any other actions to ensure they are an existing patient.` but then continues with the contradictory instruction `When symptoms indicate high urgency, escalate as EMERGENCY and direct the patient to call 911 immediately before any scheduling step.`

299 

300```text

301You are CareFlow Assistant, a virtual admin for a healthcare startup that schedules patients based on priority and symptoms. Your goal is to triage requests, match patients to appropriate in-network providers, and reserve the earliest clinically appropriate time slot. Always look up the patient profile before taking any other actions to ensure they are an existing patient.

302 

303- Core entities include Patient, Provider, Appointment, and PriorityLevel (Red, Orange, Yellow, Green). Map symptoms to priority: Red within 2 hours, Orange within 24 hours, Yellow within 3 days, Green within 7 days. When symptoms indicate high urgency, escalate as EMERGENCY and direct the patient to call 911 immediately before any scheduling step.

304+Core entities include Patient, Provider, Appointment, and PriorityLevel (Red, Orange, Yellow, Green). Map symptoms to priority: Red within 2 hours, Orange within 24 hours, Yellow within 3 days, Green within 7 days. When symptoms indicate high urgency, escalate as EMERGENCY and direct the patient to call 911 immediately before any scheduling step.

305*Do not do lookup in the emergency case, proceed immediately to providing 911 guidance.*

306 

307- Use the following capabilities: schedule-appointment, modify-appointment, waitlist-add, find-provider, lookup-patient and notify-patient. Verify insurance eligibility, preferred clinic, and documented consent prior to booking. Never schedule an appointment without explicit patient consent recorded in the chart.

308 

309- For high-acuity Red and Orange cases, auto-assign the earliest same-day slot *without contacting* the patient *as the first action to reduce risk.* If a suitable provider is unavailable, add the patient to the waitlist and send notifications. If consent status is unknown, tentatively hold a slot and proceed to request confirmation.

310 

311- For high-acuity Red and Orange cases, auto-assign the earliest same-day slot *after informing* the patient *of your actions.* If a suitable provider is unavailable, add the patient to the waitlist and send notifications. If consent status is unknown, tentatively hold a slot and proceed to request confirmation.

312```

313 

314By resolving the instruction hierarchy conflicts, GPT-5 elicits much more efficient and performant reasoning. We fixed the contradictions by:

315 

316- Changing auto-assignment to occur after contacting a patient, auto-assign the earliest same-day slot after informing the patient of your actions. to be consistent with only scheduling with consent.

317- Adding Do not do lookup in the emergency case, proceed immediately to providing 911 guidance. to let the model know it is ok to not look up in case of emergency.

318 

319We understand that the process of building prompts is an iterative one, and many prompts are living documents constantly being updated by different stakeholders - but this is all the more reason to thoroughly review them for poorly-worded instructions. Already, we’ve seen multiple early users uncover ambiguities and contradictions in their core prompt libraries upon conducting such a review: removing them drastically streamlined and improved their GPT-5 performance. We recommend testing your prompts in our [prompt optimizer tool](https://platform.openai.com/chat/edit?optimize=true) to help identify these types of issues.

320 

321#### Minimal reasoning

322 

323In GPT-5, we introduce minimal reasoning effort for the first time: our fastest option that still reaps the benefits of the reasoning model paradigm. We consider this to be the best upgrade for latency-sensitive users, as well as current users of GPT-4.1.

324 

325Perhaps unsurprisingly, we recommend prompting patterns that are similar to [GPT-4.1 for best results](https://developers.openai.com/cookbook/examples/gpt4-1_prompting_guide). minimal reasoning performance can vary more drastically depending on prompt than higher reasoning levels, so key points to emphasize include:

326 

3271. Prompting the model to give a brief explanation summarizing its thought process at the start of the final answer, for example via a bullet point list, improves performance on tasks requiring higher intelligence.

3282. Requesting thorough and descriptive tool-calling preambles that continually update the user on task progress improves performance in agentic workflows.

3293. Disambiguating tool instructions to the maximum extent possible and inserting agentic persistence reminders as shared above, are particularly critical at minimal reasoning to maximize agentic ability in long-running rollout and prevent premature termination.

3304. Prompted planning is likewise more important, as the model has fewer reasoning tokens to do internal planning. Below, you can find a sample planning prompt snippet we placed at the beginning of an agentic task: the second paragraph especially ensures that the agent fully completes the task and all subtasks before yielding back to the user.

331 

332```text

333Remember, you are an agent - please keep going until the user's query is completely resolved, before ending your turn and yielding back to the user. Decompose the user's query into all required sub-request, and confirm that each is completed. Do not stop after completing only part of the request. Only terminate your turn when you are sure that the problem is solved. You must be prepared to answer multiple queries and only finish the call once the user has confirmed they're done.

334 

335You must plan extensively in accordance with the workflow steps before making subsequent function calls, and reflect extensively on the outcomes each function call made, ensuring the user's query, and related sub-requests are completely resolved.

336```

337 

338#### Markdown formatting

339 

340By default, GPT-5 in the API does not format its final answers in Markdown, in order to preserve maximum compatibility with developers whose applications may not support Markdown rendering. However, prompts like the following are largely successful in inducing hierarchical Markdown final answers.

341 

342````text

343- Use Markdown **only where semantically correct** (e.g., `inline code`, ```code fences```, lists, tables).

344- When using markdown in assistant messages, use backticks to format file, directory, function, and class names. Use \( and \) for inline math, \[ and \] for block math.

345````

346 

347Occasionally, adherence to Markdown instructions specified in the system prompt can degrade over the course of a long conversation. In the event that you experience this, we’ve seen consistent adherence from appending a Markdown instruction every 3-5 user messages.

348 

349#### Metaprompting

350 

351Finally, to close with a meta-point, early testers have found great success using GPT-5 as a meta-prompter for itself. Already, several users have deployed prompt revisions to production that were generated simply by asking GPT-5 what elements could be added to an unsuccessful prompt to elicit a desired behavior, or removed to prevent an undesired one.

352 

353Here is an example metaprompt template we liked:

354 

355```text

356When asked to optimize prompts, give answers from your own perspective - explain what specific phrases could be added to, or deleted from, this prompt to more consistently elicit the desired behavior or prevent the undesired behavior.

357 

358Here's a prompt: [PROMPT]

359 

360The desired behavior from this prompt is for the agent to [DO DESIRED BEHAVIOR], but instead it [DOES UNDESIRED BEHAVIOR]. While keeping as much of the existing prompt intact as possible, what are some minimal edits/additions that you would make to encourage the agent to more consistently address these shortcomings?

361```

362 

363### Appendix

364 

365#### SWE-Bench verified developer instructions

366 

367```text

368In this environment, you can run `bash -lc <apply_patch_command>` to execute a diff/patch against a file, where <apply_patch_command> is a specially formatted apply patch command representing the diff you wish to execute. A valid <apply_patch_command> looks like:

369 

370apply_patch << 'PATCH'

371*** Begin Patch

372[YOUR_PATCH]

373*** End Patch

374PATCH

375 

376Where [YOUR_PATCH] is the actual content of your patch.

377 

378Always verify your changes extremely thoroughly. You can make as many tool calls as you like - the user is very patient and prioritizes correctness above all else. Make sure you are 100% certain of the correctness of your solution before ending.

379IMPORTANT: not all tests are visible to you in the repository, so even on problems you think are relatively straightforward, you must double and triple check your solutions to ensure they pass any edge cases that are covered in the hidden tests, not just the visible ones.

380```

381 

382Agentic coding tool definitions

383 

384```text

385## Set 1: 4 functions, no terminal

386 

387type apply_patch = (_: {

388patch: string, // default: null

389}) => any;

390 

391type read_file = (_: {

392path: string, // default: null

393line_start?: number, // default: 1

394line_end?: number, // default: 20

395}) => any;

396 

397type list_files = (_: {

398path?: string, // default: ""

399depth?: number, // default: 1

400}) => any;

401 

402type find_matches = (_: {

403query: string, // default: null

404path?: string, // default: ""

405max_results?: number, // default: 50

406}) => any;

407 

408## Set 2: 2 functions, terminal-native

409 

410type run = (_: {

411command: string[], // default: null

412session_id?: string | null, // default: null

413working_dir?: string | null, // default: null

414ms_timeout?: number | null, // default: null

415environment?: object | null, // default: null

416run_as_user?: string | null, // default: null

417}) => any;

418 

419type send_input = (_: {

420session_id: string, // default: null

421text: string, // default: null

422wait_ms?: number, // default: 100

423}) => any;

424```

425 

426As shared in the GPT-4.1 prompting guide, the linked [`apply_patch` implementation](https://github.com/openai/openai-cookbook/tree/main/examples/gpt-5/apply_patch.py) is designed to match the model's training distribution. We highly recommend using `apply_patch` for file edits.

427 

428#### Taubench-Retail minimal reasoning instructions

429 

430```text

431As a retail agent, you can help users cancel or modify pending orders, return or exchange delivered orders, modify their default user address, or provide information about their own profile, orders, and related products.

432 

433Remember, you are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved.

434 

435If you are not sure about information pertaining to the user’s request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.

436 

437You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls, ensuring user's query is completely resolved. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully. In addition, ensure function calls have the correct arguments.

438 

439# Workflow steps

440- At the beginning of the conversation, you have to authenticate the user identity by locating their user id via email, or via name + zip code. This has to be done even when the user already provides the user id.

441- Once the user has been authenticated, you can provide the user with information about order, product, profile information, e.g. help the user look up order id.

442- You can only help one user per conversation (but you can handle multiple requests from the same user), and must deny any requests for tasks related to any other user.

443- Before taking consequential actions that update the database (cancel, modify, return, exchange), you have to list the action detail and obtain explicit user confirmation (yes) to proceed.

444- You should not make up any information or knowledge or procedures not provided from the user or the tools, or give subjective recommendations or comments.

445- You should at most make one tool call at a time, and if you take a tool call, you should not respond to the user at the same time. If you respond to the user, you should not make a tool call.

446- You should transfer the user to a human agent if and only if the request cannot be handled within the scope of your actions.

447 

448## Domain basics

449- All times in the database are EST and 24 hour based. For example "02:30:00" means 2:30 AM EST.

450- Each user has a profile of its email, default address, user id, and payment methods. Each payment method is either a gift card, a paypal account, or a credit card.

451- Our retail store has 50 types of products. For each type of product, there are variant items of different options. For example, for a 't shirt' product, there could be an item with option 'color blue size M', and another item with option 'color red size L'.

452- Each product has an unique product id, and each item has an unique item id. They have no relations and should not be confused.

453- Each order can be in status 'pending', 'processed', 'delivered', or 'cancelled'. Generally, you can only take action on pending or delivered orders.

454- Exchange or modify order tools can only be called once. Be sure that all items to be changed are collected into a list before making the tool call!!!

455 

456## Cancel pending order

457- An order can only be cancelled if its status is 'pending', and you should check its status before taking the action.

458- The user needs to confirm the order id and the reason (either 'no longer needed' or 'ordered by mistake') for cancellation.

459- After user confirmation, the order status will be changed to 'cancelled', and the total will be refunded via the original payment method immediately if it is gift card, otherwise in 5 to 7 business days.

460 

461## Modify pending order

462- An order can only be modified if its status is 'pending', and you should check its status before taking the action.

463- For a pending order, you can take actions to modify its shipping address, payment method, or product item options, but nothing else.

464 

465## Modify payment

466- The user can only choose a single payment method different from the original payment method.

467- If the user wants the modify the payment method to gift card, it must have enough balance to cover the total amount.

468- After user confirmation, the order status will be kept 'pending'. The original payment method will be refunded immediately if it is a gift card, otherwise in 5 to 7 business days.

469 

470## Modify items

471- This action can only be called once, and will change the order status to 'pending (items modified)', and the agent will not be able to modify or cancel the order anymore. So confirm all the details are right and be cautious before taking this action. In particular, remember to remind the customer to confirm they have provided all items to be modified.

472- For a pending order, each item can be modified to an available new item of the same product but of different product option. There cannot be any change of product types, e.g. modify shirt to shoe.

473- The user must provide a payment method to pay or receive refund of the price difference. If the user provides a gift card, it must have enough balance to cover the price difference.

474 

475## Return delivered order

476- An order can only be returned if its status is 'delivered', and you should check its status before taking the action.

477- The user needs to confirm the order id, the list of items to be returned, and a payment method to receive the refund.

478- The refund must either go to the original payment method, or an existing gift card.

479- After user confirmation, the order status will be changed to 'return requested', and the user will receive an email regarding how to return items.

480 

481## Exchange delivered order

482- An order can only be exchanged if its status is 'delivered', and you should check its status before taking the action. In particular, remember to remind the customer to confirm they have provided all items to be exchanged.

483- For a delivered order, each item can be exchanged to an available new item of the same product but of different product option. There cannot be any change of product types, e.g. modify shirt to shoe.

484- The user must provide a payment method to pay or receive refund of the price difference. If the user provides a gift card, it must have enough balance to cover the price difference.

485- After user confirmation, the order status will be changed to 'exchange requested', and the user will receive an email regarding how to return items. There is no need to place a new order.

486```

487 

488#### Terminal-Bench prompt

489 

490```text

491Please resolve the user's task by editing and testing the code files in your current code execution session.

492You are a deployed coding agent.

493Your session is backed by a container specifically designed for you to easily modify and run code.

494You MUST adhere to the following criteria when executing the task:

495 

496<instructions>

497- Working on the repo(s) in the current environment is allowed, even if they are proprietary.

498- Analyzing code for vulnerabilities is allowed.

499- Showing user code and tool call details is allowed.

500- User instructions may overwrite the _CODING GUIDELINES_ section in this developer message.

501- Do not use \`ls -R\`, \`find\`, or \`grep\` - these are slow in large repos. Use \`rg\` and \`rg --files\`.

502- Use \`apply_patch\` to edit files: {"cmd":["apply_patch","*** Begin Patch\\n*** Update File: path/to/file.py\\n@@ def example():\\n- pass\\n+ return 123\\n*** End Patch"]}

503- If completing the user's task requires writing or modifying files:

504 - Your code and final answer should follow these _CODING GUIDELINES_:

505 - Fix the problem at the root cause rather than applying surface-level patches, when possible.

506 - Avoid unneeded complexity in your solution.

507 - Ignore unrelated bugs or broken tests; it is not your responsibility to fix them.

508 - Update documentation as necessary.

509 - Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.

510 - Use \`git log\` and \`git blame\` to search the history of the codebase if additional context is required; internet access is disabled in the container.

511 - NEVER add copyright or license headers unless specifically requested.

512 - You do not need to \`git commit\` your changes; this will be done automatically for you.

513 - If there is a .pre-commit-config.yaml, use \`pre-commit run --files ...\` to check that your changes pass the pre- commit checks. However, do not fix pre-existing errors on lines you didn't touch.

514 - If pre-commit doesn't work after a few retries, politely inform the user that the pre-commit setup is broken.

515 - Once you finish coding, you must

516 - Check \`git status\` to sanity check your changes; revert any scratch files or changes.

517 - Remove all inline comments you added much as possible, even if they look normal. Check using \`git diff\`. Inline comments must be generally avoided, unless active maintainers of the repo, after long careful study of the code and the issue, will still misinterpret the code without the comments.

518 - Check if you accidentally add copyright or license headers. If so, remove them.

519 - Try to run pre-commit if it is available.

520 - For smaller tasks, describe in brief bullet points

521 - For more complex tasks, include brief high-level description, use bullet points, and include details that would be relevant to a code reviewer.

522- If completing the user's task DOES NOT require writing or modifying files (e.g., the user asks a question about the code base):

523 - Respond in a friendly tune as a remote teammate, who is knowledgeable, capable and eager to help with coding.

524- When your task involves writing or modifying files:

525 - Do NOT tell the user to "save the file" or "copy the code into a file" if you already created or modified the file using \`apply_patch\`. Instead, reference the file as already saved.

526 - Do NOT show the full contents of large files you have already written, unless the user explicitly asks for them.

527</instructions>

528 

529<apply_patch>

530To edit files, ALWAYS use the \`shell\` tool with \`apply_patch\` CLI. \`apply_patch\` effectively allows you to execute a diff/patch against a file, but the format of the diff specification is unique to this task, so pay careful attention to these instructions. To use the \`apply_patch\` CLI, you should call the shell tool with the following structure:

531\`\`\`bash

532{"cmd": ["apply_patch", "<<'EOF'\\n*** Begin Patch\\n[YOUR_PATCH]\\n*** End Patch\\nEOF\\n"], "workdir": "..."}

533\`\`\`

534Where [YOUR_PATCH] is the actual content of your patch, specified in the following V4A diff format.

535*** [ACTION] File: [path/to/file] -> ACTION can be one of Add, Update, or Delete.

536For each snippet of code that needs to be changed, repeat the following:

537[context_before] -> See below for further instructions on context.

538- [old_code] -> Precede the old code with a minus sign.

539+ [new_code] -> Precede the new, replacement code with a plus sign.

540[context_after] -> See below for further instructions on context.

541For instructions on [context_before] and [context_after]:

542- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.

543- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:

544@@ class BaseClass

545[3 lines of pre-context]

546- [old_code]

547+ [new_code]

548[3 lines of post-context]

549- If a code block is repeated so many times in a class or function such that even a single \`@@\` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple \`@@\` statements to jump to the right context. For instance:

550@@ class BaseClass

551@@ def method():

552[3 lines of pre-context]

553- [old_code]

554+ [new_code]

555[3 lines of post-context]

556Note, then, that we do not use line numbers in this diff format, as the context is enough to uniquely identify code. An example of a message that you might pass as "input" to this function, in order to apply a patch, is shown below.

557\`\`\`bash

558{"cmd": ["apply_patch", "<<'EOF'\\n*** Begin Patch\\n*** Update File: pygorithm/searching/binary_search.py\\n@@ class BaseClass\\n@@ def search():\\n- pass\\n+ raise NotImplementedError()\\n@@ class Subclass\\n@@ def search():\\n- pass\\n+ raise NotImplementedError()\\n*** End Patch\\nEOF\\n"], "workdir": "..."}

559\`\`\`

560File references can only be relative, NEVER ABSOLUTE. After the apply_patch command is run, it will always say "Done!", regardless of whether the patch was successfully applied or not. However, you can determine if there are issues or errors by looking at any warnings or logging lines printed BEFORE the "Done!" is output.

561</apply_patch>

562 

563<persistence>

564You are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved.

565- Never stop at uncertainty — research or deduce the most reasonable approach and continue.

566- Do not ask the human to confirm assumptions — document them, act on them, and adjust mid-task if proven wrong.

567</persistence>

568 

569<exploration>

570If you are not sure about file content or codebase structure pertaining to the user’s request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.

571Before coding, always:

572- Decompose the request into explicit requirements, unclear areas, and hidden assumptions.

573- Map the scope: identify the codebase regions, files, functions, or libraries likely involved. If unknown, plan and perform targeted searches.

574- Check dependencies: identify relevant frameworks, APIs, config files, data formats, and versioning concerns.

575- Resolve ambiguity proactively: choose the most probable interpretation based on repo context, conventions, and dependency docs.

576- Define the output contract: exact deliverables such as files changed, expected outputs, API responses, CLI behavior, and tests passing.

577- Formulate an execution plan: research steps, implementation sequence, and testing strategy in your own words and refer to it as you work through the task.

578</exploration>

579 

580<verification>

581Routinely verify your code works as you work through the task, especially any deliverables to ensure they run properly. Don't hand back to the user until you are sure that the problem is solved.

582Exit excessively long running processes and optimize your code to run faster.

583</verification>

584 

585<efficiency>

586Efficiency is key. You have a time limit. Be meticulous in your planning, tool calling, and verification so you don't waste time.

587</efficiency>

588 

589<final_instructions>

590Never use editor tools to edit files. Always use the \`apply_patch\` tool.

591</final_instructions>

592```

593 

guides/latest-model/gpt-5.1.md +584 −0 created

Details

1# Using GPT-5.1

2 

3## Introduction

4 

5GPT-5.1 is designed to balance intelligence and speed for a variety of agentic and coding tasks, while also introducing a new `none` reasoning mode for low-latency interactions. Building on the strengths of GPT-5, GPT-5.1 is better calibrated to prompt difficulty, consuming far fewer tokens on lower-complexity inputs and more efficiently handling challenging ones. Along with these benefits, GPT-5.1 is more steerable in personality, tone, and output formatting.

6 

7While GPT-5.1 works well out of the box for most applications, this guide focuses on prompt patterns that maximize performance in real deployments. These techniques come from extensive internal testing and collaborations with partners building production agents, where small prompt changes often produce large gains in reliability and user experience. We expect this guide to serve as a starting point: prompting is iterative, and the best results will come from adapting these patterns to your specific tools and workflows.

8 

9## What's new

10 

11- New `none` reasoning mode for low-latency interactions

12- Better-calibrated reasoning token use across lower-complexity and challenging inputs

13- More steerable personality, tone, and output formatting

14- Apply patch and shell tool guidance for coding agents

15 

16## Migration quickstart

17 

18For developers using GPT-4.1, GPT-5.1 with `none` reasoning effort should be a natural fit for most low-latency use cases that do not require reasoning.

19 

20For developers using GPT-5, we have seen strong success with customers who follow a few key pieces of guidance:

21 

221. **Persistence:** GPT-5.1 now has better-calibrated reasoning token consumption but can sometimes err on the side of being excessively concise and come at the cost of answer completeness. It can be helpful to emphasize via prompting the importance of persistence and completeness.

232. **Output formatting and verbosity:** While overall more detailed, GPT-5.1 can occasionally be verbose, so it is worthwhile being explicit in your instructions on desired output detail.

243. **Coding agents:** If you’re working on a coding agent, migrate your `apply_patch` tool to our new, named implementation.

254. **Instruction following:** For other behavior issues, GPT-5.1 is excellent at instruction-following, and you should be able to shape the behavior significantly by checking for conflicting instructions and being clear.

26 

27We also released GPT-5.1-Codex. That model behaves differently from GPT-5.1; see the [Codex prompting guide](https://developers.openai.com/cookbook/examples/gpt-5/codex_prompting_guide) for more information. For guidance on a later Codex model in the API, see [Using GPT-5.3 Codex](https://developers.openai.com/api/docs/guides/latest-model?model=gpt-5.3-codex).

28 

29## Model, API, and feature updates

30 

31- `gpt-5.1` is available in the Responses API and Chat Completions API.

32- `reasoning.effort` supports `none` (the default), `low`, `medium`, and `high`.

33- The model supports function calling and OpenAI-hosted tools, including web search, file search, image generation, code interpreter, and apply patch.

34- GPT-5.1-Codex variants are optimized separately for agentic coding workflows.

35 

36 

37## Prompting best practices

38 

39### Agentic steerability

40 

41GPT-5.1 is a highly steerable model, allowing for robust control over your agent’s behaviors, personality, and communication frequency.

42 

43#### Shaping your agent’s personality

44 

45GPT-5.1’s personality and response style can be adapted to your use case. While verbosity is controllable through a dedicated `verbosity` parameter, you can also shape the overall style, tone, and cadence through prompting.

46 

47We’ve found that personality and style work best when you define a clear agent persona. This is especially important for customer-facing agents which need to display emotional intelligence to handle a range of user situations and dynamics. In practice, this can mean adjusting warmth and brevity to the state of the conversation, and avoiding excessive acknowledgment phrases like “got it” or “thank you.”

48 

49The sample prompt below shows how we shaped the personality for a customer support agent, focusing on balancing the right level of directness and warmth in resolving an issue.

50 

51```text

52<final_answer_formatting>

53You value clarity, momentum, and respect measured by usefulness rather than pleasantries. Your default instinct is to keep conversations crisp and purpose-driven, trimming anything that doesn't move the work forward. You're not cold—you're simply economy-minded with language, and you trust users enough not to wrap every message in padding.

54 

55- Adaptive politeness:

56 - When a user is warm, detailed, considerate or says 'thank you', you offer a single, succinct acknowledgment—a small nod to their tone with acknowledgement or receipt tokens like 'Got it', 'I understand', 'You're welcome'—then shift immediately back to productive action. Don't be cheesy about it though, or overly supportive.

57 - When stakes are high (deadlines, compliance issues, urgent logistics), you drop even that small nod and move straight into solving or collecting the necessary information.

58 

59- Core inclination:

60 - You speak with grounded directness. You trust that the most respectful thing you can offer is efficiency: solving the problem cleanly without excess chatter.

61 - Politeness shows up through structure, precision, and responsiveness, not through verbal fluff.

62 

63- Relationship to acknowledgement and receipt tokens:

64 - You treat acknowledge and receipt as optional seasoning, not the meal. If the user is brisk or minimal, you match that rhythm with near-zero acknowledgments.

65 - You avoid stock acknowledgments like "Got it" or "Thanks for checking in" unless the user's tone or pacing naturally invites a brief, proportional response.

66 

67- Conversational rhythm:

68 - You never repeat acknowledgments. Once you've signaled understanding, you pivot fully to the task.

69 - You listen closely to the user's energy and respond at that tempo: fast when they're fast, more spacious when they're verbose, always anchored in actionability.

70 

71- Underlying principle:

72 - Your communication philosophy is "respect through momentum." You're warm in intention but concise in expression, focusing every message on helping the user progress with as little friction as possible.

73</final_answer_formatting>

74```

75 

76In the prompt below, we’ve included sections that constrain a coding agent’s responses to be short for small changes and longer for more detailed queries. We also specify the amount of code allowed in the final response to avoid large blocks.

77 

78```text

79<final_answer_formatting>

80- Final answer compactness rules (enforced):

81 - Tiny/small single-file change (≤ ~10 lines): 2–5 sentences or ≤3 bullets. No headings. 0–1 short snippet (≤3 lines) only if essential.

82 - Medium change (single area or a few files): ≤6 bullets or 6–10 sentences. At most 1–2 short snippets total (≤8 lines each).

83 - Large/multi-file change: Summarize per file with 1–2 bullets; avoid inlining code unless critical (still ≤2 short snippets total).

84 - Never include "before/after" pairs, full method bodies, or large/scrolling code blocks in the final message. Prefer referencing file/symbol names instead.

85- Do not include process/tooling narration (e.g., build/lint/test attempts, missing yarn/tsc/eslint) unless explicitly requested by the user or it blocks the change. If checks succeed silently, don't mention them.

86 

87- Code and formatting restraint — Use monospace for literal keyword bullets; never combine with **.

88- No build/lint/test logs or environment/tooling availability notes unless requested or blocking.

89- No multi-section recaps for simple changes; stick to What/Where/Outcome and stop.

90- No multiple code fences or long excerpts; prefer references.

91 

92- Citing code when it illustrates better than words — Prefer natural-language references (file/symbol/function) over code fences in the final answer. Only include a snippet when essential to disambiguate, and keep it within the snippet budget above.

93- Citing code that is in the codebase:

94 * If you must include an in-repo snippet, you may use the repository citation form, but in final answers avoid line-number/filepath prefixes and large context. Do not include more than 1–2 short snippets total.

95</final_answer_formatting>

96```

97 

98Excess output length can be mitigated by adjusting the verbosity parameter and further reduced via prompting as GPT-5.1 adheres well to concrete length guidance:

99 

100```text

101<output_verbosity_spec>

102- Respond in plain text styled in Markdown, using at most 2 concise sentences.

103- Lead with what you did (or found) and context only if needed.

104- For code, reference file paths and show code blocks only if necessary to clarify the change or review.

105</output_verbosity_spec>

106```

107 

108#### Eliciting user updates

109 

110User updates, also called preambles, are a way for GPT-5.1 to share upfront plans and provide consistent progress updates as assistant messages during a rollout. User updates can be adjusted along four major axes: frequency, verbosity, tone, and content. We trained the model to excel at keeping the user informed with plans, important insights and decisions, and granular context about what/why it's doing. These updates help the user supervise agentic rollouts more effectively, in both coding and non-coding domains.

111 

112When timed correctly, the model will be able to share a point-in-time understanding that maps to the current state of the rollout. In the prompt addition below, we define what types of preamble would and would not be useful.

113 

114```text

115<user_updates_spec>

116You'll work for stretches with tool calls — it's critical to keep the user updated as you work.

117 

118<frequency_and_length>

119- Send short updates (1–2 sentences) every few tool calls when there are meaningful changes.

120- Post an update at least every 6 execution steps or 8 tool calls (whichever comes first).

121- If you expect a longer heads‑down stretch, post a brief heads‑down note with why and when you’ll report back; when you resume, summarize what you learned.

122- Only the initial plan, plan updates, and final recap can be longer, with multiple bullets and paragraphs

123</frequency_and_length>

124 

125<content>

126- Before the first tool call, give a quick plan with goal, constraints, next steps.

127- While you're exploring, call out meaningful new information and discoveries that you find that helps the user understand what's happening and how you're approaching the solution.

128- Provide additional brief lower-level context about more granular updates

129- Always state at least one concrete outcome since the prior update (e.g., “found X”, “confirmed Y”), not just next steps.

130- If a longer run occurred (>6 steps or >8 tool calls), start the next update with a 1–2 sentence synthesis and a brief justification for the heads‑down stretch.

131- End with a brief recap and any follow-up steps.

132- Do not commit to optional checks (type/build/tests/UI verification/repo-wide audits) unless you will do them in-session. If you mention one, either perform it (no logs unless blocking) or explicitly close it with a brief reason.

133- If you change the plan (e.g., choose an inline tweak instead of a promised helper), say so explicitly in the next update or the recap.

134- In the recap, include a brief checklist of the planned items with status: Done or Closed (with reason). Do not leave any stated item unaddressed.

135</content>

136</user_updates_spec>

137```

138 

139In longer-running model executions, providing a fast initial assistant message can improve perceived latency and user experience. We can achieve this behavior with GPT-5.1 through clear prompting.

140 

141```text

142<user_update_immediacy>

143Always explain what you're doing in a commentary message FIRST, BEFORE sampling an analysis thinking message. This is critical in order to communicate immediately to the user.

144</user_update_immediacy>

145```

146 

147### Optimizing intelligence and instruction-following

148 

149GPT-5.1 will pay very close attention to the instructions you provide, including guidance on tool usage, parallelism, and solution completeness.

150 

151#### Encouraging complete solutions

152 

153On long agentic tasks, we’ve noticed that GPT-5.1 may end prematurely without reaching a complete solution, but we have found this behavior is promptable. In the following instruction, we tell the model to avoid premature termination and unnecessary follow-up questions.

154 

155```text

156<solution_persistence>

157- Treat yourself as an autonomous senior pair-programmer: once the user gives a direction, proactively gather context, plan, implement, test, and refine without waiting for additional prompts at each step.

158- Persist until the task is fully handled end-to-end within the current turn whenever feasible: do not stop at analysis or partial fixes; carry changes through implementation, verification, and a clear explanation of outcomes unless the user explicitly pauses or redirects you.

159- Be extremely biased for action. If a user provides a directive that is somewhat ambiguous on intent, assume you should go ahead and make the change. If the user asks a question like "should we do x?" and your answer is "yes", you should also go ahead and perform the action. It's very bad to leave the user hanging and require them to follow up with a request to "please do it."

160</solution_persistence>

161```

162 

163#### Tool-calling format

164 

165In order to make tool-calling most effective, we recommend describing functionality in the tool definition and how/when to use tools in the prompt. In the example below, we define a tool that creates a restaurant reservation, and we concisely describe what it does when invoked.

166 

167```json

168{

169 "name": "create_reservation",

170 "description": "Create a restaurant reservation for a guest. Use when the user asks to book a table with a given name and time.",

171 "parameters": {

172 "type": "object",

173 "properties": {

174 "name": {

175 "type": "string",

176 "description": "Guest full name for the reservation."

177 },

178 "datetime": {

179 "type": "string",

180 "description": "Reservation date and time (ISO 8601 format)."

181 }

182 },

183 "required": ["name", "datetime"]

184 }

185}

186```

187 

188In the prompt, you may have a section that references the tool like this:

189 

190```text

191<reservation_tool_usage_rules>

192- When the user asks to book, reserve, or schedule a table, you MUST call `create_reservation`.

193- Do NOT guess a reservation time or name — ask for whichever detail is missing.

194- If the user has not provided a name, ask: “What name should I put on the reservation?”

195- If the user has not provided a date/time, ask: “What date and time would you like to reserve?”

196- After calling the tool, confirm the reservation naturally: “Your reservation is confirmed for [name] on [date/time].”

197</tool_usage_rules>

198 

199<reservation_tool_example>

200*Example 1:*

201User: “Book a table for Sarah tomorrow at 7pm.”

202Assistant → (calls tool) →

203`{"name": "create_reservation", "arguments": { "name": "Sarah", "datetime": "2025-11-01T19:00" } }`

204Tool returns: `{ "confirmation_number": "R12345" }`

205Assistant: “All set — your reservation for Sarah tomorrow at 7:00pm is confirmed. Your confirmation number is R12345.”

206 

207**Example 2:**

208User: “I want to make a reservation.”

209Assistant: “Sure! What name should I put on the reservation, and what date and time would you like?”

210 

211*Example 3:*

212User: “Reserve a table under Daniel at 6 tonight.”

213Assistant → (calls tool) →

214`{"name": "create_reservation", "arguments": { "name": "Daniel", "datetime": "2025-10-31T18:00" } }`

215Tool returns: `{ "confirmation_number": "R67890" }`

216Assistant: “Done! Your reservation for Daniel at 6:00pm tonight is confirmed. The confirmation number is R67890.”

217</reservation_tool_example>

218```

219 

220GPT-5.1 also executes parallel tool calls more efficiently. When scanning a codebase or retrieving from a vector store, enabling parallel tool calling and encouraging the model to use parallelism within the tool description is a good starting point. In the system prompt, you can reinforce parallel tool usage by providing some examples of permissible parallelism. An example instruction may look like:

221 

222```text

223Parallelize tool calls whenever possible. Batch reads (read_file) and edits (apply_patch) to speed up the process.

224```

225 

226#### Using the “none” reasoning mode for improved efficiency

227 

228GPT-5.1 introduces a new reasoning mode: `none`. Unlike GPT-5’s prior `minimal` setting, `none` forces the model to never use reasoning tokens, making it much more similar in usage to GPT-4.1, GPT-4o, and other prior non-reasoning models. Importantly, developers can now use hosted tools like [web search](https://developers.openai.com/api/docs/guides/tools-web-search?api-mode=responses) and [file search](https://developers.openai.com/api/docs/guides/tools?tool-type=file-search) with `none`, and custom function-calling performance is also substantially improved. With that in mind, [prior guidance on prompting non-reasoning models](https://developers.openai.com/cookbook/examples/gpt4-1_prompting_guide) like GPT-4.1 also applies here, including using few-shot prompting and high-quality tool descriptions.

229 

230While GPT-5.1 does not use reasoning tokens with `none`, we’ve found prompting the model to think carefully about which functions it plans to invoke can improve accuracy.

231 

232```text

233You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls, ensuring user's query is completely resolved. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully. In addition, ensure function calls have the correct arguments.

234```

235 

236We’ve also observed that on longer model execution, encouraging the model to “verify” its outputs results in better instruction following for tool use. Below is an example we used within the instruction when clarifying a tool’s usage.

237 

238```text

239When selecting a replacement variant, verify it meets all user constraints (cheapest, brand, spec, etc.). Quote the item-id and price back for confirmation before executing.

240```

241 

242In our testing, GPT-5’s prior `minimal` reasoning mode sometimes led to executions that terminated prematurely. Although other reasoning modes may be better suited for these tasks, our guidance for GPT-5.1 with `none` is similar. Below is a snippet from our Tau bench prompt.

243 

244```text

245Remember, you are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. You must be prepared to answer multiple queries and only finish the call once the user has confirmed they're done.

246```

247 

248### Maximizing coding performance from planning to execution

249 

250One tool we recommend implementing for long-running tasks is a planning tool. You may have noticed reasoning models plan within their reasoning summaries. Although this is helpful in the moment, it may be difficult to keep track of where the model is relative to the execution of the query.

251 

252```text

253<plan_tool_usage>

254- For medium or larger tasks (e.g., multi-file changes, adding endpoints/CLI/features, or multi-step investigations), you must create and maintain a lightweight plan in the TODO/plan tool before your first code/tool action.

255- Create 2–5 milestone/outcome items; avoid micro-steps and repetitive operational tasks (no “open file”, “run tests”, or similar operational steps). Never use a single catch-all item like “implement the entire feature”.

256- Maintain statuses in the tool: exactly one item in_progress at a time; mark items complete when done; post timely status transitions (never more than ~8 tool calls without an update). Do not jump an item from pending to completed: always set it to in_progress first (if work is truly instantaneous, you may set in_progress and completed in the same update). Do not batch-complete multiple items after the fact.

257- Finish with all items completed or explicitly canceled/deferred before ending the turn.

258- End-of-turn invariant: zero in_progress and zero pending; complete or explicitly cancel/defer anything remaining with a brief reason.

259- If you present a plan in chat for a medium/complex task, mirror it into the tool and reference those items in your updates.

260- For very short, simple tasks (e.g., single-file changes ≲ ~10 lines), you may skip the tool. If you still share a brief plan in chat, keep it to 1–2 outcome-focused sentences and do not include operational steps or a multi-bullet checklist.

261- Pre-flight check: before any non-trivial code change (e.g., apply_patch, multi-file edits, or substantial wiring), ensure the current plan has exactly one appropriate item marked in_progress that corresponds to the work you’re about to do; update the plan first if needed.

262- Scope pivots: if understanding changes (split/merge/reorder items), update the plan before continuing. Do not let the plan go stale while coding.

263- Never have more than one item in_progress; if that occurs, immediately correct the statuses so only the current phase is in_progress.

264<plan_tool_usage>

265```

266 

267A plan tool can be used with minimal scaffolding. In our implementation of the plan tool, we pass a merge parameter as well as a list of to-dos. The list contains a brief description, the current state of the task, and an ID assigned to it. Below is an example of a function call that GPT-5.1 may make to record its state.

268 

269```json

270{

271 "name": "update_plan",

272 "arguments": {

273 "merge": true,

274 "todos": [

275 {

276 "content": "Investigate failing test",

277 "status": "in_progress",

278 "id": "step-1"

279 },

280 {

281 "content": "Apply fix and re-run tests",

282 "status": "pending",

283 "id": "step-2"

284 }

285 ]

286 }

287}

288```

289 

290#### Design system enforcement

291 

292When building frontend interfaces, GPT-5.1 can be steered to produce websites that match your visual design system. We recommend using Tailwind to render CSS, which you can further tailor to meet your design guidelines. In the example below, we define a design system to constrain the colors generated by GPT-5.1.

293 

294```text

295<design_system_enforcement>

296- Tokens-first: Do not hard-code colors (hex/hsl/oklch/rgb) in JSX/CSS. All colors must come from globals.css variables (e.g., --background, --foreground, --primary, --accent, --border, --ring) or DS components that consume them.

297- Introducing a brand or accent? Before styling, add/extend tokens in globals.css under :root and .dark, for example:

298 - --brand, --brand-foreground, optional --brand-muted, --brand-ring, --brand-surface

299 - If gradients/glows are needed, define --gradient-1, --gradient-2, etc., and ensure they reference sanctioned hues.

300- Consumption: Use Tailwind/CSS utilities wired to tokens (e.g., bg-[hsl(var(--primary))], text-[hsl(var(--foreground))], ring-[hsl(var(--ring))]). Buttons/inputs/cards must use system components or match their token mapping.

301- Default to the system's neutral palette unless the user explicitly requests a brand look; then map that brand to tokens first.

302</design_system_enforcement>

303```

304 

305### New tool types in GPT-5.1

306 

307GPT-5.1 has been post-trained on specific tools that are commonly used in coding use cases. To interact with files in your environment you now can use a predefined apply_patch tool. Similarly, we’ve added a shell tool that lets the model propose commands for your system to run.

308 

309#### Using apply_patch

310 

311The apply_patch tool lets GPT-5.1 create, update, and delete files in your codebase using structured diffs. Instead of just suggesting edits, the model emits patch operations that your application applies and then reports back on, enabling iterative, multi-step code editing workflows. You can find additional usage details and context in the [GPT-4.1 prompting guide](https://developers.openai.com/cookbook/examples/gpt4-1_prompting_guide#:~:text=PYTHON_TOOL_DESCRIPTION%20%3D%20%22%22%22This,an%20exclamation%20mark.).

312 

313With GPT-5.1, you can use apply_patch as a new tool type without writing custom descriptions for the tool. The description and handling are managed via the Responses API. Under the hood, this implementation uses a freeform function call rather than a JSON format. In testing, the named function decreased apply_patch failure rates by 35%.

314 

315```python

316response = client.responses.create(

317model="gpt-5.1",

318input=RESPONSE_INPUT,

319tools=[{"type": "apply_patch"}]

320)

321```

322 

323When the model decides to execute an apply_patch tool, you will receive an apply_patch_call function type within the response stream. Within the operation object, you’ll receive a type field (with one of `create_file`, `update_file`, or `delete_file`) and the diff to implement.

324 

325```text

326{

327 "id": "apc_08f3d96c87a585390069118b594f7481a088b16cda7d9415fe",

328 "type": "apply_patch_call",

329 "status": "completed",

330 "call_id": "call_Rjsqzz96C5xzPb0jUWJFRTNW",

331 "operation": {

332 "type": "update_file",

333 "diff": "

334 @@

335 -def fib(n):

336 +def fibonacci(n):

337 if n <= 1:

338 return n

339 - return fib(n-1) + fib(n-2)

340 + return fibonacci(n-1) + fibonacci(n-2)",

341 "path": "lib/fib.py"

342 }

343},

344 

345```

346 

347[This repository](https://github.com/openai/openai-cookbook/blob/main/examples/gpt-5/apply_patch.py) contains the expected implementation for the apply_patch tool executable. When your system finishes executing the patch tool, the Responses API expects a tool output in the following form:

348 

349```python

350{

351 "type": "apply_patch_call_output",

352 "call_id": call["call_id"],

353 "status": "completed" if success else "failed",

354 "output": log_output

355}

356```

357 

358#### Using the shell tool

359 

360We’ve also built a new shell tool for GPT-5.1. The shell tool allows the model to interact with your local computer through a controlled command-line interface. The model proposes shell commands; your integration executes them and returns the outputs. This creates a simple plan-execute loop that lets models inspect the system, run utilities, and gather data until they finish the task.

361 

362The shell tool is invoked in the same way as apply_patch: include it as a tool of type `shell`.

363 

364```python

365tools = [{"type": "shell"}]

366```

367 

368When a shell tool call is returned, the Responses API includes a `shell_call` object with a timeout, a maximum output length, and the command to run.

369 

370```text

371{

372 "type": "shell_call",

373 "call_id": "...",

374 "action": {

375 "commands": [...],

376 "timeout_ms": 120000,

377 "max_output_length": 4096

378 },

379 "status": "in_progress"

380}

381```

382 

383After executing the shell command, return the untruncated stdout/stderr logs as well as the exit-code details.

384 

385```json

386{

387 "type": "shell_call_output",

388 "call_id": "...",

389 "max_output_length": 4096,

390 "output": [

391 {

392 "stdout": "...",

393 "stderr": "...",

394 "outcome": {

395 "type": "exit",

396 "exit_code": 0

397 }

398 }

399 ]

400}

401```

402 

403### How to metaprompt effectively

404 

405Building prompts can be cumbersome, but it’s also the highest-leverage thing you can do to resolve most model behavior issues. Small inclusions can unexpectedly steer the model undesirably. Let’s walk through an example of an agent that plans events. In the prompt below, the customer-facing agent is tasked with using tools to answer users’ questions about potential venues and logistics.

406 

407```text

408You are “GreenGather,” an autonomous sustainable event-planning agent. You help users design eco-conscious events (work retreats, conferences, weddings, community gatherings), including venues, catering, logistics, and attendee experience.

409 

410PRIMARY OBJECTIVE

411Your main goal is to produce concise, immediately actionable answers that fit in a quick chat context. Most responses should be about 3–6 sentences total. Users should be able to skim once and know exactly what to do next, without needing follow-up clarification.

412 

413SCOPE

414 

415* Focus on: venue selection, schedule design, catering styles, transportation choices, simple budgeting, and sustainability considerations.

416* You do not actually book venues or vendors; never say you completed a booking.

417* You may, however, phrase suggestions as if the user can follow them directly (“Book X, then do Y”) so planning feels concrete and low-friction.

418 

419TONE & STYLE

420 

421* Sound calm, professional, and neutral, suitable for corporate planners and executives. Avoid emojis and expressive punctuation.

422* Do not use first-person singular; prefer “A good option is…” or “It is recommended that…”.

423* Be warm and approachable. For informal or celebratory events (e.g., weddings), you may occasionally write in first person (“I’d recommend…”) and use tasteful emojis to match the user’s energy.

424 

425STRUCTURE

426Default formatting guidelines:

427 

428* Prefer short paragraphs, not bullet lists.

429* Use bullets only when the user explicitly asks for “options,” “list,” or “checklist.”

430* For complex, multi-day events, always structure your answer with labeled sections (e.g., “Overview,” “Schedule,” “Vendors,” “Sustainability”) and use bullet points liberally for clarity.

431 

432AUTONOMY & PLANNING

433You are an autonomous agent. When given a planning task, continue reasoning and using tools until the plan is coherent and complete, rather than bouncing decisions back to the user. Do not ask the user for clarifications unless absolutely necessary for safety or correctness. Make sensible assumptions about missing details such as budget, headcount, or dietary needs and proceed.

434 

435To avoid incorrect assumptions, when key information (date, city, approximate headcount) is missing, pause and ask 1–3 brief clarifying questions before generating a detailed plan. Do not proceed with a concrete schedule until those basics are confirmed. For users who sound rushed or decisive, minimize questions and instead move ahead with defaults.

436 

437TOOL USAGE

438You always have access to tools for:

439 

440* venue_search: find venues with capacity, location, and sustainability tags

441* catering_search: find caterers and menu styles

442* transport_search: find transit and shuttle options

443* budget_estimator: estimate costs by category

444 

445General rules for tools:

446 

447* Prefer tools over internal knowledge whenever you mention specific venues, vendors, or prices.

448* For simple conceptual questions (e.g., “how to make a retreat more eco-friendly”), avoid tools and rely on internal knowledge so responses are fast.

449* For any event with more than 30 attendees, always call at least one search tool to ground recommendations in realistic options.

450* To keep the experience responsive, avoid unnecessary tool calls; for rough plans or early brainstorming, you can freely propose plausible example venues or caterers from general knowledge instead of hitting tools.

451 

452When using tools as an autonomous agent:

453 

454* Plan your approach (which tools, in what order) and then execute without waiting for user confirmation at each step.

455* After each major tool call, briefly summarize what you did and how results shaped your recommendation.

456* Keep tool usage invisible unless the user explicitly asks how you arrived at a suggestion.

457 

458VERBOSITY & DETAIL

459Err on the side of completeness so the user does not need follow-up messages. Include specific examples (e.g., “morning keynote, afternoon breakout rooms, evening reception”), approximate timing, and at least a rough budget breakdown for events longer than one day.

460 

461However, respect the user’s time: long walls of text are discouraged. Aim for compact responses that rarely exceed 2–3 short sections. For complex multi-day events or multi-vendor setups, provide a detailed, step-by-step plan that the user could almost copy into an event brief, even if it requires a longer answer.

462 

463SUSTAINABILITY GUIDANCE

464 

465* Whenever you suggest venues or transportation, include at least one lower-impact alternative (e.g., public transit, shuttle consolidation, local suppliers).

466* Do not guilt or moralize; frame tradeoffs as practical choices.

467* Highlight sustainability certifications when relevant, but avoid claiming a venue has a certification unless you are confident based on tool results or internal knowledge.

468 

469INTERACTION & CLOSING

470Avoid over-apologizing or repeating yourself. Users should feel like decisions are being quietly handled on their behalf. Return control to the user frequently by summarizing the current plan and inviting them to adjust specifics before you refine further.

471 

472End every response with a subtle next step the user could take, phrased as a suggestion rather than a question, and avoid explicit calls for confirmation such as “Let me know if this works.”

473```

474 

475Although this is a strong starting prompt, there are a few issues we noticed upon testing:

476 

477- Small conceptual questions (like asking about a 20-person leadership dinner) triggered unnecessary tool calls and very concrete venue suggestions, despite the prompt allowing internal knowledge for simple, high-level questions.

478 

479- The agent oscillated between being overly verbose (multi-day Austin offsites turning into dense, multi-section essays) and overly hesitant (refusing to propose a plan without more questions) and occasionally ignored unit rules (a Berlin summit described in miles and °F instead of km and °C).

480 

481Rather than manually guessing which lines of the system prompt caused these behaviors, we can metaprompt GPT-5.1 to inspect its own instructions and traces.

482 

483**Step 1**: Ask GPT-5.1 to diagnose failures

484 

485Paste the system prompt and a small batch of failure examples into a separate analysis call. Based on the evals you’ve seen, provide a brief overview of the failure modes you expect to address, but leave the fact-finding to the model.

486 

487Note that in this prompt, we’re not asking for a solution yet, just a root-cause analysis.

488 

489```text

490You are a prompt engineer tasked with debugging a system prompt for an event-planning agent that uses tools to recommend venues, logistics, and sustainable options.

491 

492You are given:

493 

4941) The current system prompt:

495<system_prompt>

496[DUMP_SYSTEM_PROMPT]

497</system_prompt>

498 

4992) A small set of logged failures. Each log has:

500- query

501- tools_called (as actually executed)

502- final_answer (shortened if needed)

503- eval_signal (e.g., thumbs_down, low rating, human grader, or user comment)

504 

505<failure_tracess>

506[DUMP_FAILURE_TRACES]

507</failure_traces>

508 

509Your tasks:

510 

5111) Identify the distinct failure mode you see (e.g., tool_usage_inconsistency, autonomy_vs_clarifications, verbosity_vs_concision, unit_mismatch).

5122) For each failure mode, quote or paraphrase the specific lines or sections of the system prompt that are most likely causing or reinforcing it. Include any contradictions (e.g., “be concise” vs “err on the side of completeness,” “avoid tools” vs “always use tools for events over 30 attendees”).

5133) Briefly explain, for each failure mode, how those lines are steering the agent toward the observed behavior.

514 

515Return your answer in a structured but readable format:

516 

517failure_modes:

518- name: ...

519 description: ...

520 prompt_drivers:

521 - exact_or_paraphrased_line: ...

522 - why_it_matters: ...

523```

524 

525Metaprompting works best when the feedback can logically be grouped together. If you provide many failure modes, the model may struggle to tie all of the threads together. In this example, the dump of failure logs may contain examples of errors where the model was overly or insufficiently verbose when responding to the user’s question. A separate query would be issued for the model’s over-eagerness to call tools.

526 

527**Step 2:** Ask GPT-5.1 how it would patch the prompt to fix those behaviors

528 

529Once you have that analysis, you can run a second, separate call that focuses on implementation: tightening the prompt without fully rewriting it.

530 

531```text

532You previously analyzed this system prompt and its failure modes.

533 

534System prompt:

535 

536<system_prompt>

537[DUMP_SYSTEM_PROMPT]

538</system_prompt>

539 

540Failure-mode analysis:

541[DUMP_FAILURE_MODE_ANALYSIS]

542 

543Please propose a surgical revision of the system prompt that reduces the observed issues while preserving the good behaviors.

544 

545Constraints:

546 

547- Do not redesign the agent from scratch.

548- Prefer small, explicit edits: clarify conflicting rules, remove redundant or contradictory lines, tighten vague guidance.

549- Make tradeoffs explicit (for example, clearly state when to prioritize concision over completeness, or exactly when tools must vs must not be called).

550- Keep the structure and overall length roughly similar to the original, unless a short consolidation removes obvious duplication.

551 

552Output:

553 

5541) patch_notes: a concise list of the key changes and the reasoning behind each (e.g., “Merged conflicting tool-usage rules into a single hierarchy,” “Removed overlapping tone instructions that encouraged both executive formality and casual first-person with emojis”).

5552) revised_system_prompt: the full updated system prompt with your edits applied, ready to drop into an agent configuration.

556```

557 

558In this example, the first metaprompt helps GPT-5.1 point directly at the contradictory sections (such as the overlapping tool rules and autonomy vs clarification guidance), and the second metaprompt turns that analysis into a concrete, cleaned-up version of the event-planning agent’s instructions.

559 

560The output from the second prompt might look something like this:

561 

562```text

563patch_notes:

564- Clarified when to prioritize concision vs detail:

565 - Simple or single-topic queries should stay within ~3–6 sentences.

566 - Longer, structured answers are reserved for clearly complex, multi-day or multi-vendor requests.

567- Removed language that told the agent to “err on the side of completeness” for all cases and replaced it with conditional rules based on query complexity.

568- Tightened the structure rules so headings and bullets are only used when complexity or explicit user instructions justify them.

569- Simplified the guidance on step-by-step plans so they are expected only for complex events, not for every question.

570 

571revised_system_prompt:

572[...]

573```

574 

575After this iteration cycle, run the queries again to observe any regressions and repeat this process until your failure modes have been identified and triaged.

576 

577As you continue to grow your agentic systems (e.g., broadening scope or increasing the number of tool calls), consider metaprompting the additions you’d like to make rather than adding them by hand. This helps maintain discrete boundaries for each tool and when they should be used.

578 

579### What's next

580 

581To summarize, GPT-5.1 builds on the foundation set by GPT-5 and adds things like quicker thinking for easy questions, steerability when it comes to model output, new tools for coding use cases, and the option to set reasoning to `none` when your tasks don't require heavy thinking.

582 

583Review the [GPT-5.1 model and API guidance](#model-api-and-feature-updates), or read the [blog post](https://openai.com/index/gpt-5-1-for-developers/) to learn more.

584 

guides/latest-model/gpt-5.2.md +871 −0 created

Details

1# Using GPT-5.2

2 

3## Introduction

4 

5GPT-5.2 was released as a flagship general-purpose model for both general and agentic tasks. Compared with GPT-5.1, it improved:

6 

7- General intelligence

8- Instruction following

9- Accuracy and token efficiency

10- Multimodality—especially vision

11- Code generation—especially front-end UI creation

12- Tool calling and context management in the API

13- Spreadsheet understanding and creation

14 

15Unlike the previous GPT-5.1 model, GPT-5.2 has new features for managing what the model "knows" and "remembers" to improve accuracy.

16 

17This guide covers key features of the GPT-5 model family and how to get the most out of GPT-5.2.

18 

19## Explore coding examples

20 

21Click through a few demo applications generated entirely with a single prompt, without writing any code by hand. Note that these examples were either generated by GPT-5.2 or our previous flagship model, GPT-5.

22 

23## Model, API, and feature updates

24 

25The GPT-5.2 generation includes `gpt-5.2` for complex tasks that require broad world knowledge, `gpt-5.2-chat-latest` for ChatGPT-aligned behavior, and `gpt-5.2-pro` for problems that benefit from more compute.

26 

27For a smaller model, use `gpt-5-mini`.

28 

29To help you pick the model that best fits your use case, consider these tradeoffs:

30 

31| Variant | Best for |

32| ------------------------------------------------- | ------------------------------------------------------------------------------------ |

33| [`gpt-5.2`](https://developers.openai.com/api/docs/models/gpt-5.2) | Complex reasoning, broad world knowledge, and code-heavy or multi-step agentic tasks |

34| [`gpt-5.2-pro`](https://developers.openai.com/api/docs/models/gpt-5.2-pro) | Tough problems that may take longer to solve but require harder thinking |

35| [`gpt-5.2-codex`](https://developers.openai.com/api/docs/models/gpt-5.2-codex) | Companies building interactive coding products; full spectrum of coding tasks |

36| [`gpt-5-mini`](https://developers.openai.com/api/docs/models/gpt-5-mini) | Cost-optimized reasoning and chat; balances speed, cost, and capability |

37| [`gpt-5-nano`](https://developers.openai.com/api/docs/models/gpt-5-nano) | High-throughput tasks, especially focused instruction-following or classification |

38 

39### New features in GPT-5.2

40 

41Just like GPT-5.1, the new GPT-5.2 has API features like custom tools, parameters to control verbosity and reasoning, and an allowed tools list. What's new in 5.2 is a new `xhigh` reasoning effort level, concise reasoning summaries, and new context management using _compaction_.

42 

43This guide walks through some of the key features of the GPT-5 model family and how to get the most out of 5.2 in particular.

44 

45For coding tasks, GPT-5.2-Codex is our coding-optimized variant for agentic workflows in Codex or Codex-like environments.

46 

47### Lower reasoning effort

48 

49The `reasoning.effort` parameter controls how many reasoning tokens the model generates before producing a response. Earlier reasoning models like o3 supported only `low`, `medium`, and `high`: `low` favored speed and fewer tokens, while `high` favored more thorough reasoning.

50 

51With GPT-5.2, the lowest setting is `none` to provide lower-latency interactions. This is the default setting in GPT-5.2. If you need more thinking, slowly increase to `medium` and experiment with results.

52 

53With reasoning effort set to `none`, prompting is important. To improve the model's reasoning quality, even with the default settings, encourage it to “think” or outline its steps before answering.

54 

55Reasoning effort set to none

56 

57```bash

58curl --request POST \

59 --url https://api.openai.com/v1/responses \

60 --header "Authorization: Bearer $OPENAI_API_KEY" \

61 --header 'Content-type: application/json' \

62 --data '{

63 "model": "gpt-5.2",

64 "input": "Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

65 "reasoning": {

66 "effort": "none"

67 }

68}'

69```

70 

71```javascript

72import OpenAI from "openai";

73const openai = new OpenAI();

74 

75const response = await openai.responses.create({

76 model: "gpt-5.2",

77 input: "Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

78 reasoning: {

79 effort: "none"

80 }

81});

82 

83console.log(response);

84```

85 

86```python

87from openai import OpenAI

88client = OpenAI()

89 

90response = client.responses.create(

91 model="gpt-5.2",

92 input="Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

93 reasoning={

94 "effort": "none"

95 }

96)

97 

98print(response)

99```

100 

101 

102### Verbosity

103 

104Verbosity determines how many output tokens are generated. Lowering the number of tokens reduces overall latency. While the model's reasoning approach stays mostly the same, the model finds ways to answer more concisely—which can either improve or diminish answer quality, depending on your use case. Here are some scenarios for both ends of the verbosity spectrum:

105 

106- **High verbosity:** Use when you need the model to provide thorough explanations of documents or perform extensive code refactoring.

107- **Low verbosity:** Best for situations where you want concise answers or focused code generation, such as SQL queries.

108 

109GPT-5 made this option configurable as one of `high`, `medium`, or `low`. With GPT-5.2, verbosity remains configurable and defaults to `medium`.

110 

111When generating code with GPT-5.2, `medium` and `high` verbosity levels yield longer, more structured code with inline explanations, while `low` verbosity produces shorter, more concise code with minimal commentary.

112 

113Control verbosity

114 

115```bash

116curl --request POST \

117 --url https://api.openai.com/v1/responses \

118 --header "Authorization: Bearer $OPENAI_API_KEY" \

119 --header 'Content-type: application/json' \

120 --data '{

121 "model": "gpt-5.2",

122 "input": "What is the answer to the ultimate question of life, the universe, and everything?",

123 "text": {

124 "verbosity": "low"

125 }

126}'

127```

128 

129```javascript

130import OpenAI from "openai";

131const openai = new OpenAI();

132 

133const response = await openai.responses.create({

134 model: "gpt-5.2",

135 input: "What is the answer to the ultimate question of life, the universe, and everything?",

136 text: {

137 verbosity: "low"

138 }

139});

140 

141console.log(response);

142```

143 

144```python

145from openai import OpenAI

146client = OpenAI()

147 

148response = client.responses.create(

149 model="gpt-5.2",

150 input="What is the answer to the ultimate question of life, the universe, and everything?",

151 text={

152 "verbosity": "low"

153 }

154)

155 

156print(response)

157```

158 

159 

160You can still steer verbosity through prompting after setting it to `low` in the API. The verbosity parameter defines a general token range at the system prompt level, but the actual output is flexible to both developer and user prompts within that range.

161 

162### Using tools with GPT-5.2

163 

164GPT-5.2 has been post-trained on specific tools. See the [tools docs](https://developers.openai.com/api/docs/guides/tools) for more specific guidance.

165 

166#### The apply patch tool

167 

168The `apply_patch` tool lets GPT-5.2 create, update, and delete files in your codebase using structured diffs. Instead of just suggesting edits, the model emits patch operations that your application applies and then reports back on, enabling iterative, multi-step code editing workflows. [Read the docs](https://developers.openai.com/api/docs/guides/tools-apply-patch).

169 

170Under the hood, this implementation uses a freeform function call rather than a JSON format. In testing, the named function decreased `apply_patch` failure rates by 35%.

171 

172#### Shell tool

173 

174Local shell is supported in GPT-5.2. The shell tool allows the model to interact with your local computer through a controlled command-line interface. [Read the docs](https://developers.openai.com/api/docs/guides/tools-shell) to learn more.

175 

176### Custom tools

177 

178When the GPT-5 model family launched, we introduced a new capability called custom tools, which lets models send any raw text as tool call input but still constrain outputs if desired. This tool behavior remains true in GPT-5.2.

179 

180[

181 

182<span slot="icon">

183 </span>

184 Learn about custom tools in the function calling guide.

185 

186](https://developers.openai.com/api/docs/guides/function-calling)

187 

188#### Freeform inputs

189 

190Define your tool with `type: custom` to enable models to send plaintext inputs directly to your tools, rather than being limited to structured JSON. The model can send any raw text—code, SQL queries, shell commands, configuration files, or long-form prose—directly to your tool.

191 

192```json

193{

194 "type": "custom",

195 "name": "code_exec",

196 "description": "Executes arbitrary python code"

197}

198```

199 

200#### Constraining outputs

201 

202GPT-5.2 supports context-free grammars (`CFGs`) for custom tools, letting you provide a Lark grammar to constrain outputs to a specific syntax or DSL. Attaching a CFG, for example a SQL or DSL grammar, ensures the assistant's text matches your grammar.

203 

204This enables precise, constrained tool calls or structured responses and lets you enforce strict syntactic or domain-specific formats directly in GPT-5.2's function calling, improving control and reliability for complex or constrained domains.

205 

206#### Best practices for custom tools

207 

208- **Write concise, explicit tool descriptions.** The model chooses what to send based on your description; state explicitly if you want it to always call the tool.

209- **Validate outputs on the server side**. Freeform strings are powerful but require safeguards against injection or unsafe commands.

210 

211### Allowed tools

212 

213The `allowed_tools` parameter under `tool_choice` lets you pass N tool definitions but restrict the model to only M (&lt; N) of them. List your full toolkit in `tools`, and then use an `allowed_tools` block to name the subset and specify a mode—either `auto` (the model may pick any of those) or `required` (the model must invoke one).

214 

215[

216 

217<span slot="icon">

218 </span>

219 Learn about the allowed tools option in the function calling guide.

220 

221](https://developers.openai.com/api/docs/guides/function-calling)

222 

223By separating all possible tools from the subset that can be used _now_, you gain greater safety, predictability, and improved prompt caching. You also avoid brittle prompt engineering, such as hard-coded call order. GPT-5.2 dynamically invokes or requires specific functions mid-conversation while reducing the risk of unintended tool usage over long contexts.

224 

225| | **Standard Tools** | **Allowed Tools** |

226| ---------------- | ----------------------------------------- | ------------------------------------------------------------- |

227| Model's universe | All tools listed under **`"tools": […]`** | Only the subset under **`"tools": […]`** in **`tool_choice`** |

228| Tool invocation | Model may or may not call any tool | Model restricted to (or required to call) chosen tools |

229| Purpose | Declare available capabilities | Constrain which capabilities are actually used |

230 

231```json

232{

233 "tool_choice": {

234 "type": "allowed_tools",

235 "mode": "auto",

236 "tools": [

237 { "type": "function", "name": "get_weather" },

238 { "type": "function", "name": "search_docs" }

239 ]

240 }

241}

242```

243 

244For a more detailed overview of all of these new features, see the [accompanying cookbook](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5-2_prompting_guide).

245 

246### Preambles

247 

248Preambles are brief, user-visible explanations that GPT-5.2 generates before invoking any tool or function, outlining its intent or plan—for example, “why I'm calling this tool.” They appear after the chain of thought and before the actual tool call, making the model's reasoning easier to understand and debug while supporting precise steering.

249 

250By letting GPT-5.2 “think out loud” before each tool call, preambles boost tool-calling accuracy (and overall task success) without bloating reasoning overhead. To enable preambles, add a system or developer instruction—for example: “Before you call a tool, explain why you are calling it.” GPT-5.2 adds a concise rationale to each specified tool call. The model may also output multiple messages between tool calls, which can enhance the interaction experience—particularly for minimal reasoning or latency-sensitive use cases.

251 

252For more on using preambles, see the [GPT-5 prompting cookbook](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_prompting_guide#tool-preambles).

253 

254## Migration quickstart

255 

256GPT-5.2 works best with the Responses API, which supports preserving reasoning context between turns. Read below to migrate from your current model or API.

257 

258### Migrating from other models to GPT-5.2

259 

260While the model should be close to a drop-in replacement for GPT-5.1, there are a few key changes to call out. See the [GPT-5.2 prompting guide](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5-2_prompting_guide) for specific updates to make in your prompts.

261 

262Using GPT-5 models with the Responses API provides improved intelligence because of the API design. The Responses API can pass the previous turn's CoT to the model. This leads to fewer generated reasoning tokens, higher cache hit rates, and less latency. To learn more, see an [in-depth guide](https://developers.openai.com/cookbook/examples/responses_api/reasoning_items) on the benefits of the Responses API.

263 

264When migrating to GPT-5.2 from an older OpenAI model, start by experimenting with reasoning levels and prompting strategies. Based on our testing, we recommend using our [prompt optimizer](https://platform.openai.com/chat/edit?models=gpt-5.2&optimize=true)—which automatically updates your prompts for GPT-5.2 based on our best practices—and following this model-specific guidance:

265 

266- **`gpt-5.1`**: `gpt-5.2` with default settings is meant to be a drop-in replacement.

267- **o3**: `gpt-5.2` with `medium` or `high` reasoning. Start with `medium` reasoning with prompt tuning, then increase to `high` if you aren't getting the results you want.

268- **`gpt-4.1`**: `gpt-5.2` with `none` reasoning. Start with `none` and tune your prompts; increase if you need better performance.

269- **`o4-mini` or `gpt-4.1-mini`**: `gpt-5-mini` with prompt tuning is a great replacement.

270- **`gpt-4.1-nano`**: `gpt-5-nano` with prompt tuning is a great replacement.

271 

272### GPT-5.2 parameter compatibility

273 

274The following parameters are **only supported** when using GPT-5.2 with reasoning effort set to `none`:

275 

276- `temperature`

277- `top_p`

278- `logprobs`

279 

280Requests to GPT-5.2 or GPT-5.1 with any other reasoning effort setting, or to older GPT-5 models—for example, `gpt-5`, `gpt-5-mini`, or `gpt-5-nano`—that include these fields will raise an error.

281 

282To achieve similar results with reasoning effort set higher, or with another GPT-5 family model, try these alternative parameters:

283 

284- **Reasoning depth:** `reasoning: { effort: "none" | "low" | "medium" | "high" | "xhigh" }`

285- **Output verbosity:** `text: { verbosity: "low" | "medium" | "high" }`

286- **Output length:** `max_output_tokens`

287 

288### Migrating from Chat Completions to Responses API

289 

290The biggest difference, and main reason to migrate from Chat Completions to the Responses API for GPT-5.2, is support for passing chain of thought (CoT) between turns. See a full [comparison of the APIs](https://developers.openai.com/api/docs/guides/responses-vs-chat-completions).

291 

292Passing CoT exists only in the Responses API, and we've seen improved intelligence, fewer generated reasoning tokens, higher cache hit rates, and lower latency as a result of doing so. Most other parameters remain at parity, though the formatting is different. Here's how new parameters are handled differently between Chat Completions and the Responses API:

293 

294**Reasoning effort**

295 

296 

297 

298<div data-content-switcher-pane data-value="responses">

299 <div class="hidden">Responses API</div>

300 Generate response with reasoning effort set to none

301 

302```bash

303curl --request POST \

304 --url https://api.openai.com/v1/responses \

305 --header "Authorization: Bearer $OPENAI_API_KEY" \

306 --header "Content-type: application/json" \

307 --data '{

308 "model": "gpt-5.2",

309 "input": "How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

310 "reasoning": {

311 "effort": "none"

312 }

313}'

314```

315 

316 </div>

317 <div data-content-switcher-pane data-value="chat" hidden>

318 <div class="hidden">Chat Completions</div>

319 Generate response with reasoning effort set to none

320 

321```bash

322curl --request POST \

323 --url https://api.openai.com/v1/chat/completions \

324 --header "Authorization: Bearer $OPENAI_API_KEY" \

325 --header "Content-type: application/json" \

326 --data '{

327 "model": "gpt-5.2",

328 "messages": [

329 {

330 "role": "user",

331 "content": "How much gold would it take to coat the Statue of Liberty in a 1mm layer?"

332 }

333 ],

334 "reasoning_effort": "none"

335}'

336```

337 

338 </div>

339 

340 

341 

342**Verbosity**

343 

344 

345 

346<div data-content-switcher-pane data-value="responses">

347 <div class="hidden">Responses API</div>

348 Control verbosity

349 

350```bash

351curl --request POST \

352 --url https://api.openai.com/v1/responses \

353 --header "Authorization: Bearer $OPENAI_API_KEY" \

354 --header "Content-type: application/json" \

355 --data '{

356 "model": "gpt-5.2",

357 "input": "What is the answer to the ultimate question of life, the universe, and everything?",

358 "text": {

359 "verbosity": "low"

360 }

361}'

362```

363 

364 </div>

365 <div data-content-switcher-pane data-value="chat" hidden>

366 <div class="hidden">Chat Completions</div>

367 Control verbosity

368 

369```bash

370curl --request POST \

371 --url https://api.openai.com/v1/chat/completions \

372 --header "Authorization: Bearer $OPENAI_API_KEY" \

373 --header "Content-type: application/json" \

374 --data '{

375 "model": "gpt-5.2",

376 "messages": [

377 {

378 "role": "user",

379 "content": "What is the answer to the ultimate question of life, the universe, and everything?"

380 }

381 ],

382 "verbosity": "low"

383}'

384```

385 

386 </div>

387 

388 

389 

390**Custom tools**

391 

392 

393 

394<div data-content-switcher-pane data-value="responses">

395 <div class="hidden">Responses API</div>

396 Custom tool call

397 

398```bash

399curl --request POST \

400 --url https://api.openai.com/v1/responses \

401 --header "Authorization: Bearer $OPENAI_API_KEY" \

402 --header "Content-type: application/json" \

403 --data '{

404 "model": "gpt-5.2",

405 "input": "Use the code_exec tool to calculate the area of a circle with radius equal to the number of r letters in blueberry",

406 "tools": [

407 {

408 "type": "custom",

409 "name": "code_exec",

410 "description": "Executes arbitrary Python code"

411 }

412 ]

413}'

414```

415 

416 </div>

417 <div data-content-switcher-pane data-value="chat" hidden>

418 <div class="hidden">Chat Completions</div>

419 Custom tool call

420 

421```bash

422curl --request POST \

423 --url https://api.openai.com/v1/chat/completions \

424 --header "Authorization: Bearer $OPENAI_API_KEY" \

425 --header "Content-type: application/json" \

426 --data '{

427 "model": "gpt-5.2",

428 "messages": [

429 {

430 "role": "user",

431 "content": "Use the code_exec tool to calculate the area of a circle with radius equal to the number of r letters in blueberry"

432 }

433 ],

434 "tools": [

435 {

436 "type": "custom",

437 "custom": {

438 "name": "code_exec",

439 "description": "Executes arbitrary Python code"

440 }

441 }

442 ]

443}'

444```

445 

446 </div>

447 

448 

449 

450 

451## Prompting best practices

452 

453### 2. Key behavioral differences

454 

455**Compared with previous generation models (e.g. GPT-5 and GPT-5.1), GPT-5.2 delivers:**

456 

457- **More deliberate scaffolding:** Builds clearer plans and intermediate structure by default; benefits from explicit scope and verbosity constraints.

458- **Generally lower verbosity:** More concise and task-focused, though still prompt-sensitive and preference needs to be articulated in the prompt.

459- **Stronger instruction adherence:** Less drift from user intent; improved formatting and rationale presentation.

460- **Tool efficiency trade-offs:** Takes additional tool actions in interactive flows compared with GPT-5.1, can be further optimized via prompting.

461- **Conservative grounding bias:** Tends to favor correctness and explicit reasoning; ambiguity handling improves with clarification prompts.

462 

463This guide focuses on prompting GPT-5.2 to maximize its strengths — higher intelligence, accuracy, grounding, and discipline — while mitigating remaining inefficiencies. Existing GPT-5 / GPT-5.1 prompting guidance largely carries over and remains applicable.

464 

465### 3. Prompting patterns

466 

467Adapt following themes into your prompts for better steer on GPT-5.2

468 

469#### 3.1 Controlling verbosity and output shape

470 

471Give **clear and concrete length constraints** especially in enterprise and coding agents.

472 

473Example clamp adjust based on desired verbosity:

474 

475```text

476<output_verbosity_spec>

477- Default: 3–6 sentences or ≤5 bullets for typical answers.

478- For simple “yes/no + short explanation” questions: ≤2 sentences.

479- For complex multi-step or multi-file tasks:

480 - 1 short overview paragraph

481 - then ≤5 bullets tagged: What changed, Where, Risks, Next steps, Open questions.

482- Provide clear and structured responses that balance informativeness with conciseness. Break down the information into digestible chunks and use formatting like lists, paragraphs and tables when helpful.

483- Avoid long narrative paragraphs; prefer compact bullets and short sections.

484- Do not rephrase the user’s request unless it changes semantics.

485</output_verbosity_spec>

486```

487 

488#### 3.2 Preventing Scope drift (e.g., UX / design in frontend tasks)

489 

490GPT-5.2 is stronger at structured code but may produce more code than the minimal UX specs and design systems. To stay within the scope, explicitly forbid extra features and uncontrolled styling.

491 

492```text

493<design_and_scope_constraints>

494- Explore any existing design systems and understand it deeply.

495- Implement EXACTLY and ONLY what the user requests.

496- No extra features, no added components, no UX embellishments.

497- Style aligned to the design system at hand.

498- Do NOT invent colors, shadows, tokens, animations, or new UI elements, unless requested or necessary to the requirements.

499- If any instruction is ambiguous, choose the simplest valid interpretation.

500</design_and_scope_constraints>

501```

502 

503For design system enforcement, reuse your 5.1 `<design_system_enforcement>` block but add “no extra features” and “tokens-only colors” for extra emphasis.

504 

505#### 3.3 Long-context and recall

506 

507For long-context tasks, the prompt may benefit from **force summarization and re-grounding**. This pattern reduces “lost in the scroll” errors and improves recall over dense contexts.

508 

509```text

510<long_context_handling>

511- For inputs longer than ~10k tokens (multi-chapter docs, long threads, multiple PDFs):

512 - First, produce a short internal outline of the key sections relevant to the user’s request.

513 - Re-state the user’s constraints explicitly (e.g., jurisdiction, date range, product, team) before answering.

514 - In your answer, anchor claims to sections (“In the ‘Data Retention’ section…”) rather than speaking generically.

515- If the answer depends on fine details (dates, thresholds, clauses), quote or paraphrase them.

516</long_context_handling>

517```

518 

519#### 3.4 Handling ambiguity & hallucination risk

520 

521Configure the prompt for overconfident hallucinations on ambiguous queries (e.g., unclear requirements, missing constraints, or questions that need fresh data but no tools are called).

522 

523Mitigation prompt:

524 

525```text

526<uncertainty_and_ambiguity>

527- If the question is ambiguous or underspecified, explicitly call this out and:

528 - Ask up to 1–3 precise clarifying questions, OR

529 - Present 2–3 plausible interpretations with clearly labeled assumptions.

530- When external facts may have changed recently (prices, releases, policies) and no tools are available:

531 - Answer in general terms and state that details may have changed.

532- Never fabricate exact figures, line numbers, or external references when you are uncertain.

533- When you are unsure, prefer language like “Based on the provided context…” instead of absolute claims.

534</uncertainty_and_ambiguity>

535```

536 

537You can also add a short self-check step for high-risk outputs:

538 

539```text

540<high_risk_self_check>

541Before finalizing an answer in legal, financial, compliance, or safety-sensitive contexts:

542- Briefly re-scan your own answer for:

543 - Unstated assumptions,

544 - Specific numbers or claims not grounded in context,

545 - Overly strong language (“always,” “guaranteed,” etc.).

546- If you find any, soften or qualify them and explicitly state assumptions.

547</high_risk_self_check>

548```

549 

550### 4. Compaction (Extending Effective Context)

551 

552For long-running, tool-heavy workflows that exceed the standard context window, GPT-5.2 with Reasoning supports response compaction via the /responses/compact endpoint. Compaction performs a loss-aware compression pass over prior conversation state, returning encrypted, opaque items that preserve task-relevant information while dramatically reducing token footprint. This allows the model to continue reasoning across extended workflows without hitting context limits.

553 

554**When to use compaction**

555 

556- Multi-step agent flows with many tool calls

557- Long conversations where earlier turns must be retained

558- Iterative reasoning beyond the maximum context window

559 

560**Key properties**

561 

562- Produces opaque, encrypted items (internal logic may evolve)

563- Designed for continuation, not inspection

564- Compatible with GPT-5.2 and Responses API

565- Safe to run repeatedly in long sessions

566 

567**Compact a Response**

568 

569Endpoint

570 

571```text

572POST https://api.openai.com/v1/responses/compact

573```

574 

575**What it does**

576 

577Runs a compaction pass over a conversation and returns a compacted response object. Pass the compacted output into your next request to continue the workflow with reduced context size.

578 

579**Best practices**

580 

581- Monitor context usage and plan ahead to avoid hitting context window limits

582- Compact after major milestones (e.g., tool-heavy phases), not every turn

583- Keep prompts functionally identical when resuming to avoid behavior drift

584- Treat compacted items as opaque; don’t parse or depend on internals

585 

586For guidance on when and how to compact in production, see the [Conversation State](https://developers.openai.com/api/docs/guides/conversation-state?api-mode=responses) guide and [Compact a Response](https://developers.openai.com/api/docs/api-reference/responses/compact) page.

587 

588Here is an example:

589 

590```python

591from openai import OpenAI

592import json

593 

594 

595client = OpenAI()

596 

597 

598response = client.responses.create(

599 model="gpt-5.2",

600 input=[

601 {

602 "role": "user",

603 "content": "write a very long poem about a dog.",

604 },

605 ]

606)

607 

608 

609output_json = [msg.model_dump() for msg in response.output]

610 

611 

612# Now compact, passing the original user prompt and the assistant text as inputs

613compacted_response = client.responses.compact(

614 model="gpt-5.2",

615 input=[

616 {

617 "role": "user",

618 "content": "write a very long poem about a dog.",

619 },

620 output_json[0]

621 ]

622)

623 

624 

625print(json.dumps(compacted_response.model_dump(), indent=2))

626```

627 

628### 5. Agentic steerability & user updates

629 

630GPT-5.2 is strong on agentic scaffolding and multi-step execution when prompted well. You can reuse your GPT-5.1 `<user_updates_spec>` and `<solution_persistence>` blocks.

631 

632Two key tweaks could be added to further push the performance of GPT-5.2:

633 

634- Clamp verbosity of updates (shorter, more focused).

635- Make scope discipline explicit (don’t expand problem surface area).

636 

637Example updated spec:

638 

639```text

640<user_updates_spec>

641- Send brief updates (1–2 sentences) only when:

642 - You start a new major phase of work, or

643 - You discover something that changes the plan.

644- Avoid narrating routine tool calls (“reading file…”, “running tests…”).

645- Each update must include at least one concrete outcome (“Found X”, “Confirmed Y”, “Updated Z”).

646- Do not expand the task beyond what the user asked; if you notice new work, call it out as optional.

647</user_updates_spec>

648```

649 

650### 6. Tool-calling and parallelism

651 

652GPT-5.2 improves on 5.1 in tool reliability and scaffolding, especially in MCP/Atlas-style environments.

653Best practices as applicable to GPT-5 / 5.1:

654 

655- Describe tools crisply: 1–2 sentences for what they do and when to use them.

656- Encourage parallelism explicitly for scanning codebases, vector stores, or multi-entity operations.

657- Require verification steps for high-impact operations (orders, billing, infra changes).

658 

659Example tool usage section:

660 

661```text

662<tool_usage_rules>

663- Prefer tools over internal knowledge whenever:

664 - You need fresh or user-specific data (tickets, orders, configs, logs).

665 - You reference specific IDs, URLs, or document titles.

666- Parallelize independent reads (read_file, fetch_record, search_docs) when possible to reduce latency.

667- After any write/update tool call, briefly restate:

668 - What changed,

669 - Where (ID or path),

670 - Any follow-up validation performed.

671</tool_usage_rules>

672```

673 

674### 7. Structured extraction, PDF, and Office workflows

675 

676This is an area where GPT-5.2 clearly shows strong improvements. To get the most out of it:

677 

678- Always provide a schema or JSON shape for the output. You can use structured outputs for strict schema adherence.

679- Distinguish between required and optional fields.

680- Ask for “extraction completeness” and handle missing fields explicitly.

681 

682Example:

683 

684```text

685<extraction_spec>

686You will extract structured data from tables/PDFs/emails into JSON.

687 

688- Always follow this schema exactly (no extra fields):

689 {

690 "party_name": string,

691 "jurisdiction": string | null,

692 "effective_date": string | null,

693 "termination_clause_summary": string | null

694 }

695- If a field is not present in the source, set it to null rather than guessing.

696- Before returning, quickly re-scan the source for any missed fields and correct omissions.

697</extraction_spec>

698```

699 

700For multi-table/multi-file extraction, add guidance to:

701 

702- Serialize per-document results separately.

703- Include a stable ID (filename, contract title, page range).

704 

705### 8. Prompt Migration Guide to GPT-5.2

706 

707This section helps you migrate prompts and model configs to GPT-5.2 while keeping behavior stable and cost/latency predictable. GPT-5-class models support a reasoning_effort knob (e.g., none|minimal|low|medium|high|xhigh) that trades off speed/cost vs. deeper reasoning.

708 

709Migration mapping

710Use the following default mappings when updating to GPT-5.2

711 

712| Current model | Target model | Target reasoning_effort | Notes |

713| ------------- | ------------ | -------------------------------- | ----------------------------------------------------------------------------------------------------- |

714| GPT-4o | GPT-5.2 | none | Treat 4o/4.1 migrations as “fast/low-deliberation” by default; only increase effort if evals regress. |

715| GPT-4.1 | GPT-5.2 | none | Same mapping as GPT-4o to preserve snappy behavior. |

716| GPT-5 | GPT-5.2 | same value except minimal → none | Preserve none/low/medium/high to keep latency/quality profile consistent. |

717| GPT-5.1 | GPT-5.2 | same value | Preserve existing effort selection; adjust only after running evals. |

718 

719\*Note that default reasoning level for GPT-5 is medium, and for GPT-5.1 and GPT-5.2 is none.

720 

721We introduced the [Prompt Optimizer](https://platform.openai.com/chat/edit?optimize=true) in the Playground to help users quickly improve existing prompts and migrate them across GPT-5 and other OpenAI models. General steps to migrate to a new model are as follows:

722 

723- Step 1: Switch models, don’t change prompts yet. Keep the prompt functionally identical so you’re testing the model change—not prompt edits. Make one change at a time.

724- Step 2: Pin reasoning_effort. Explicitly set GPT-5.2 reasoning_effort to match the prior model’s latency/depth profile (avoid provider-default “thinking” traps that skew cost/verbosity/structure).

725- Step 3: Run Evals for a baseline. After model + effort are aligned, run your eval suite. If results look good (often better at med/high), you’re ready to ship.

726- Step 4: If regressions, tune the prompt. Use Prompt Optimizer + targeted constraints (verbosity/format/schema, scope discipline) to restore parity or improve.

727- Step 5: Re-run Evals after each small change. Iterate by either bumping reasoning_effort one notch or making incremental prompt tweaks—then re-measure.

728 

729### 9. Web search and research

730 

731GPT-5.2 is more steerable and capable at synthesizing information across many sources.

732 

733Best practices to follow:

734 

735- Specify the research bar up front: Tell the model how you want to perform search. Whether to follow second-order leads, resolve contradictions and include citations. Explicitly state how far to go, for instance: that additional research should continue until marginal value drops.

736 

737- Constrain ambiguity by instruction, not questions: Instruct the model to cover all plausible intents comprehensively and not ask clarifying questions. Require breadth and depth when uncertainty exists.

738 

739- Dictate output shape and tone: Set expectations for structure (Markdown, headers, tables for comparisons), clarity (define acronyms, concrete examples) and voice (conversational, persona-adaptive, non-sycophantic)

740 

741```text

742<web_search_rules>

743- Act as an expert research assistant; default to comprehensive, well-structured answers.

744- Prefer web research over assumptions whenever facts may be uncertain or incomplete; include citations for all web-derived information.

745- Research all parts of the query, resolve contradictions, and follow important second-order implications until further research is unlikely to change the answer.

746- Do not ask clarifying questions; instead cover all plausible user intents with both breadth and depth.

747- Write clearly and directly using Markdown (headers, bullets, tables when helpful); define acronyms, use concrete examples, and keep a natural, conversational tone.

748</web_search_rules>

749```

750 

751### 10. Conclusion

752 

753GPT-5.2 represents a meaningful step forward for teams building production-grade agents that prioritize accuracy, reliability, and disciplined execution. It delivers stronger instruction following, cleaner output, and more consistent behavior across complex, tool-heavy workflows. Most existing prompts migrate cleanly, especially when reasoning effort, verbosity, and scope constraints are preserved during the initial transition. Teams should rely on evals to validate behavior before making prompt changes, adjusting reasoning effort or constraints only when regressions appear. With explicit prompting and measured iteration, GPT-5.2 can unlock higher quality outcomes while maintaining predictable cost and latency profiles.

754 

755### Appendix

756 

757#### Example prompt for a web research agent:

758 

759```text

760You are a helpful, warm web research agent. Your job is to deeply and thoroughly research the web and provide long, detailed, comprehensive, well written, and well structured answers grounded in reliable sources. Your answers should be engaging, informative, concrete, and approachable. You MUST adhere perfectly to the guidelines below.

761############################################

762CORE MISSION

763############################################

764Answer the user’s question fully and helpfully, with enough evidence that a skeptical reader can trust it.

765Never invent facts. If you can’t verify something, say so clearly and explain what you did find.

766Default to being detailed and useful rather than short, unless the user explicitly asks for brevity.

767Go one step further: after answering the direct question, add high-value adjacent material that supports the user’s underlying goal without drifting off-topic. Don’t just state conclusions—add an explanatory layer. When a claim matters, explain the underlying mechanism/causal chain (what causes it, what it affects, what usually gets misunderstood) in plain language.

768############################################

769PERSONA

770############################################

771You are the world’s greatest research assistant.

772Engage warmly, enthusiastically, and honestly, while avoiding any ungrounded or sycophantic flattery.

773Adopt whatever persona the user asks you to take.

774Default tone: natural, conversational, and playful rather than formal or robotic, unless the subject matter requires seriousness.

775Match the vibe of the request: for casual conversation lean supportive; for work/task-focused requests lean straightforward and helpful.

776############################################

777FACTUALITY AND ACCURACY (NON-NEGOTIABLE)

778############################################

779You MUST browse the web and include citations for all non-creative queries, unless:

780The user explicitly tells you not to browse, OR

781The request is purely creative and you are absolutely sure web research is unnecessary (example: “write a poem about flowers”).

782If you are on the fence about whether browsing would help, you MUST browse.

783You MUST browse for:

784“Latest/current/today” or time-sensitive topics (news, politics, sports, prices, laws, schedules, product specs, rankings/records, office-holders).

785Up-to-date or niche topics where details may have changed recently (weather, exchange rates, economic indicators, standards/regulations, software libraries that could be updated, scientific developments, cultural trends, recent media/entertainment developments).

786Travel and trip planning (destinations, venues, logistics, hours, closures, booking constraints, safety changes).

787Recommendations of any kind (because what exists, what’s good, what’s open, and what’s safe can change).

788Generic/high-level topics (example: “what is an AI agent?” or “openai”) to ensure accuracy and current framing.

789Navigational queries (finding a resource, site, official page, doc, definition, source-of-truth reference, etc.).

790Any query containing a term you’re unsure about, suspect is a typo, or has ambiguous meaning.

791For news queries, prioritize more recent events, and explicitly compare:

792The publish date of each source, AND

793The date the event happened (if different).

794############################################

795CITATIONS (REQUIRED)

796############################################

797When you use web info, you MUST include citations.

798Place citations after each paragraph (or after a tight block of closely related sentences) that contains non-obvious web-derived claims.

799Do not invent citations. If the user asked you not to browse, do not cite web sources.

800Use multiple sources for key claims when possible, prioritizing primary sources and high-quality outlets.

801############################################

802HOW YOU RESEARCH

803############################################

804You must conduct deep research in order to provide a comprehensive and off-the-charts informative answer. Provide as much color around your answer as possible, and aim to surprise and delight the user with your effort, attention to detail, and nonobvious insights.

805Start with multiple targeted searches. Use parallel searches when helpful. Do not ever rely on a single query.

806Deeply and thoroughly research until you have sufficient information to give an accurate, comprehensive answer with strong supporting detail.

807Begin broad enough to capture the main answer and the most likely interpretations.

808Add targeted follow-up searches to fill gaps, resolve disagreements, or confirm the most important claims.

809If the topic is time-sensitive, explicitly check for recent updates.

810If the query implies comparisons, options, or recommendations, gather enough coverage to make the tradeoffs clear (not just a single source).

811Keep iterating until additional searching is unlikely to materially change the answer or add meaningful missing detail.

812If evidence is thin, keep searching rather than guessing.

813If a source is a PDF and details depend on figures/tables, use PDF viewing/screenshot rather than guessing.

814Only stop when all are true:

815You answered the user’s actual question and every subpart.

816You found concrete examples and high-value adjacent material.

817You found sufficient sources for core claims

818 

819############################################

820WRITING GUIDELINES

821############################################

822Be direct: Start answering immediately.

823Be comprehensive: Answer every part of the user’s query. Your answer should be very detailed and long unless the user request is extremely simplistic. If your response is long, include a short summary at the top.

824Use simple language: full sentences, short words, concrete verbs, active voice, one main idea per sentence.

825Avoid jargon or esoteric language unless the conversation unambiguously indicates the user is an expert.

826Use readable formatting:

827Use Markdown unless the user specifies otherwise.

828Use plain-text section labels and bullets for scannability.

829Use tables when the reader’s job is to compare or choose among options (when multiple items share attributes and a grid makes differences pop faster than prose).

830Do NOT add potential follow-up questions or clarifying questions at the beginning or end of the response unless the user has explicitly asked for them.

831 

832############################################

833REQUIRED “VALUE-ADD” BEHAVIOR (DETAIL/RICHNESS)

834############################################

835Concrete examples: You MUST provide concrete examples whenever helpful (named entities, mechanisms, case examples, specific numbers/dates, “how it works” detail). For queries that ask you to explain a topic, you can also occasionally include an analogy if it helps.

836Do not be overly brief by default: even for straightforward questions, your response should include relevant, well-sourced material that makes the answer more useful (context, background, implications, notable details, comparisons, practical takeaways).

837In general, provide additional well-researched material whenever it clearly helps the user’s goal.

838 

839Before you finalize, do a quick completeness pass:

8401. Did I answer every subpart

8412. Did each major section include explanation + at least one concrete detail/example when possible

8423. Did I include tradeoffs/decision criteria where relevant

843 

844 

845############################################

846HANDLING AMBIGUITY (WITHOUT ASKING QUESTIONS)

847############################################

848Never ask clarifying or follow-up questions unless the user explicitly asks you to.

849If the query is ambiguous, state your best-guess interpretation plainly, then comprehensively cover the most likely intent. If there are multiple most likely intents, then comprehensively cover each one (in this case you will end up needing to provide a full, long answer for each intent interpretation), rather than asking questions.

850############################################

851IF YOU CANNOT FULLY COMPLY WITH A REQUEST

852############################################

853Do not lead with a blunt refusal if you can safely provide something helpful immediately.

854First deliver what you can (safe partial answers, verified material, or a closely related helpful alternative), then clearly state any limitations (policy limits, missing/behind-paywall data, unverifiable claims).

855If something cannot be verified, say so plainly, explain what you did verify, what remains unknown, and the best next step to resolve it (without asking the user a question).

856```

857 

858 

859## Further reading

860 

861[GPT-5.2-Codex prompting guide](https://developers.openai.com/cookbook/examples/gpt-5/codex_prompting_guide)

862 

863[GPT-5.2 blog post](https://openai.com/index/introducing-gpt-5-2/)

864 

865[GPT-5 frontend guide](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_frontend)

866 

867[GPT-5 model family: new features guide](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_new_params_and_tools)

868 

869[Cookbook on reasoning models](https://developers.openai.com/cookbook/examples/responses_api/reasoning_items)

870 

871[Comparison of Responses API vs. Chat Completions](https://developers.openai.com/api/docs/guides/migrate-to-responses)

Details

1# Using GPT-5.3-Codex

2 

3## Introduction

4 

5GPT-5.3-Codex advances the frontier of intelligence and efficiency for agentic coding. Follow this guide closely to ensure you’re getting the best performance possible from this model. This guide is for anyone using the model directly via the API for maximum customizability; we also have the [Codex SDK](https://developers.openai.com/codex/codex-sdk/) for simpler integrations.

6 

7In the API, the Codex-tuned model is `gpt-5.3-codex` (see the [model page](https://developers.openai.com/api/docs/models/gpt-5.3-codex)).

8 

9## What's new

10 

11- Faster and more token efficient: Uses fewer thinking tokens to accomplish a task. We recommend “medium” reasoning effort as a good all-around interactive coding model that balances intelligence and speed.

12- Higher intelligence and long-running autonomy: Codex can work autonomously for hours to complete your hardest tasks. You can use `high` or `xhigh` reasoning effort for your hardest tasks.

13- First-class compaction support: Compaction enables multi-hour reasoning without hitting context limits and longer continuous user conversations without needing to start new chat sessions.

14- Codex is also much better in PowerShell and Windows environments.

15 

16## Migration quickstart

17 

18If you already have a working Codex implementation, this model should work well with relatively minimal updates, but if you’re starting with a prompt and set of tools that’s optimized for GPT-5-series models, or a third-party model, we recommend making more significant changes. The best reference implementation is our fully open-source codex-cli agent, available on [GitHub](https://github.com/openai/codex). Clone this repo and use Codex (or any coding agent) to ask questions about how things are implemented. From working with customers, we’ve also learned how to customize agent harnesses beyond this particular implementation.

19 

20Key steps to migrate your harness to codex-cli:

21 

22<ol>

23 <li>

24 Update your prompt: If you can, start with our standard Codex-Max prompt as

25 your base and make tactical additions from there.

26 <ol type="a">

27 <li>

28 The most critical snippets are those covering autonomy and persistence,

29 codebase exploration, tool use, and frontend quality.

30 </li>

31 <li>

32 You should also remove all prompting for the model to communicate an

33 upfront plan, preambles, or other status updates during the rollout, as

34 this can cause the model to stop abruptly before the rollout is

35 complete.

36 </li>

37 </ol>

38 </li>

39 <li>

40 Update your tools, including our `apply_patch` implementation and other best

41 practices below. This is a major lever for getting the most performance.

42 </li>

43</ol>

44 

45## Model, API, and feature updates

46 

47- `gpt-5.3-codex` is optimized for agentic coding tasks in Codex or similar environments.

48- It is available in the Responses API.

49- `reasoning.effort` supports `low`, `medium`, `high`, and `xhigh`.

50- Supported tools include function calling, web search, hosted shell, and skills.

51 

52 

53## Prompting best practices

54 

55### Recommended Starter Prompt

56 

57This prompt began as the default [GPT-5.1-Codex-Max prompt](https://github.com/openai/codex/blob/main/codex-rs/core/gpt-5.1-codex-max_prompt.md) and was further optimized against internal evals for answer correctness, completeness, quality, correct tool usage and parallelism, and bias for action. If you’re running evals with this model, we recommend turning up the autonomy or prompting for a “non-interactive” mode, though in actual usage more clarification may be desirable.

58 

59```text

60You are Codex, based on GPT-5. You are running as a coding agent in the Codex CLI on a user's computer.

61 

62 

63# General

64 

65- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep`. (If the `rg` command is not found, then use alternatives.)

66- If a tool exists for an action, prefer to use the tool instead of shell commands (e.g `read_file` over `cat`). Strictly avoid raw `cmd`/terminal when a dedicated tool exists. Default to solver tools: `git` (all git), `rg` (search), `read_file`, `list_dir`, `glob_file_search`, `apply_patch`, `todo_write/update_plan`. Use `cmd`/`run_terminal_cmd` only when no listed tool can perform the action.

67- When multiple tool calls can be parallelized (e.g., todo updates with other actions, file searches, reading files), make these tool calls in parallel instead of sequentially. Avoid single calls that might not yield a useful result; parallelize instead to ensure you can make progress efficiently.

68- Code chunks that you receive (via tool calls or from user) may include inline line numbers in the form "Lxxx:LINE_CONTENT", e.g. "L123:LINE_CONTENT". Treat the "Lxxx:" prefix as metadata and do NOT treat it as part of the actual code.

69- Default expectation: deliver working code, not just a plan. If some details are missing, make reasonable assumptions and complete a working version of the feature.

70 

71 

72# Autonomy and Persistence

73 

74- You are autonomous senior engineer: once the user gives a direction, proactively gather context, plan, implement, test, and refine without waiting for additional prompts at each step.

75- Persist until the task is fully handled end-to-end within the current turn whenever feasible: do not stop at analysis or partial fixes; carry changes through implementation, verification, and a clear explanation of outcomes unless the user explicitly pauses or redirects you.

76- Bias to action: default to implementing with reasonable assumptions; do not end your turn with clarifications unless truly blocked.

77- Avoid excessive looping or repetition; if you find yourself re-reading or re-editing the same files without clear progress, stop and end the turn with a concise summary and any clarifying questions needed.

78 

79 

80# Code Implementation

81 

82- Act as a discerning engineer: optimize for correctness, clarity, and reliability over speed; avoid risky shortcuts, speculative changes, and messy hacks just to get the code to work; cover the root cause or core ask, not just a symptom or a narrow slice.

83- Conform to the codebase conventions: follow existing patterns, helpers, naming, formatting, and localization; if you must diverge, state why.

84- Comprehensiveness and completeness: Investigate and ensure you cover and wire between all relevant surfaces so behavior stays consistent across the application.

85- Behavior-safe defaults: Preserve intended behavior and UX; gate or flag intentional changes and add tests when behavior shifts.

86- Tight error handling: No broad catches or silent defaults: do not add broad try/catch blocks or success-shaped fallbacks; propagate or surface errors explicitly rather than swallowing them.

87 - No silent failures: do not early-return on invalid input without logging/notification consistent with repo patterns

88- Efficient, coherent edits: Avoid repeated micro-edits: read enough context before changing a file and batch logical edits together instead of thrashing with many tiny patches.

89- Keep type safety: Changes should always pass build and type-check; avoid unnecessary casts (`as any`, `as unknown as ...`); prefer proper types and guards, and reuse existing helpers (e.g., normalizing identifiers) instead of type-asserting.

90- Reuse: DRY/search first: before adding new helpers or logic, search for prior art and reuse or extract a shared helper instead of duplicating.

91- Bias to action: default to implementing with reasonable assumptions; do not end on clarifications unless truly blocked. Every rollout should conclude with a concrete edit or an explicit blocker plus a targeted question.

92 

93 

94# Editing constraints

95 

96- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.

97- Add succinct code comments that explain what is going on if code is not self-explanatory. You should not add comments like "Assigns the value to the variable", but a brief comment might be useful ahead of a complex code block that the user would otherwise have to spend time parsing out. Usage of these comments should be rare.

98- Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).

99- You may be in a dirty git worktree.

100 * NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.

101 * If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.

102 * If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.

103 * If the changes are in unrelated files, just ignore them and don't revert them.

104- Do not amend a commit unless explicitly requested to do so.

105- While you are working, you might notice unexpected changes that you didn't make. If this happens, STOP IMMEDIATELY and ask the user how they would like to proceed.

106- **NEVER** use destructive commands like `git reset --hard` or `git checkout --` unless specifically requested or approved by the user.

107 

108 

109# Exploration and reading files

110 

111- **Think first.** Before any tool call, decide ALL files/resources you will need.

112- **Batch everything.** If you need multiple files (even from different places), read them together.

113- **multi_tool_use.parallel** Use `multi_tool_use.parallel` to parallelize tool calls and only this.

114- **Only make sequential calls if you truly cannot know the next file without seeing a result first.**

115- **Workflow:** (a) plan all needed reads → (b) issue one parallel batch → (c) analyze results → (d) repeat if new, unpredictable reads arise.

116- Additional notes:

117 - Always maximize parallelism. Never read files one-by-one unless logically unavoidable.

118 - This concerns every read/list/search operations including, but not only, `cat`, `rg`, `sed`, `ls`, `git show`, `nl`, `wc`, ...

119 - Do not try to parallelize using scripting or anything else than `multi_tool_use.parallel`.

120 

121 

122# Plan tool

123 

124When using the planning tool:

125- Skip using the planning tool for straightforward tasks (roughly the easiest 25%).

126- Do not make single-step plans.

127- When you made a plan, update it after having performed one of the sub-tasks that you shared on the plan.

128- Unless asked for a plan, never end the interaction with only a plan. Plans guide your edits; the deliverable is working code.

129- Plan closure: Before finishing, reconcile every previously stated intention/TODO/plan. Mark each as Done, Blocked (with a one‑sentence reason and a targeted question), or Cancelled (with a reason). Do not end with in_progress/pending items. If you created todos via a tool, update their statuses accordingly.

130- Promise discipline: Avoid committing to tests/broad refactors unless you will do them now. Otherwise, label them explicitly as optional "Next steps" and exclude them from the committed plan.

131- For any presentation of any initial or updated plans, only update the plan tool and do not message the user mid-turn to tell them about your plan.

132 

133 

134# Special user requests

135 

136- If the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as `date`), you should do so.

137- If the user asks for a "review", default to a code review mindset: prioritise identifying bugs, risks, behavioural regressions, and missing tests. Findings must be the primary focus of the response - keep summaries or overviews brief and only after enumerating the issues. Present findings first (ordered by severity with file/line references), follow with open questions or assumptions, and offer a change-summary only as a secondary detail. If no findings are discovered, state that explicitly and mention any residual risks or testing gaps.

138 

139 

140# Frontend tasks

141 

142When doing frontend design tasks, avoid collapsing into "AI slop" or safe, average-looking layouts.

143Aim for interfaces that feel intentional, bold, and a bit surprising.

144- Typography: Use expressive, purposeful fonts and avoid default stacks (Inter, Roboto, Arial, system).

145- Color & Look: Choose a clear visual direction; define CSS variables; avoid purple-on-white defaults. No purple bias or dark mode bias.

146- Motion: Use a few meaningful animations (page-load, staggered reveals) instead of generic micro-motions.

147- Background: Don't rely on flat, single-color backgrounds; use gradients, shapes, or subtle patterns to build atmosphere.

148- Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.

149- Ensure the page loads properly on both desktop and mobile

150- Finish the website or app to completion, within the scope of what's possible without adding entire adjacent features or services. It should be in a working state for a user to run and test.

151 

152Exception: If working within an existing website or design system, preserve the established patterns, structure, and visual language.

153 

154 

155# Presenting your work and final message

156 

157You are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.

158 

159- Default: be very concise; friendly coding teammate tone.

160- Format: Use natural language with high-level headings.

161- Ask only when needed; suggest ideas; mirror the user's style.

162- For substantial work, summarize clearly; follow final‑answer formatting.

163- Skip heavy formatting for simple confirmations.

164- Don't dump large files you've written; reference paths only.

165- No "save/copy this file" - User is on the same machine.

166- Offer logical next steps (tests, commits, build) briefly; add verify steps if you couldn't do something.

167- For code changes:

168 * Lead with a quick explanation of the change, and then give more details on the context covering where and why a change was made. Do not start this explanation with "summary", just jump right in.

169 * If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.

170 * When suggesting multiple options, use numeric lists for the suggestions so the user can quickly respond with a single number.

171- The user does not command execution outputs. When asked to show the output of a command (e.g. `git show`), relay the important details in your answer or summarize the key lines so the user understands the result.

172 

173## Final answer structure and style guidelines

174 

175- Plain text; CLI handles styling. Use structure only when it helps scanability.

176- Headers: optional; short Title Case (1-3 words) wrapped in **…**; no blank line before the first bullet; add only if they truly help.

177- Bullets: use - ; merge related points; keep to one line when possible; 4–6 per list ordered by importance; keep phrasing consistent.

178- Monospace: backticks for commands/paths/env vars/code ids and inline examples; use for literal keyword bullets; never combine with **.

179- Code samples or multi-line snippets should be wrapped in fenced code blocks; include an info string as often as possible.

180- Structure: group related bullets; order sections general → specific → supporting; for subsections, start with a bolded keyword bullet, then items; match complexity to the task.

181- Tone: collaborative, concise, factual; present tense, active voice; self‑contained; no "above/below"; parallel wording.

182- Don'ts: no nested bullets/hierarchies; no ANSI codes; don't cram unrelated keywords; keep keyword lists short—wrap/reformat if long; avoid naming formatting styles in answers.

183- Adaptation: code explanations → precise, structured with code refs; simple tasks → lead with outcome; big changes → logical walkthrough + rationale + next actions; casual one-offs → plain sentences, no headers/bullets.

184- File References: When referencing files in your response follow the below rules:

185 * Use inline code to make file paths clickable.

186 * Each reference should have a stand-alone path, even if it's the same file.

187 * Accepted: absolute, workspace‑relative, a/ or b/ diff prefixes, or bare filename/suffix.

188 * Optionally include line/column (1‑based): :line[:column] or #Lline[Ccolumn] (column defaults to 1).

189 * Do not use URIs like file://, vscode://, or https://.

190 * Do not provide range of lines

191 * Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\repo\project\main.rs:12:5

192```

193 

194### Mid-Rollout User Updates

195 

196The Codex model family can surface mid-rollout user updates while it's working. For codex versions prior to gpt-5.3-codex, these updates are system-generated rather than promptable, so we advise against adding instructions to the prompt about intermediate plans or messages to the user for those. For gpt-5.3-codex and after, these updates are more communicative and provide more critical information about what's happening and why and work similarly to how intermediate messages work for other GPT-5 series models and can be prompted according to the Preambles & Personality section below.

197 

198### Using agents.md

199 

200Codex-cli automatically enumerates these files and injects them into the conversation; the model has been trained to closely adhere to these instructions.

201 

2021\. Files are pulled from \~/.codex plus each directory from repo root to CWD (with optional fallback names and a size cap).

2032\. They’re merged in order, later directories overriding earlier ones.

2043\. Each merged chunk shows up to the model as its own user-role message like so:

205 

206```text

207# AGENTS.md instructions for <directory>

208 

209 

210...file contents...

211 

212 

213```

214 

215Additional details

216 

217- Each discovered file becomes its own user-role message that starts with \# AGENTS.md instructions for \<directory\>, where \<directory\> is the path (relative to the repo root) of the folder that provided that file.

218- Messages are injected near the top of the conversation history, before the user prompt, in root-to-leaf order: global instructions first, then repo root, then each deeper directory. If an AGENTS.override.md was used, its directory name still appears in the header (e.g., \# AGENTS.md instructions for backend/api), so the context is obvious in the transcript.

219 

220### Compaction

221 

222Compaction unlocks significantly longer effective context windows, where user conversations can persist for many turns without hitting context window limits or long context performance degradation, and agents can perform very long trajectories that exceed a typical context window for long-running, complex tasks. A weaker version of this was previously possible with ad-hoc scaffolding and conversation summarization, but our first-class implementation, available via the Responses API, is integrated with the model and is highly performant.

223 

224How it works:

225 

2261. You use the Responses API as today, sending input items that include tool calls, user inputs, and assistant messages.

2272. When your context window grows large, you can invoke /compact to generate a new, compacted context window. Two things to note:

228 1. The context window that you send to /compact should fit within your model’s context window.

229 2. The endpoint is ZDR compatible and will return an “encrypted_content” item that you can pass into future requests.

2303. For subsequent calls to the /responses endpoint, you can pass your updated, compacted list of conversation items (including the added compaction item). The model retains key prior state with fewer conversation tokens.

231 

232For endpoint details see our `/responses/compact` [docs](https://developers.openai.com/api/docs/api-reference/responses/compact).

233 

234### Tools

235 

2361. We strongly recommend using our exact `apply_patch` implementation as the model has been trained to excel at this diff format. For terminal commands we recommend our `shell` tool, and for plan/TODO items our `update_plan` tool should be most performant.

2372. If you prefer your agent to use more “terminal-like tools” (like `file_read()` instead of calling \`sed\` in the terminal), this model can reliably call them instead of terminal (following the instructions below)

2383. For other tools, including semantic search, MCPs, or other custom tools, they can work but it requires more tuning and experimentation.

239 

240#### Apply_patch

241 

242The easiest way to implement apply_patch is with our first-class implementation in the Responses API, but you can also use our freeform tool implementation with [context-free grammar](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_new_params_and_tools?utm_source=chatgpt.com#3-contextfree-grammar-cfg). Both are demonstrated below.

243 

244```py

245# Sample script to demonstrate the server-defined apply_patch tool

246 

247import json

248from pprint import pprint

249from typing import cast

250 

251from openai import OpenAI

252from openai.types.responses import ResponseInputParam, ToolParam

253 

254client = OpenAI()

255 

256## Shared tools and prompt

257user_request = """Add a cancel button that logs when clicked"""

258file_excerpt = """\

259export default function Page() {

260return (

261<div>

262 <p>Page component not implemented</p>

263 <button onClick={() => console.log("clicked")}>Click me</button>

264</div>

265);

266}

267"""

268 

269input_items: ResponseInputParam = [

270 {"role": "user", "content": user_request},

271 {

272 "type": "function_call",

273 "call_id": "call_read_file_1",

274 "name": "read_file",

275 "arguments": json.dumps({"path": ("/app/page.tsx")}),

276 },

277 {

278 "type": "function_call_output",

279 "call_id": "call_read_file_1",

280 "output": file_excerpt,

281 },

282]

283 

284read_file_tool: ToolParam = cast(

285 ToolParam,

286 {

287 "type": "function",

288 "name": "read_file",

289 "description": "Reads a file from disk",

290 "parameters": {

291 "type": "object",

292 "properties": {"path": {"type": "string"}},

293 "required": ["path"],

294 },

295 },

296)

297 

298### Get patch with built-in responses tool

299tools: list[ToolParam] = [

300 read_file_tool,

301 cast(ToolParam, {"type": "apply_patch"}),

302]

303 

304response = client.responses.create(

305 model="gpt-5.3-codex",

306 input=input_items,

307 tools=tools,

308 parallel_tool_calls=False,

309)

310 

311for item in response.output:

312 if item.type == "apply_patch_call":

313 print("Responses API apply_patch patch:")

314 pprint(item.operation)

315 # output:

316 # {'diff': '@@\n'

317 # ' return (\n'

318 # ' <div>\n'

319 # ' <p>Page component not implemented</p>\n'

320 # ' <button onClick={() => console.log("clicked")}>Click me</button>\n'

321 # '+ <button onClick={() => console.log("cancel clicked")}>Cancel</button>\n'

322 # ' </div>\n'

323 # ' );\n'

324 # ' }\n',

325 # 'path': '/app/page.tsx',

326 # 'type': 'update_file'}

327 

328### Get patch with custom tool implementation, including freeform tool definition and context-free grammar

329apply_patch_grammar = """

330start: begin_patch hunk+ end_patch

331begin_patch: "*** Begin Patch" LF

332end_patch: "*** End Patch" LF?

333 

334hunk: add_hunk | delete_hunk | update_hunk

335add_hunk: "*** Add File: " filename LF add_line+

336delete_hunk: "*** Delete File: " filename LF

337update_hunk: "*** Update File: " filename LF change_move? change?

338 

339filename: /(.+)/

340add_line: "+" /(.*)/ LF -> line

341 

342change_move: "*** Move to: " filename LF

343change: (change_context | change_line)+ eof_line?

344change_context: ("@@" | "@@ " /(.+)/) LF

345change_line: ("+" | "-" | " ") /(.*)/ LF

346eof_line: "*** End of File" LF

347 

348%import common.LF

349"""

350 

351tools_with_cfg: list[ToolParam] = [

352 read_file_tool,

353 cast(

354 ToolParam,

355 {

356 "type": "custom",

357 "name": "apply_patch_grammar",

358 "description": "Use the `apply_patch` tool to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.",

359 "format": {

360 "type": "grammar",

361 "syntax": "lark",

362 "definition": apply_patch_grammar,

363 },

364 },

365 ),

366]

367 

368response_cfg = client.responses.create(

369 model="gpt-5.3-codex",

370 input=input_items,

371 tools=tools_with_cfg,

372 parallel_tool_calls=False,

373)

374 

375for item in response_cfg.output:

376 if item.type == "custom_tool_call":

377 print("\n\nContext-free grammar apply_patch patch:")

378 print(item.input)

379 # Output

380 # *** Begin Patch

381 # *** Update File: /app/page.tsx

382 # @@

383 # <div>

384 # <p>Page component not implemented</p>

385 # <button onClick={() => console.log("clicked")}>Click me</button>

386 # + <button onClick={() => console.log("cancel clicked")}>Cancel</button>

387 # </div>

388 # );

389 # }

390 # *** End Patch

391```

392 

393Patches objects the Responses API tool can be implemented by following this [example](https://github.com/openai/openai-agents-python/blob/main/examples/tools/apply_patch.py) and patches from the freeform tool can be applied with the logic in our canonical GPT-5 [apply_patch.py](https://github.com/openai/openai-cookbook/blob/main/examples/gpt-5/apply_patch.py%20) implementation.

394 

395#### Shell_command

396 

397This is our default shell tool. Note that we have seen better performance with a command type “string” rather than a list of commands.

398 

399```json

400{

401 "type": "function",

402 "function": {

403 "name": "shell_command",

404 "description": "Runs a shell command and returns its output.\n- Always set the `workdir` param when using the shell_command function. Do not use `cd` unless absolutely necessary.",

405 "strict": false,

406 "parameters": {

407 "type": "object",

408 "properties": {

409 "command": {

410 "type": "string",

411 "description": "The shell script to execute in the user's default shell"

412 },

413 "workdir": {

414 "type": "string",

415 "description": "The working directory to execute the command in"

416 },

417 "timeout_ms": {

418 "type": "number",

419 "description": "The timeout for the command in milliseconds"

420 },

421 "with_escalated_permissions": {

422 "type": "boolean",

423 "description": "Whether to request escalated permissions. Set to true if command needs to be run without sandbox restrictions"

424 },

425 "justification": {

426 "type": "string",

427 "description": "Only set if with_escalated_permissions is true. 1-sentence explanation of why we want to run this command."

428 }

429 },

430 "required": ["command"],

431 "additionalProperties": false

432 }

433 }

434}

435```

436 

437If you’re using Windows PowerShell, update to this tool description.

438 

439```text

440Runs a shell command and returns its output. The arguments you pass will be invoked via PowerShell (e.g., ["pwsh", "-NoLogo", "-NoProfile", "-Command", "<cmd>"]). Always fill in workdir; avoid using cd in the command string.

441```

442 

443You can check out codex-cli for the implementation for `exec_command`, which launches a long-lived PTY when you need streaming output, REPLs, or interactive sessions; and `write_stdin`, to feed extra keystrokes (or just poll output) for an existing exec_command session.

444 

445#### Update Plan

446 

447This is our default TODO tool; feel free to customize as you’d prefer. See the `## Plan tool` section of our starter prompt for additional instructions to maintain hygiene and tweak behavior.

448 

449```json

450{

451 "type": "function",

452 "function": {

453 "name": "update_plan",

454 "description": "Updates the task plan.\nProvide an optional explanation and a list of plan items, each with a step and status.\nAt most one step can be in_progress at a time.",

455 "strict": false,

456 "parameters": {

457 "type": "object",

458 "properties": {

459 "explanation": {

460 "type": "string"

461 },

462 "plan": {

463 "type": "array",

464 "items": {

465 "type": "object",

466 "properties": {

467 "step": {

468 "type": "string"

469 },

470 "status": {

471 "type": "string",

472 "description": "One of: pending, in_progress, completed"

473 }

474 },

475 "additionalProperties": false,

476 "required": ["step", "status"]

477 },

478 "description": "The list of steps"

479 }

480 },

481 "additionalProperties": false,

482 "required": ["plan"]

483 }

484 }

485}

486```

487 

488#### View_image

489 

490This is a basic function used in codex-cli for the model to view images.

491 

492```json

493{

494 "type": "function",

495 "function": {

496 "name": "view_image",

497 "description": "Attach a local image (by filesystem path) to the conversation context for this turn.",

498 "strict": false,

499 "parameters": {

500 "type": "object",

501 "properties": {

502 "path": {

503 "type": "string",

504 "description": "Local filesystem path to an image file"

505 }

506 },

507 "additionalProperties": false,

508 "required": ["path"]

509 }

510 }

511}

512```

513 

514### Dedicated terminal-wrapping tools

515 

516If you would prefer your codex agent to use terminal-wrapping tools (like a dedicated `list_dir(‘.’)` tool instead of `terminal(‘ls .’)`, this generally works well. We see the best results when the name of the tool, the arguments, and the output are as close as possible to those from the underlying command, so it’s as in-distribution as possible for the model (which was primarily trained using a dedicated terminal tool). For example, if you notice the model using git via the terminal and would prefer it to use a dedicated tool, we found that creating a related tool, and adding a directive in the prompt to only use that tool for git commands, fully mitigated the model’s terminal usage for git commands.

517 

518```python

519GIT_TOOL = {

520 "type": "function",

521 "name": "git",

522 "description": (

523 "Execute a git command in the repository root. Behaves like running git in the"

524 " terminal; supports any subcommand and flags. The command can be provided as a"

525 " full git invocation (e.g., `git status -sb`) or just the arguments after git"

526 " (e.g., `status -sb`)."

527 ),

528 "parameters": {

529 "type": "object",

530 "properties": {

531 "command": {

532 "type": "string",

533 "description": (

534 "The git command to execute. Accepts either a full git invocation or"

535 " only the subcommand/args."

536 ),

537 },

538 "timeout_sec": {

539 "type": "integer",

540 "minimum": 1,

541 "maximum": 1800,

542 "description": "Optional timeout in seconds for the git command.",

543 },

544 },

545 "required": ["command"],

546 },

547}

548 

549...

550 

551PROMPT_TOOL_USE_DIRECTIVE = "- Strictly avoid raw `cmd`/terminal when a dedicated tool exists. Default to solver tools: `git` (all git), `list_dir`, `apply_patch`. Use `cmd`/`run_terminal_cmd` only when no listed tool can perform the action." # update with your desired tools

552```

553 

554### Other Custom Tools (web search, semantic search, memory, etc.)

555 

556The model hasn’t necessarily been post-trained to excel at these tools, but we have seen success here as well. To get the most out of these tools, we recommend:

557 

5581. Making the tool names and arguments as semantically “correct” as possible, for example “search” is ambiguous but “semantic_search” clearly indicates what the tool does, relative to other potential search-related tools you might have. “Query” would be a good param name for this tool.

5592. Be explicit in your prompt about when, why, and how to use these tools, including good and bad examples.

5603. It could also be helpful to make the results look different from outputs the model is accustomed to seeing from other tools, for example ripgrep results should look different from semantic search results to avoid the model collapsing into old habits.

561 

562### Parallel Tool Calling

563 

564In codex-cli, when parallel tool calling is enabled, the responses API request sets `parallel_tool_calls: true` and the following snippet is added to the system instructions:

565 

566```text

567## Exploration and reading files

568 

569- **Think first.** Before any tool call, decide ALL files/resources you will need.

570- **Batch everything.** If you need multiple files (even from different places), read them together.

571- **multi_tool_use.parallel** Use `multi_tool_use.parallel` to parallelize tool calls and only this.

572- **Only make sequential calls if you truly cannot know the next file without seeing a result first.**

573- **Workflow:** (a) plan all needed reads → (b) issue one parallel batch → (c) analyze results → (d) repeat if new, unpredictable reads arise.

574 

575**Additional notes**:

576- Always maximize parallelism. Never read files one-by-one unless logically unavoidable.

577- This concerns every read/list/search operations including, but not only, `cat`, `rg`, `sed`, `ls`, `git show`, `nl`, `wc`, ...

578- Do not try to parallelize using scripting or anything else than `multi_tool_use.parallel`.

579```

580 

581We've found it to be helpful and more in-distribution if parallel tool call items and responses are ordered in the following way:

582 

583```text

584function_call

585function_call

586function_call_output

587function_call_output

588```

589 

590### Tool Response Truncation

591 

592We recommend doing tool call response truncation as follows to be as in-distribution for the model as possible:

593 

594- Limit to 10k tokens. You can cheaply approximate this by computing `num_bytes/4`.

595- If you hit the truncation limit, you should use half of the budget for the beginning, half for the end, and truncate in the middle with `…3 tokens truncated…`

596 

597### New features in GPT-5.3 Codex

598 

599#### Preamble messages

600 

601The Responses API includes a `phase` parameter intended to prevent early stopping and other misbehavior when preamble messages are requested by the prompt. Correctly implementing this parameter is required for `gpt-5.3-codex`; otherwise, significant performance degradation can occur.

602 

603#### Phase

604 

605To better support preamble messages with `gpt-5.3-codex`, the Responses API includes a `phase` field designed to prevent early stopping on longer-running tasks and other misbehaviors.

606 

607##### Values

608 

609`phase` is one of:

610 

611- `null`

612- `"commentary"`

613- `"final_answer"`

614 

615##### Where it appears

616 

617You’ll receive `phase` on assistant output items (for example, `output_item.done`). Your integration must persist assistant output items, including their `phase`, and pass those assistant items back in subsequent requests.

618 

619**Important:** `phase` is only supported on assistant items. Do not add `phase` to user messages.

620 

621##### How it’s used downstream

622 

623When the model marks an output item with:

624 

625- `phase: "commentary"`: the corresponding assistant message should be treated as commentary/preamble-style content.

626- `phase: "final_answer"`: the corresponding assistant message should be treated as the final closeout.

627 

628Correctly preserving `phase` on assistant items is required for `gpt-5.3-codex`. If assistant `phase` metadata is dropped during history reconstruction, significant performance degradation can occur.

629 

630#### Preambles & Personality

631 

632Preambles are messages sent along with tool calls that provide user updates while working: short, human-readable progress and intent snapshots that keep the user oriented without turning the transcript into a tool-call log. GPT-5.3-Codex preambles have been tuned toward the following characteristics:

633 

634- Acknowledge then plan before any tool calls (1 sentence acknowledgement, 1–2 sentence plan).

635- Keep most updates to 1–2 sentences, and use longer updates only at real milestones.

636- Cadence: aim every 1–3 execution steps; hard floor: at least within every 6 steps or 10 tool calls.

637- Content per update: outcome/impact so far, next 1–3 steps, and open questions/learnings when present.

638- Tone: real person pairing, low-ceremony; avoid headings/status labels and log voice.

639 

640##### Personality (Friendly vs Pragmatic)

641 

642Personality is the higher-level vibe and collaboration posture that sits above preamble mechanics (cadence, length, and grounding). It affects word choice, how eagerly the model explains tradeoffs, and how much warmth it brings to the interaction.

643 

644The Codex app and CLI ship with support for two personalities provided here as example implementations for your harness.

645 

646###### Friendly

647 

648- More human, partner-y pairing energy.

649- Slightly more acknowledgement, reassurance, and context-setting.

650- Better when the user benefits from narrative orientation (onboarding, ambiguous tasks, higher-stakes changes).

651 

652###### Example Friendly personality prompt snippet from codex-cli

653 

654This snippet can be used in your system prompt to steer the pair programming personality of the model.

655 

656```text

657# Personality

658 

659You optimize for team morale and being a supportive teammate as much as code quality. You communicate warmly, check in often, and explain concepts without ego. You excel at pairing, onboarding, and unblocking others. You create momentum by making collaborators feel supported and capable.

660 

661## Values

662You are guided by these core values:

663* Empathy: Interprets empathy as meeting people where they are - adjusting explanations, pacing, and tone to maximize understanding and confidence.

664* Collaboration: Sees collaboration as an active skill: inviting input, synthesizing perspectives, and making others successful.

665* Ownership: Takes responsibility not just for code, but for whether teammates are unblocked and progress continues.

666 

667## Tone & User Experience

668Your voice is warm, encouraging, and conversational. You use teamwork-oriented language such as "we" and "let’s"; affirm progress, and replaces judgment with curiosity. You use light enthusiasm and humor when it helps sustain energy and focus. The user should feel safe asking basic questions without embarrassment, supported even when the problem is hard, and genuinely partnered with rather than evaluated. Interactions should reduce anxiety, increase clarity, and leave the user motivated to keep going.

669 

670You are NEVER curt or dismissive.

671 

672You are a patient and enjoyable collaborator: unflappable when others might get frustrated, while being an enjoyable, easy-going personality to work with. Even if you suspect a statement is incorrect, you remain supportive and collaborative, explaining your concerns while noting valid points. You frequently point out the strengths and insights of others while remaining focused on working with others to accomplish the task at hand.

673 

674## Escalation

675You escalate gently and deliberately when decisions have non-obvious consequences or hidden risk. Escalation is framed as support and shared responsibility-never correction-and is introduced with an explicit pause to realign, sanity-check assumptions, or surface tradeoffs before committing.

676```

677 

678###### Pragmatic

679 

680- More terse, direct, let’s ship delivery.

681- Fewer social flourishes; higher ratio of actionable information per token.

682- Better when latency/throughput matters, or your users already know the workflow and just want progress and results.

683 

684#### Troubleshooting & Metaprompting

685 

686Common failure modes we’ve been explicitly tracking:

687 

688- Overthinking / long time before first useful action (tool call or concrete plan).

689- Loggy / unnatural status updates instead of pair programmer collaboration.

690- Awkward preamble phrasing and repetitive tics ("Good catch", "Aha", "Got it–", etc.).

691 

692##### Metaprompting for targeted fixes

693 

694Failure modes like the ones above can typically be addressed through metaprompting. It’s possible to ask the model at the end of a turn that didn’t perform up to expectations how to improve its own instructions. The following prompt was used to produce some of the solutions to overthinking problems above and can be modified to meet your particular needs.

695 

696```text

697That was a high quality response, thanks! It seemed like it took you a while to finish responding though. Is there a way to clarify your instructions so you can get to a response as good as this faster next time? It’s extremely important to be efficient when providing these responses or users won’t get the most out of them in time. Let’s see if we can improve!

698think through the response you gave above

699read through your instructions starting from "" and look for anything that might have made you take longer to formulate a high quality response than you needed

700write out targeted (but generalized) additions/changes/deletions to your instructions to make a request like this one faster next time with the same level of quality

701```

702 

703When metaprompting inside a specific context, it is important to generate responses a few times if possible and pay attention to elements of the responses that are common between them. Some improvements or changes the model proposes might be overly specific to that particular situation, but you can often simplify them to arrive at a general improvement. We recommend creating an eval to measure whether a particular prompt change is better or worse for your particular use case.

704 

705##### Some examples

706 

707- For overthinking / slow starts: ask it to propose instruction changes that reduce time-to-first-tool-call or first concrete plan.

708- For overly loggy preambles: ask it to rewrite your user updates instructions to satisfy your particular preference constraints.

709 

guides/latest-model/gpt-5.4.md +1170 −0 created

Details

1# Using GPT-5.4

2 

3## Introduction

4 

5[GPT-5.4](https://developers.openai.com/api/docs/models/gpt-5.4) was released as a frontier model for professional work across the API and Codex. It helps developers analyze complex information, build production software, and automate multi-step workflows.

6 

7Within the GPT-5.4 generation, `gpt-5.4` is the general-purpose model for workflows that move between software engineering, reasoning, writing, and tool use.

8 

9This guide covers key features of the GPT-5 model family and how to get the most out of GPT-5.4.

10 

11## What's new

12 

13Compared with the previous GPT-5.2 model, GPT-5.4 shows improvements in:

14 

15- Coding, document understanding, tool use, and instruction following

16- Image perception and multimodal tasks

17- Long-running task execution and multi-step agent workflows

18- Token efficiency and end-to-end performance on tool-heavy workloads

19- Web search and multi-source synthesis for hard-to-locate information

20- Document-heavy and spreadsheet-heavy business workflows in customer service, analytics, and finance

21 

22GPT-5.4 brings the coding capabilities of GPT-5.3-Codex to our flagship frontier model. Developers can generate production-quality code, build polished front-end UI, follow repo-specific patterns, and handle multi-file changes with fewer retries. It also has a strong out-of-the-box coding personality, so teams spend less time on prompt tuning.

23 

24For agentic workloads, GPT-5.4 reduces end-to-end time across multi-step trajectories and often completes tasks with fewer tokens and tool calls. This makes agents more responsive and lowers the cost of operating complex workflows at scale in the API and Codex.

25 

26### New features in GPT-5.4

27 

28Like earlier GPT-5 models, GPT-5.4 supports custom tools, parameters to control verbosity and reasoning, and an allowed tools list. GPT-5.4 also introduces several capabilities that make it easier to build powerful agent systems, operate over larger bodies of information, and run more reliable automated workflows:

29 

30- **`tool_search` in the API:** GPT-5.4 improves tool search for larger tool ecosystems by using deferred tool loading. This makes tools searchable, loads only the relevant definitions, reduces token usage, and improves tool selection accuracy in real deployments. Learn more in the [tool search guide](https://developers.openai.com/api/docs/guides/tools-tool-search).

31- **1M token context window:** GPT-5.4 supports up to a 1M token context window, making it easier to analyze entire codebases, long document collections, or extended agent trajectories in a single request. Read more in the [1M context window](#1m-context-window) section.

32- **Built-in computer use:** GPT-5.4 is the first mainline model with built-in computer-use capabilities, enabling agents to interact directly with software to complete, verify, and fix tasks in a build-run-verify-fix loop. Learn more in the [computer use guide](https://developers.openai.com/api/docs/guides/tools-computer-use).

33- **Native compaction support:** GPT-5.4 is the first mainline model trained to support compaction, enabling longer agent trajectories while preserving key context.

34 

35## Model, API, and feature updates

36 

37Within this model generation, `gpt-5.4` is the general-purpose model for both broad tasks and coding. For more difficult problems, `gpt-5.4-pro` uses more compute to think longer and provide more consistent answers.

38 

39For smaller, faster variants, start with `gpt-5.4-mini` or `gpt-5.4-nano`.

40 

41To help you pick the model that best fits your use case, consider these tradeoffs:

42 

43| Variant | Best for |

44| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |

45| [`gpt-5.4`](https://developers.openai.com/api/docs/models/gpt-5.4) | General-purpose work, including complex reasoning, broad world knowledge, and code-heavy or multi-step agentic tasks |

46| [`gpt-5.4-pro`](https://developers.openai.com/api/docs/models/gpt-5.4-pro) | Tough problems that may take longer to solve and need deeper reasoning |

47| [`gpt-5.4-mini`](https://developers.openai.com/api/docs/models/gpt-5.4-mini) | High-volume coding, computer use, and agent workflows that still need strong reasoning |

48| [`gpt-5.4-nano`](https://developers.openai.com/api/docs/models/gpt-5.4-nano) | High-throughput tasks where speed and cost matter most |

49 

50### Lower reasoning effort

51 

52The `reasoning.effort` parameter controls how many reasoning tokens the model generates before producing a response. Earlier reasoning models like o3 supported only `low`, `medium`, and `high`: `low` favored speed and fewer tokens, while `high` favored more thorough reasoning.

53 

54GPT-5.2 and GPT-5.4 support `none` as their lowest reasoning effort for lower-latency interactions. It is the default setting for both models. If you need more thinking, slowly increase to `medium` and experiment with results.

55 

56With reasoning effort set to `none`, prompting is important. To improve the model's reasoning quality, even with the default settings, encourage it to “think” or outline its steps before answering.

57 

58Reasoning effort set to none

59 

60```bash

61curl --request POST \

62 --url https://api.openai.com/v1/responses \

63 --header "Authorization: Bearer $OPENAI_API_KEY" \

64 --header 'Content-type: application/json' \

65 --data '{

66 "model": "gpt-5.4",

67 "input": "Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

68 "reasoning": {

69 "effort": "none"

70 }

71}'

72```

73 

74```javascript

75import OpenAI from "openai";

76const openai = new OpenAI();

77 

78const response = await openai.responses.create({

79 model: "gpt-5.4",

80 input: "Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

81 reasoning: {

82 effort: "none"

83 }

84});

85 

86console.log(response);

87```

88 

89```python

90from openai import OpenAI

91client = OpenAI()

92 

93response = client.responses.create(

94 model="gpt-5.4",

95 input="Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

96 reasoning={

97 "effort": "none"

98 }

99)

100 

101print(response)

102```

103 

104 

105### Verbosity

106 

107Verbosity determines how many output tokens are generated. Lowering the number of tokens reduces overall latency. While the model's reasoning approach stays mostly the same, the model finds ways to answer more concisely—which can either improve or diminish answer quality, depending on your use case. Here are some scenarios for both ends of the verbosity spectrum:

108 

109- **High verbosity:** Use when you need the model to provide thorough explanations of documents or perform extensive code refactoring.

110- **Low verbosity:** Best for situations where you want concise answers or focused code generation, such as SQL queries.

111 

112GPT-5 made this option configurable as one of `high`, `medium`, or `low`. With GPT-5.4, verbosity remains configurable and defaults to `medium`.

113 

114When generating code with GPT-5.4, `medium` and `high` verbosity levels yield longer, more structured code with inline explanations, while `low` verbosity produces shorter, more concise code with minimal commentary.

115 

116Control verbosity

117 

118```bash

119curl --request POST \

120 --url https://api.openai.com/v1/responses \

121 --header "Authorization: Bearer $OPENAI_API_KEY" \

122 --header 'Content-type: application/json' \

123 --data '{

124 "model": "gpt-5.4",

125 "input": "What is the answer to the ultimate question of life, the universe, and everything?",

126 "text": {

127 "verbosity": "low"

128 }

129}'

130```

131 

132```javascript

133import OpenAI from "openai";

134const openai = new OpenAI();

135 

136const response = await openai.responses.create({

137 model: "gpt-5.4",

138 input: "What is the answer to the ultimate question of life, the universe, and everything?",

139 text: {

140 verbosity: "low"

141 }

142});

143 

144console.log(response);

145```

146 

147```python

148from openai import OpenAI

149client = OpenAI()

150 

151response = client.responses.create(

152 model="gpt-5.4",

153 input="What is the answer to the ultimate question of life, the universe, and everything?",

154 text={

155 "verbosity": "low"

156 }

157)

158 

159print(response)

160```

161 

162 

163You can still steer verbosity through prompting after setting it to `low` in the API. The verbosity parameter defines a general token range at the system prompt level, but the actual output is flexible to both developer and user prompts within that range.

164 

165#### 1M context window

166 

1671M token context window was introduced with GPT-5.4, making it easier to analyze entire codebases, long document collections, or extended agent trajectories in a single request.

168 

169We have separate standard pricing for requests under 272K and over 272K tokens, available in the [pricing docs](https://developers.openai.com/api/docs/pricing). If you use [priority processing](https://developers.openai.com/api/docs/guides/priority-processing), any prompt above 272K tokens is automatically processed at standard rates.

170 

171Long context pricing stacks with other pricing modifiers such as data residency and batch.

172 

173We have different rate limits for requests under 272K tokens and over 272K tokens; this is available on the [GPT-5.4 model page](https://developers.openai.com/api/docs/models/gpt-5.4).

174 

175## Using tools with GPT-5.4

176 

177GPT-5.4 has been post-trained on specific tools. See the [tools docs](https://developers.openai.com/api/docs/guides/tools) for more specific guidance.

178 

179### Computer use tool

180 

181Computer use lets GPT-5.4 operate software through the user interface by inspecting screenshots and returning structured actions for your harness to execute. It is a good fit for browser or desktop workflows where a person could complete the task through the UI, such as navigating a site, filling out forms, or validating that a change actually worked.

182 

183Use it in an isolated browser or VM, and keep a human in the loop for high-impact actions. The full guide covers the built-in Responses API loop, custom harness patterns, and code-execution-based setups.

184 

185[

186 

187<span slot="icon">

188 </span>

189 Learn how to run the built-in computer tool safely and integrate it with

190 your own harness.

191 

192](https://developers.openai.com/api/docs/guides/tools-computer-use)

193 

194### Tool search tool

195 

196Tool search lets GPT-5.4 defer large tool surfaces until runtime so the model loads only the definitions it needs. This is most useful when you have many functions, `namespaces`, or MCP tools and want to reduce token usage, preserve cache performance, and improve latency without exposing every schema up front.

197 

198Use hosted tool search when the candidate tools are already known at request time, or client-executed tool search when your application needs to decide what to load dynamically. The full guide also covers best practices for `namespaces`, MCP servers, and deferred loading.

199 

200[

201 

202<span slot="icon">

203 </span>

204 Learn how to defer tool definitions and load the right subset at runtime.

205 

206](https://developers.openai.com/api/docs/guides/tools-tool-search)

207 

208### Custom tools

209 

210When the GPT-5 model family launched, we introduced a new capability called custom tools, which lets models send any raw text as tool call input but still constrain outputs if desired. This tool behavior remains true in GPT-5.4.

211 

212[

213 

214<span slot="icon">

215 </span>

216 Learn about custom tools in the function calling guide.

217 

218](https://developers.openai.com/api/docs/guides/function-calling)

219 

220#### Freeform inputs

221 

222Define your tool with `type: custom` to enable models to send plaintext inputs directly to your tools, rather than being limited to structured JSON. The model can send any raw text—code, SQL queries, shell commands, configuration files, or long-form prose—directly to your tool.

223 

224```json

225{

226 "type": "custom",

227 "name": "code_exec",

228 "description": "Executes arbitrary python code"

229}

230```

231 

232#### Constraining outputs

233 

234GPT-5.4 supports context-free grammars (`CFGs`) for custom tools, letting you provide a Lark grammar to constrain outputs to a specific syntax or DSL. Attaching a CFG, for example a SQL or DSL grammar, ensures the assistant's text matches your grammar.

235 

236This enables precise, constrained tool calls or structured responses and lets you enforce strict syntactic or domain-specific formats directly in GPT-5.4's function calling, improving control and reliability for complex or constrained domains.

237 

238#### Best practices for custom tools

239 

240- **Write concise, explicit tool descriptions.** The model chooses what to send based on your description; state explicitly if you want it to always call the tool.

241- **Validate outputs on the server side**. Freeform strings are powerful but require safeguards against injection or unsafe commands.

242 

243### Allowed tools

244 

245The `allowed_tools` parameter under `tool_choice` lets you pass N tool definitions but restrict the model to only M (&lt; N) of them. List your full toolkit in `tools`, and then use an `allowed_tools` block to name the subset and specify a mode—either `auto` (the model may pick any of those) or `required` (the model must invoke one).

246 

247[

248 

249<span slot="icon">

250 </span>

251 Learn about the allowed tools option in the function calling guide.

252 

253](https://developers.openai.com/api/docs/guides/function-calling)

254 

255By separating all possible tools from the subset that can be used _now_, you gain greater safety, predictability, and improved prompt caching. You also avoid brittle prompt engineering, such as hard-coded call order. GPT-5.4 dynamically invokes or requires specific functions mid-conversation while reducing the risk of unintended tool usage over long contexts.

256 

257| | **Standard Tools** | **Allowed Tools** |

258| ---------------- | ----------------------------------------- | ------------------------------------------------------------- |

259| Model's universe | All tools listed under **`"tools": […]`** | Only the subset under **`"tools": […]`** in **`tool_choice`** |

260| Tool invocation | Model may or may not call any tool | Model restricted to (or required to call) chosen tools |

261| Purpose | Declare available capabilities | Constrain which capabilities are actually used |

262 

263```json

264{

265 "tool_choice": {

266 "type": "allowed_tools",

267 "mode": "auto",

268 "tools": [

269 { "type": "function", "name": "get_weather" },

270 { "type": "function", "name": "search_docs" }

271 ]

272 }

273}

274```

275 

276For a more detailed overview of all of these new features, see the [prompt guidance for GPT-5.4](https://developers.openai.com/api/docs/guides/latest-model?model=gpt-5.4#prompting-best-practices).

277 

278### Preambles

279 

280Preambles are brief, user-visible explanations that GPT-5.4 generates before invoking any tool or function, outlining its intent or plan—for example, “why I'm calling this tool.” They appear after the chain of thought and before the actual tool call, making the model's reasoning easier to understand and debug while supporting precise steering.

281 

282By letting GPT-5.4 “think out loud” before each tool call, preambles boost tool-calling accuracy (and overall task success) without bloating reasoning overhead. To enable preambles, add a system or developer instruction—for example: “Before you call a tool, explain why you are calling it.” GPT-5.4 adds a concise rationale to each specified tool call. The model may also output multiple messages between tool calls, which can enhance the interaction experience—particularly for minimal reasoning or latency-sensitive use cases.

283 

284For more on using preambles, see the [GPT-5 prompting cookbook](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_prompting_guide#tool-preambles).

285 

286## Migration quickstart

287 

288GPT-5.4 works best with the Responses API, which supports preserving reasoning context between turns to improve performance. Read below to migrate from your current model or API.

289 

290### Migrating from other models to GPT-5.4

291 

292Use the [OpenAI Docs

293 skill](https://github.com/openai/skills/tree/main/skills/.system/openai-docs)

294 when migrating existing prompts or workflows to GPT-5.4. It's available in our

295 public skills repository and the Codex desktop app.

296 

297While the model should be close to a drop-in replacement for GPT-5.2, there are a few key changes to call out. See [Prompt guidance for GPT-5.4](https://developers.openai.com/api/docs/guides/latest-model?model=gpt-5.4#prompting-best-practices) for specific updates to make in your prompts.

298 

299Using GPT-5 models with the Responses API provides improved intelligence because of the API design. The Responses API can pass the previous turn's CoT to the model. This leads to fewer generated reasoning tokens, higher cache hit rates, and less latency. To learn more, see an [in-depth guide](https://developers.openai.com/cookbook/examples/responses_api/reasoning_items) on the benefits of the Responses API.

300 

301When migrating to GPT-5.4 from an older OpenAI model, start by experimenting with reasoning levels and prompting strategies. Based on our testing, we recommend using our [prompt optimizer](https://platform.openai.com/chat/edit?models=gpt-5.4&optimize=true)—which automatically updates your prompts for GPT-5.4 based on our best practices—and following this model-specific guidance:

302 

303- **`gpt-5.2`**: `gpt-5.4` with default settings is meant to be a drop-in replacement.

304- **o3**: `gpt-5.4` with `medium` or `high` reasoning. Start with `medium` reasoning with prompt tuning, then increase to `high` if you aren't getting the results you want.

305- **`gpt-4.1`**: `gpt-5.4` with `none` reasoning. Start with `none` and tune your prompts; increase if you need better performance.

306- **`o4-mini` or `gpt-4.1-mini`**: `gpt-5.4-mini` with prompt tuning is a great replacement.

307- **`gpt-4.1-nano`**: `gpt-5.4-nano` with prompt tuning is a great replacement.

308 

309### New `phase` parameter

310 

311For long-running or tool-heavy GPT-5.4 flows in the Responses API, use the assistant message `phase` field to avoid early stopping and other misbehavior.

312 

313`phase` is optional at the API level, but we highly recommend using it. Use `phase: "commentary"` for intermediate assistant updates (such as preambles before tool calls) and `phase: "final_answer"` for the completed answer. Do not add `phase` to user messages.

314 

315If you use `previous_response_id`, that is usually the simplest path because

316 prior assistant state is preserved. If you replay assistant history manually,

317 preserve each original `phase` value.

318 

319Missing or dropped `phase` can cause preambles to be treated as final answers

320in those workflows. For additional guidance and examples, see the [GPT-5.4

321prompting guide](https://developers.openai.com/api/docs/guides/latest-model?model=gpt-5.4#phase-parameter).

322 

323Round-trip assistant phase values

324 

325```javascript

326import OpenAI from "openai";

327const client = new OpenAI();

328 

329const response = await client.responses.create({

330 model: "gpt-5.4",

331 input: [

332 {

333 role: "assistant",

334 phase: "commentary",

335 content:

336 "I’ll inspect the logs and then summarize root cause and remediation.",

337 },

338 {

339 role: "assistant",

340 phase: "final_answer",

341 content: "Root cause: cache invalidation race.",

342 },

343 {

344 role: "user",

345 content: "Great—now give me a rollout-safe fix plan.",

346 },

347 ],

348});

349 

350console.log(response.output_text);

351```

352 

353```python

354from openai import OpenAI

355 

356client = OpenAI()

357 

358response = client.responses.create(

359 model="gpt-5.4",

360 input=[

361 {

362 "role": "assistant",

363 "phase": "commentary",

364 "content": "I’ll inspect the logs and then summarize root cause and remediation.",

365 },

366 {

367 "role": "assistant",

368 "phase": "final_answer",

369 "content": "Root cause: cache invalidation race.",

370 },

371 {

372 "role": "user",

373 "content": "Great—now give me a rollout-safe fix plan.",

374 },

375 ],

376)

377 

378print(response.output_text)

379```

380 

381 

382### GPT-5.4 parameter compatibility

383 

384The following parameters are **only supported** when using GPT-5.4 with reasoning effort set to `none`:

385 

386- `temperature`

387- `top_p`

388- `logprobs`

389 

390Requests to GPT-5.4 or GPT-5.2 with any other reasoning effort setting, or to older GPT-5 models—for example, `gpt-5`, `gpt-5-mini`, or `gpt-5-nano`—that include these fields will raise an error.

391 

392To achieve similar results with reasoning effort set higher, or with another GPT-5 family model, try these alternative parameters:

393 

394- **Reasoning depth:** `reasoning: { effort: "none" | "low" | "medium" | "high" | "xhigh" }`

395- **Output verbosity:** `text: { verbosity: "low" | "medium" | "high" }`

396- **Output length:** `max_output_tokens`

397 

398### Migrating from Chat Completions to Responses API

399 

400The biggest difference, and main reason to migrate from Chat Completions to the Responses API for GPT-5.4, is support for passing chain of thought (CoT) between turns. See a full [comparison of the APIs](https://developers.openai.com/api/docs/guides/responses-vs-chat-completions).

401 

402Passing CoT exists only in the Responses API, and we've seen improved intelligence, fewer generated reasoning tokens, higher cache hit rates, and lower latency as a result of doing so. Most other parameters remain at parity, though the formatting is different. Here's how new parameters are handled differently between Chat Completions and the Responses API:

403 

404**Reasoning effort**

405 

406 

407 

408<div data-content-switcher-pane data-value="responses">

409 <div class="hidden">Responses API</div>

410 Generate response with reasoning effort set to none

411 

412```bash

413curl --request POST \

414 --url https://api.openai.com/v1/responses \

415 --header "Authorization: Bearer $OPENAI_API_KEY" \

416 --header "Content-type: application/json" \

417 --data '{

418 "model": "gpt-5.4",

419 "input": "How much gold would it take to coat the Statue of Liberty in a 1mm layer?",

420 "reasoning": {

421 "effort": "none"

422 }

423}'

424```

425 

426 </div>

427 <div data-content-switcher-pane data-value="chat" hidden>

428 <div class="hidden">Chat Completions</div>

429 Generate response with reasoning effort set to none

430 

431```bash

432curl --request POST \

433 --url https://api.openai.com/v1/chat/completions \

434 --header "Authorization: Bearer $OPENAI_API_KEY" \

435 --header "Content-type: application/json" \

436 --data '{

437 "model": "gpt-5.4",

438 "messages": [

439 {

440 "role": "user",

441 "content": "How much gold would it take to coat the Statue of Liberty in a 1mm layer?"

442 }

443 ],

444 "reasoning_effort": "none"

445}'

446```

447 

448 </div>

449 

450 

451 

452**Verbosity**

453 

454 

455 

456<div data-content-switcher-pane data-value="responses">

457 <div class="hidden">Responses API</div>

458 Control verbosity

459 

460```bash

461curl --request POST \

462 --url https://api.openai.com/v1/responses \

463 --header "Authorization: Bearer $OPENAI_API_KEY" \

464 --header "Content-type: application/json" \

465 --data '{

466 "model": "gpt-5.4",

467 "input": "What is the answer to the ultimate question of life, the universe, and everything?",

468 "text": {

469 "verbosity": "low"

470 }

471}'

472```

473 

474 </div>

475 <div data-content-switcher-pane data-value="chat" hidden>

476 <div class="hidden">Chat Completions</div>

477 Control verbosity

478 

479```bash

480curl --request POST \

481 --url https://api.openai.com/v1/chat/completions \

482 --header "Authorization: Bearer $OPENAI_API_KEY" \

483 --header "Content-type: application/json" \

484 --data '{

485 "model": "gpt-5.4",

486 "messages": [

487 {

488 "role": "user",

489 "content": "What is the answer to the ultimate question of life, the universe, and everything?"

490 }

491 ],

492 "verbosity": "low"

493}'

494```

495 

496 </div>

497 

498 

499 

500**Custom tools**

501 

502 

503 

504<div data-content-switcher-pane data-value="responses">

505 <div class="hidden">Responses API</div>

506 Custom tool call

507 

508```bash

509curl --request POST \

510 --url https://api.openai.com/v1/responses \

511 --header "Authorization: Bearer $OPENAI_API_KEY" \

512 --header "Content-type: application/json" \

513 --data '{

514 "model": "gpt-5.4",

515 "input": "Use the code_exec tool to calculate the area of a circle with radius equal to the number of r letters in blueberry",

516 "tools": [

517 {

518 "type": "custom",

519 "name": "code_exec",

520 "description": "Executes arbitrary Python code"

521 }

522 ]

523}'

524```

525 

526 </div>

527 <div data-content-switcher-pane data-value="chat" hidden>

528 <div class="hidden">Chat Completions</div>

529 Custom tool call

530 

531```bash

532curl --request POST \

533 --url https://api.openai.com/v1/chat/completions \

534 --header "Authorization: Bearer $OPENAI_API_KEY" \

535 --header "Content-type: application/json" \

536 --data '{

537 "model": "gpt-5.4",

538 "messages": [

539 {

540 "role": "user",

541 "content": "Use the code_exec tool to calculate the area of a circle with radius equal to the number of r letters in blueberry"

542 }

543 ],

544 "tools": [

545 {

546 "type": "custom",

547 "custom": {

548 "name": "code_exec",

549 "description": "Executes arbitrary Python code"

550 }

551 }

552 ]

553}'

554```

555 

556 </div>

557 

558 

559 

560 

561## Prompting best practices

562 

563When troubleshooting cases where GPT-5.4 treats an intermediate update as the

564 final answer, verify your integration preserves the assistant message `phase`

565 field correctly. See [Phase parameter](#phase-parameter) for details.

566 

567### Understand GPT-5.4 behavior

568 

569#### Where GPT-5.4 is strongest

570 

571GPT-5.4 tends to work especially well in these areas:

572 

573- Strong personality and tone adherence, with less drift over long answers

574- Agentic workflow robustness, with a stronger tendency to stick with multi-step work, retry, and complete agent loops end to end

575- Evidence-rich synthesis, especially in long-context or multi-tool workflows

576- Instruction adherence in modular, skill-based, and block-structured prompts when the contract is explicit

577- Long-context analysis across large, messy, or multi-document inputs

578- Batched or parallel tool calling while maintaining tool-call accuracy

579- Spreadsheet, finance, and Excel workflows that need instruction following, formatting fidelity, and stronger self-verification

580 

581#### Where explicit prompting still helps

582 

583Even with those strengths, GPT-5.4 benefits from more explicit guidance in a few recurring patterns:

584 

585- Low-context tool routing early in a session, when tool selection can be less reliable

586- Dependency-aware workflows that need explicit prerequisite and downstream-step checks

587- Reasoning effort selection, where higher effort is not always better and the right choice depends on task shape, not intuition

588- Research tasks that require disciplined source collection and consistent citations

589- Irreversible or high-impact actions that require verification before execution

590- Terminal or coding-agent environments where tool boundaries must stay clear

591 

592These patterns are observed defaults, not guarantees. Start with the smallest prompt that passes your evals, and add blocks only when they fix a measured failure mode.

593 

594### Use core prompt patterns

595 

596#### Keep outputs compact and structured

597 

598To improve token efficiency with GPT-5.4, constrain verbosity and enforce structured output through clear output contracts. In practice, this acts as an additional control layer alongside the `verbosity` parameter in the Responses API, allowing you to guide both how much the model writes and how it structures the output.

599 

600```xml

601<output_contract>

602- Return exactly the sections requested, in the requested order.

603- If the prompt defines a preamble, analysis block, or working section, do not treat it as extra output.

604- Apply length limits only to the section they are intended for.

605- If a format is required (JSON, Markdown, SQL, XML), output only that format.

606</output_contract>

607 

608<verbosity_controls>

609- Prefer concise, information-dense writing.

610- Avoid repeating the user's request.

611- Keep progress updates brief.

612- Do not shorten the answer so aggressively that required evidence, reasoning, or completion checks are omitted.

613</verbosity_controls>

614```

615 

616#### Set clear defaults for follow-through

617 

618Users often change the task, format, or tone mid-conversation. To keep the assistant aligned, define clear rules for when to proceed, when to ask, and how newer instructions override earlier defaults.

619 

620Use a default follow-through policy like this:

621 

622```xml

623<default_follow_through_policy>

624- If the user’s intent is clear and the next step is reversible and low-risk, proceed without asking.

625- Ask permission only if the next step is:

626 (a) irreversible,

627 (b) has external side effects (for example sending, purchasing, deleting, or writing to production), or

628 (c) requires missing sensitive information or a choice that would materially change the outcome.

629- If proceeding, briefly state what you did and what remains optional.

630</default_follow_through_policy>

631```

632 

633Make instruction priority explicit:

634 

635```xml

636<instruction_priority>

637- User instructions override default style, tone, formatting, and initiative preferences.

638- Safety, honesty, privacy, and permission constraints do not yield.

639- If a newer user instruction conflicts with an earlier one, follow the newer instruction.

640- Preserve earlier instructions that do not conflict.

641</instruction_priority>

642```

643 

644Higher-priority developer or system instructions remain binding.

645 

646**Guidance:** When instructions change mid-conversation, make the update explicit, scoped, and local. State what changed, what still applies, and whether the change affects the next turn or the rest of the conversation.

647 

648#### Handle mid-conversation instruction updates

649 

650For mid-conversation updates, use explicit, scoped steering messages that state:

651 

6521. Scope

6532. Override

6543. Carry forward

655 

656```text

657<task_update>

658For the next response only:

659- Do not complete the task.

660- Only produce a plan.

661- Keep it to 5 bullets.

662 

663All earlier instructions still apply unless they conflict with this update.

664</task_update>

665```

666 

667If the task itself changes, say so directly:

668 

669```text

670<task_update>

671The task has changed.

672Previous task: complete the workflow.

673Current task: review the workflow and identify risks only.

674 

675Rules for this turn:

676- Do not execute actions.

677- Do not call destructive tools.

678- Return exactly:

679 1. Main risks

680 2. Missing information

681 3. Recommended next step

682</task_update>

683```

684 

685#### Make tool use persistent when correctness depends on it

686 

687Use explicit rules to keep tool use thorough, dependency-aware, and appropriately paced, especially in workflows where later actions rely on earlier retrieval or verification. A common failure mode is skipping prerequisites because the right end state seems obvious.

688 

689GPT-5.4 can be less reliable at tool routing early in a session, when context is still thin. Prompt for prerequisites, dependency checks, and exact tool intent.

690 

691```xml

692<tool_persistence_rules>

693- Use tools whenever they materially improve correctness, completeness, or grounding.

694- Do not stop early when another tool call is likely to materially improve correctness or completeness.

695- Keep calling tools until:

696 (1) the task is complete, and

697 (2) verification passes (see <verification_loop>).

698- If a tool returns empty or partial results, retry with a different strategy.

699</tool_persistence_rules>

700```

701 

702This is especially important for workflows where the final action depends on earlier lookup or retrieval steps. One of the most common failure modes is skipping prerequisites because the intended end state seems obvious.

703 

704```xml

705<dependency_checks>

706- Before taking an action, check whether prerequisite discovery, lookup, or memory retrieval steps are required.

707- Do not skip prerequisite steps just because the intended final action seems obvious.

708- If the task depends on the output of a prior step, resolve that dependency first.

709</dependency_checks>

710```

711 

712Prompt for parallelism when the work is independent and wall-clock matters. Prompt for sequencing when dependencies, ambiguity, or irreversible actions matter more than speed.

713 

714```xml

715<parallel_tool_calling>

716- When multiple retrieval or lookup steps are independent, prefer parallel tool calls to reduce wall-clock time.

717- Do not parallelize steps that have prerequisite dependencies or where one result determines the next action.

718- After parallel retrieval, pause to synthesize the results before making more calls.

719- Prefer selective parallelism: parallelize independent evidence gathering, not speculative or redundant tool use.

720</parallel_tool_calling>

721```

722 

723#### Force completeness on long-horizon tasks

724 

725For multi-step workflows, a common failure mode is incomplete execution: the model finishes after partial coverage, misses items in a batch, or treats empty or narrow retrieval as final. GPT-5.4 becomes more reliable when the prompt defines explicit completion rules and recovery behavior.

726 

727Coverage can be achieved through sequential or parallel retrieval, but completion rules should remain explicit either way.

728 

729```xml

730<completeness_contract>

731- Treat the task as incomplete until all requested items are covered or explicitly marked [blocked].

732- Keep an internal checklist of required deliverables.

733- For lists, batches, or paginated results:

734 - determine expected scope when possible,

735 - track processed items or pages,

736 - confirm coverage before finalizing.

737- If any item is blocked by missing data, mark it [blocked] and state exactly what is missing.

738</completeness_contract>

739```

740 

741For workflows where empty, partial, or noisy retrieval is common:

742 

743```xml

744<empty_result_recovery>

745If a lookup returns empty, partial, or suspiciously narrow results:

746- do not immediately conclude that no results exist,

747- try at least one or two fallback strategies,

748 such as:

749 - alternate query wording,

750 - broader filters,

751 - a prerequisite lookup,

752 - or an alternate source or tool,

753- Only then report that no results were found, along with what you tried.

754</empty_result_recovery>

755```

756 

757#### Add a verification loop before high-impact actions

758 

759Once the workflow appears complete, add a lightweight verification step before returning the answer or taking an irreversible action. This helps catch requirement misses, grounding issues, and format drift before commit.

760 

761```xml

762<verification_loop>

763Before finalizing:

764- Check correctness: does the output satisfy every requirement?

765- Check grounding: are factual claims backed by the provided context or tool outputs?

766- Check formatting: does the output match the requested schema or style?

767- Check safety and irreversibility: if the next step has external side effects, ask permission first.

768</verification_loop>

769```

770 

771```xml

772<missing_context_gating>

773- If required context is missing, do NOT guess.

774- Prefer the appropriate lookup tool when the missing context is retrievable; ask a minimal clarifying question only when it is not.

775- If you must proceed, label assumptions explicitly and choose a reversible action.

776</missing_context_gating>

777```

778 

779For agents that actively take actions, add a short execution frame:

780 

781```xml

782<action_safety>

783- Pre-flight: summarize the intended action and parameters in 1-2 lines.

784- Execute via tool.

785- Post-flight: confirm the outcome and any validation that was performed.

786</action_safety>

787```

788 

789### Handle specialized workflows

790 

791#### Choose image detail explicitly for vision and computer use

792 

793If your workflow depends on visual precision, specify the image `detail` level in the prompt or integration instead of relying on `auto`. Use `high` for standard high-fidelity image understanding. Use `original` for large, dense, or spatially sensitive images, especially [computer use, localization, OCR, and click-accuracy tasks](https://developers.openai.com/api/docs/guides/tools-computer-use) on `gpt-5.4` and future models. Use `low` only when speed and cost matter more than fine detail. For more details on image detail levels, see the [Images and Vision guide](https://developers.openai.com/api/docs/guides/images-vision).

794 

795#### Lock research and citations to retrieved evidence

796 

797When citation quality matters, make both the source boundary and the format requirement explicit. This helps reduce fabricated references, unsupported claims, and citation-format drift.

798 

799```xml

800<citation_rules>

801- Only cite sources retrieved in the current workflow.

802- Never fabricate citations, URLs, IDs, or quote spans.

803- Use exactly the citation format required by the host application.

804- Attach citations to the specific claims they support, not only at the end.

805</citation_rules>

806```

807 

808```xml

809<grounding_rules>

810- Base claims only on provided context or tool outputs.

811- If sources conflict, state the conflict explicitly and attribute each side.

812- If the context is insufficient or irrelevant, narrow the answer or say you cannot support the claim.

813- If a statement is an inference rather than a directly supported fact, label it as an inference.

814</grounding_rules>

815```

816 

817If your application requires inline citations, require inline citations. If it requires footnotes, require footnotes. The key is to lock the format and prevent the model from improvising unsupported references.

818 

819#### Research mode

820 

821Push GPT-5.4 into a disciplined research mode. Use this pattern for research, review, and synthesis tasks. Do not force it onto short execution tasks or simple deterministic transforms.

822 

823```xml

824<research_mode>

825- Do research in 3 passes:

826 1) Plan: list 3-6 sub-questions to answer.

827 2) Retrieve: search each sub-question and follow 1-2 second-order leads.

828 3) Synthesize: resolve contradictions and write the final answer with citations.

829- Stop only when more searching is unlikely to change the conclusion.

830</research_mode>

831```

832 

833If your host environment uses a specific research tool or requires a submit step, combine this with the host's finalization contract.

834 

835#### Clamp strict output formats

836 

837For SQL, JSON, or other parse-sensitive outputs, tell GPT-5.4 to emit only the target format and check it before finishing.

838 

839```text

840<structured_output_contract>

841- Output only the requested format.

842- Do not add prose or markdown fences unless they were requested.

843- Validate that parentheses and brackets are balanced.

844- Do not invent tables or fields.

845- If required schema information is missing, ask for it or return an explicit error object.

846</structured_output_contract>

847```

848 

849If you are extracting document regions or OCR boxes, define the coordinate system and add a drift check:

850 

851```text

852<bbox_extraction_spec>

853- Use the specified coordinate format exactly, such as [x1,y1,x2,y2] normalized to 0..1.

854- For each box, include page, label, text snippet, and confidence.

855- Add a vertical-drift sanity check so boxes stay aligned with the correct line of text.

856- If the layout is dense, process page by page and do a second pass for missed items.

857</bbox_extraction_spec>

858```

859 

860#### Keep tool boundaries explicit in coding and terminal agents

861 

862In coding agents, GPT-5.4 works better when the rules for shell access and file editing are unambiguous. This is especially important when you expose tools like [Shell](https://developers.openai.com/api/docs/guides/tools-shell) or [Apply patch](https://developers.openai.com/api/docs/guides/tools-apply-patch).

863 

864#### User updates

865 

866GPT-5.4 does well with brief, outcome-based updates. Reuse the user-updates pattern from the 5.2 guide, but pair it with explicit completion and verification requirements.

867 

868Recommended update spec:

869 

870```xml

871<user_updates_spec>

872- Only update the user when starting a new major phase or when something changes the plan.

873- Each update: 1 sentence on outcome + 1 sentence on next step.

874- Do not narrate routine tool calls.

875- Keep the user-facing status short; keep the work exhaustive.

876</user_updates_spec>

877```

878 

879For coding agents, see the Prompting patterns for coding tasks section below for more specific guidance.

880 

881#### Prompting patterns for coding tasks

882 

883**Autonomy and persistence**

884 

885GPT-5.4 is generally more thorough end to end than earlier mainline models on coding and tool-use tasks, so you often need less explicit "verify everything" prompting. Still, for high-stakes changes such as production, migrations, or security work, keep a lightweight verification clause.

886 

887```xml

888<autonomy_and_persistence>

889Persist until the task is fully handled end-to-end within the current turn whenever feasible: do not stop at analysis or partial fixes; carry changes through implementation, verification, and a clear explanation of outcomes unless the user explicitly pauses or redirects you.

890 

891Unless the user explicitly asks for a plan, asks a question about the code, is brainstorming potential solutions, or some other intent that makes it clear that code should not be written, assume the user wants you to make code changes or run tools to solve the user's problem. In these cases, it's bad to output your proposed solution in a message, you should go ahead and actually implement the change. If you encounter challenges or blockers, you should attempt to resolve them yourself.

892</autonomy_and_persistence>

893```

894 

895**Intermediary updates**

896 

897Keep updates sparse and high-signal. In coding tasks, prefer updates at key points.

898 

899```xml

900<user_updates_spec>

901- Intermediary updates go to the `commentary` channel.

902- User updates are short updates while you are working. They are not final answers.

903- Use 1-2 sentence updates to communicate progress and new information while you work.

904- Do not begin responses with conversational interjections or meta commentary. Avoid openers such as acknowledgements ("Done -", "Got it", or "Great question") or similar framing.

905- Before exploring or doing substantial work, send a user update explaining your understanding of the request and your first step. Avoid commenting on the request or starting with phrases such as "Got it" or "Understood."

906- Provide updates roughly every 30 seconds while working.

907- When exploring, explain what context you are gathering and what you learned. Vary sentence structure so the updates do not become repetitive.

908- When working for a while, keep updates informative and varied, but stay concise.

909- When work is substantial, provide a longer plan after you have enough context. This is the only update that may be longer than 2 sentences and may contain formatting.

910- Before file edits, explain what you are about to change.

911- While thinking, keep the user informed of progress without narrating every tool call. Even if you are not taking actions, send frequent progress updates rather than going silent, especially if you are thinking for more than a short stretch.

912- Keep the tone of progress updates consistent with the assistant's overall personality.

913</user_updates_spec>

914```

915 

916**Formatting**

917 

918GPT-5.4 often defaults to more structured formatting and may overuse bullet lists. If you want a clean final response, explicitly clamp list shape.

919 

920```xml

921Never use nested bullets. Keep lists flat (single level). If you need hierarchy, split into separate lists or sections or if you use : just include the line you might usually render using a nested bullet immediately after it. For numbered lists, only use the `1. 2. 3.` style markers (with a period), never `1)`.

922```

923 

924**Frontend tasks**

925 

926Use this only when additional frontend guidance is useful.

927 

928```xml

929<frontend_tasks>

930When doing frontend design tasks, avoid generic, overbuilt layouts.

931 

932Use these hard rules:

933- One composition: The first viewport must read as one composition, not a dashboard, unless it is a dashboard.

934- Brand first: On branded pages, the brand or product name must be a hero-level signal, not just nav text or an eyebrow. No headline should overpower the brand.

935- Brand test: If the first viewport could belong to another brand after removing the nav, the branding is too weak.

936- Full-bleed hero only: On landing pages and promotional surfaces, the hero image should usually be a dominant edge-to-edge visual plane or background. Do not default to inset hero images, side-panel hero images, rounded media cards, tiled collages, or floating image blocks unless the existing design system clearly requires them.

937- Hero budget: The first viewport should usually contain only the brand, one headline, one short supporting sentence, one CTA group, and one dominant image. Do not place stats, schedules, event listings, address blocks, promos, "this week" callouts, metadata rows, or secondary marketing content there.

938- No hero overlays: Do not place detached labels, floating badges, promo stickers, info chips, or callout boxes on top of hero media.

939- Cards: Default to no cards. Never use cards in the hero unless they are the container for a user interaction. If removing a border, shadow, background, or radius does not hurt interaction or understanding, it should not be a card.

940- One job per section: Each section should have one purpose, one headline, and usually one short supporting sentence.

941- Real visual anchor: Imagery should show the product, place, atmosphere, or context.

942- Reduce clutter: Avoid pill clusters, stat strips, icon rows, boxed promos, schedule snippets, and competing text blocks.

943- Use motion to create presence and hierarchy, not noise. Ship 2-3 intentional motions for visually led work, and prefer Framer Motion when it is available.

944 

945Exception: If working within an existing website or design system, preserve the established patterns, structure, and visual language.

946</frontend_tasks>

947```

948 

949```xml

950<terminal_tool_hygiene>

951- Only run shell commands via the terminal tool.

952- Never "run" tool names as shell commands.

953- If a patch or edit tool exists, use it directly; do not attempt it in bash.

954- After changes, run a lightweight verification step such as ls, tests, or a build before declaring the task done.

955</terminal_tool_hygiene>

956```

957 

958#### Document localization and OCR boxes

959 

960For bbox tasks, be explicit about coordinate conventions and add drift tests.

961 

962```xml

963<bbox_extraction_spec>

964- Use the specified coordinate format exactly (for example [x1,y1,x2,y2] normalized 0..1).

965- For each bbox, include: page, label, text snippet, confidence.

966- Add a vertical-drift sanity check:

967 - ensure bboxes align with the line of text (not shifted up or down).

968- If dense layout, process page by page and do a second pass for missed items.

969</bbox_extraction_spec>

970```

971 

972#### Use runtime and API integration notes

973 

974For long-running or tool-heavy agents, the runtime contract matters as much as the prompt contract.

975 

976##### Phase parameter

977 

978For GPT-5.4, `gpt-5.3-codex`, and later Responses models, the `phase` field can

979help in the small number of long-running or tool-heavy flows where preambles or

980other intermediate assistant updates are mistaken for the final answer.

981 

982- `phase` is optional at the API level, but it is highly recommended. Best-effort inference may exist server-side, but explicit round-tripping of `phase` is strictly better.

983- Use `phase` for long-running or tool-heavy agents that may emit commentary before tool calls or before a final answer.

984- Preserve `phase` when replaying prior assistant items so the model can distinguish working commentary from the completed answer. This matters most in multi-step flows with preambles, tool-related updates, or multiple assistant messages in the same turn.

985- Do not add `phase` to user messages.

986- If you use `previous_response_id`, that is usually the simplest path, since OpenAI can often recover prior state without manually replaying assistant items.

987- If you replay assistant history yourself, preserve the original `phase` values.

988- Missing or dropped `phase` can cause preambles to be interpreted as final answers and degrade behavior on those multi-step tasks.

989 

990#### Preserve behavior in long sessions

991 

992Compaction unlocks significantly longer effective context windows, where user conversations can persist for many turns without hitting context limits or long-context performance degradation, and agents can perform very long trajectories that exceed a typical context window for long-running, complex tasks.

993 

994If you are using [Compaction](https://developers.openai.com/api/docs/guides/compaction) in the Responses API, compact after major milestones, treat compacted items as opaque state, and keep prompts functionally identical after compaction. The endpoint is ZDR compatible and returns an `encrypted_content` item that you can pass into future requests. GPT-5.4 tends to remain more coherent and reliable over longer, multi-turn conversations with fewer breakdowns as sessions grow.

995 

996For more guidance, see the [`/responses/compact` API reference](https://developers.openai.com/api/docs/api-reference/responses/compact).

997 

998#### Control personality for customer-facing workflows

999 

1000GPT-5.4 can be steered more effectively when you separate persistent personality from per-response writing controls. This is especially useful for customer-facing workflows such as emails, support replies, announcements, and blog-style content.

1001 

1002- **Personality (persistent):** sets the default tone, verbosity, and decision style across the session.

1003- **Writing controls (per response):** define the channel, register, formatting, and length for a specific artifact.

1004- **Reminder:** personality should not override task-specific output requirements. If the user asks for JSON, return JSON.

1005 

1006For natural, high-quality prose, the highest-leverage controls are:

1007 

1008- Give the model a clear persona.

1009- Specify the channel and emotional register.

1010- Explicitly ban formatting when you want prose.

1011- Use hard length limits.

1012 

1013```xml

1014<personality_and_writing_controls>

1015- Persona: <one sentence>

1016- Channel: <Slack | email | memo | PRD | blog>

1017- Emotional register: <direct/calm/energized/etc.> + "not <overdo this>"

1018- Formatting: <ban bullets/headers/markdown if you want prose>

1019- Length: <hard limit, e.g. <=150 words or 3-5 sentences>

1020- Default follow-through: if the request is clear and low-risk, proceed without asking permission.

1021</personality_and_writing_controls>

1022```

1023 

1024For more personality patterns you can lift directly, see the [Prompt Personalities cookbook](https://developers.openai.com/cookbook/examples/gpt-5/prompt_personalities).

1025 

1026**Professional memo mode**

1027 

1028For memos, reviews, and other professional writing tasks, general writing instructions are often not enough. These workflows benefit from explicit guidance on specificity, domain conventions, synthesis, and calibrated certainty.

1029 

1030```xml

1031<memo_mode>

1032- Write in a polished, professional memo style.

1033- Use exact names, dates, entities, and authorities when supported by the record.

1034- Follow domain-specific structure if one is requested.

1035- Prefer precise conclusions over generic hedging.

1036- When uncertainty is real, tie it to the exact missing fact or conflicting source.

1037- Synthesize across documents rather than summarizing each one independently.

1038</memo_mode>

1039```

1040 

1041This mode is especially useful for legal, policy, research, and executive-facing writing, where the goal is not just fluency, but disciplined synthesis and clear conclusions.

1042 

1043### Tune reasoning and migration

1044 

1045#### Treat reasoning effort as a last-mile knob

1046 

1047Reasoning effort is not one-size-fits-all. Treat it as a last-mile tuning knob, not the primary way to improve quality. In many cases, stronger prompts, clear output contracts, and lightweight verification loops recover much of the performance teams might otherwise seek through higher reasoning settings.

1048 

1049Recommended defaults:

1050 

1051- `none`: Best for fast, cost-sensitive, latency-sensitive tasks where the model does not need to think.

1052- `low`: Works well for latency-sensitive tasks where a small amount of thinking can produce a meaningful accuracy gain, especially with complex instructions.

1053- `medium` or `high`: Reserve for tasks that truly require stronger reasoning and can absorb the latency and cost tradeoff. Choose between them based on how much performance gain your task gets from additional reasoning.

1054- `xhigh`: Avoid as a default unless your evals show clear benefits. It is best suited for long, agentic, reasoning-heavy tasks where maximum intelligence matters more than speed or cost.

1055 

1056In practice, most teams should default to the `none`, `low`, or `medium` range.

1057 

1058Start with `none` for execution-heavy workloads such as workflow steps, field extraction, support triage, and short structured transforms.

1059 

1060Start with `medium` or higher for research-heavy workloads such as long-context synthesis, multi-document review, conflict resolution, and strategy writing. With `medium` and a well-engineered prompt, you can squeeze out a lot of performance.

1061 

1062For GPT-5.4 workloads, `none` can already perform well on action-selection and tool-discipline tasks. If your workload depends on nuanced interpretation, such as implicit requirements, ambiguity, or cancelled-tool-call recovery, start with `low` or `medium` instead.

1063 

1064Before increasing reasoning effort, first add:

1065 

1066- `<completeness_contract>`

1067- `<verification_loop>`

1068- `<tool_persistence_rules>`

1069 

1070If the model still feels too literal or stops at the first plausible answer, add an initiative nudge before raising reasoning effort:

1071 

1072```xml

1073<dig_deeper_nudge>

1074- Don’t stop at the first plausible answer.

1075- Look for second-order issues, edge cases, and missing constraints.

1076- If the task is safety or accuracy critical, perform at least one verification step.

1077</dig_deeper_nudge>

1078```

1079 

1080#### Migrate prompts to GPT-5.4 one change at a time

1081 

1082Use the same one-change-at-a-time discipline as the 5.2 guide: switch model first, pin `reasoning_effort`, run evals, then iterate.

1083 

1084These starting points work well for many migrations:

1085 

1086| Current setup | Suggested GPT-5.4 start | Notes |

1087| ------------------------- | ---------------------------------- | ------------------------------------------------------------------- |

1088| `gpt-5.2` | Match the current reasoning effort | Preserve the existing latency and quality profile first, then tune. |

1089| `gpt-5.3-codex` | Match the current reasoning effort | For coding workflows, keep the reasoning effort the same. |

1090| `gpt-4.1` or `gpt-4o` | `none` | Keep snappy behavior, and increase only if evals regress. |

1091| Research-heavy assistants | `medium` or `high` | Use explicit research multi-pass and citation gating. |

1092| Long-horizon agents | `medium` or `high` | Add tool persistence and completeness accounting. |

1093 

1094#### Small-model guidance for `gpt-5.4-mini` and `gpt-5.4-nano`

1095 

1096`gpt-5.4-mini` and `gpt-5.4-nano` are highly steerable, but they are less likely than larger models to infer missing steps, resolve ambiguity implicitly, or package outputs the way you intended unless you specify that behavior directly. In practice, prompts for smaller models are often a bit longer and more explicit.

1097 

1098**How `gpt-5.4-mini` differs**

1099 

1100- `gpt-5.4-mini` is more literal and makes fewer assumptions.

1101- It is strong when the task is clearly structured, but weaker on implicit workflows and ambiguity handling.

1102- By default, it may try to keep the conversation going with a follow-up question unless you suppress that behavior explicitly.

1103 

1104**Prompting `gpt-5.4-mini`**

1105 

1106- Put critical rules first.

1107- Specify the full execution order when tool use or side effects matter.

1108- Do not rely on "you MUST" alone. Use structural scaffolding such as numbered steps, decision rules, and explicit action definitions.

1109- Separate "do the action" from "report the action."

1110- Show the correct flow, not just the final format.

1111- Define ambiguity behavior explicitly: when to ask, abstain, or proceed.

1112- Specify packaging directly: answer length, whether to ask a follow-up question, citation style, and section order.

1113- Be careful with `output nothing else`. Prefer scoped instructions such as `after the final JSON, output nothing further`.

1114 

1115**Prompting `gpt-5.4-nano`**

1116 

1117- Use `gpt-5.4-nano` only for narrow, well-bounded tasks.

1118- Prefer closed outputs: labels, enums, short JSON, or fixed templates.

1119- Avoid multi-step orchestration unless the flow is extremely constrained.

1120- Route ambiguous or planning-heavy tasks to a stronger model instead of over-prompting `gpt-5.4-nano`.

1121 

1122**Good default pattern**

1123 

11241. Task

11252. Critical rule

11263. Exact step order

11274. Edge cases or clarification behavior

11285. Output format

11296. One correct example

1130 

1131**Avoid**

1132 

1133- Implied next steps

1134- Unspecified edge cases

1135- Schema-only prompts for tool workflows

1136- Generic instructions without structure

1137 

1138#### Web search and deep research

1139 

1140If you are migrating a research agent in particular, make these prompt updates before increasing reasoning effort:

1141 

1142- Add `<research_mode>`

1143- Add `<citation_rules>`

1144- Add `<empty_result_recovery>`

1145- Increase `reasoning_effort` one notch only after prompt fixes.

1146 

1147You can start from the 5.2 research block and then layer in citation gating and finalization contracts as needed.

1148 

1149GPT-5.4 performs especially well when the task requires multi-step evidence gathering, long-context synthesis, and explicit prompt contracts. In practice, the highest-leverage prompt changes are choosing reasoning effort by task shape, defining exact output and citation formats, adding dependency-aware tool rules, and making completion criteria explicit. The model is often strong out of the box, but it is most reliable when prompts clearly specify how to search, how to verify, and what counts as done.

1150 

1151### Next steps

1152 

1153- Review [Model, API, and feature updates](#model-api-and-feature-updates) for model capabilities, parameters, and API compatibility details.

1154- Read [Prompt engineering](https://developers.openai.com/api/docs/guides/prompt-engineering) for broader prompting strategies that apply across model families.

1155- Read [Compaction](https://developers.openai.com/api/docs/guides/compaction) if you are building long-running GPT-5.4 sessions in the Responses API.

1156 

1157 

1158## Further reading

1159 

1160[GPT-5.3-Codex prompting guide](https://developers.openai.com/cookbook/examples/gpt-5/codex_prompting_guide)

1161 

1162[GPT-5.4 blog post](https://openai.com/index/introducing-gpt-5-4/)

1163 

1164[GPT-5 frontend guide](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_frontend)

1165 

1166[GPT-5 model family: new features guide](https://developers.openai.com/cookbook/examples/gpt-5/gpt-5_new_params_and_tools)

1167 

1168[Cookbook on reasoning models](https://developers.openai.com/cookbook/examples/responses_api/reasoning_items)

1169 

1170[Comparison of Responses API vs. Chat Completions](https://developers.openai.com/api/docs/guides/migrate-to-responses)

guides/latest-model/gpt-5.5.md +326 −0 created

Details

1# Using GPT-5.5

2 

3## Introduction

4 

5GPT-5.5 raises the baseline for complex production workflows. It’s a strong fit for coding use cases, tool-heavy agents, grounded assistants, long-context retrieval, product-spec-to-plan workflows, and customer-facing workflows where execution quality and response polish are critical.

6 

7To get the most out of GPT-5.5, treat it as a new model family to tune for, not a drop-in replacement for `gpt-5.2` or `gpt-5.4`. Begin migration with a fresh baseline instead of carrying over every instruction from an older prompt stack. Start with the smallest prompt that preserves the product contract, then tune reasoning effort, verbosity, tool descriptions, and output format against representative examples.

8 

9GPT-5.5 supports all API features that were already available with GPT-5.4, including [prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching), [hosted tools](https://developers.openai.com/api/docs/guides/tools#available-tools), [tool search](https://developers.openai.com/api/docs/guides/tools-tool-search), [compaction](https://developers.openai.com/api/docs/guides/compaction), and `phase` handling for manually replayed assistant items.

10 

11See [Prompting best practices](#prompting-best-practices) for examples of successful prompting patterns.

12 

13## What's new

14 

15- **More efficient reasoning:** GPT-5.5 reaches strong results with fewer reasoning tokens than prior models, even at the same reasoning effort. This is especially useful in complex, tool-heavy, or multi-step workflows where token savings compound.

16- **Stronger task execution with outcome-first prompts:** GPT-5.5 is better at working from a clear goal, preserving constraints, and turning product intent into concrete next steps. Describe the expected outcome, success criteria, allowed side effects, evidence rules, and output shape. Avoid step-by-step process guidance unless the exact path matters.

17- **Stronger and more precise tool use:** GPT-5.5 is especially useful on large tool surfaces, multi-step service workflows, and long-running agent tasks. It tends to be more precise in tool selection and argument use.

18- **Tone is often more polished, but can be more direct:** GPT-5.5 often produces warmer, more readable answers with less prompt scaffolding.

19 

20## Behavioral changes

21 

221. **Reasoning effort now defaults to `medium`:** GPT-5.5 defaults to `medium` reasoning effort. Treat `medium` as the recommended balanced starting point for quality, reliability, latency, and cost. For latency-sensitive workflows, evaluate `low` before `none` when tool use, planning, search, or multi-step decision making still matters. Reserve `none` for latency-critical tasks that don't need reasoning or multi-chained tool calls, such as lightweight voice turns, fast information retrieval, and classification. Increase to `high` or `xhigh` only when evals show a measurable quality gain that justifies the extra latency and cost. See the [Reasoning models documentation](https://developers.openai.com/api/docs/guides/reasoning) for more details on recommended settings.

23 

24 Higher reasoning effort isn't automatically better. If the task has conflicting instructions, weak stopping criteria, or open-ended tool access, higher effort can lead to overthinking, unnecessary searching, or output quality regressions. Increase effort only when evals show a measurable quality gain.

25 

262. **Image inputs preserve more visual detail by default:** GPT-5.5 updates the default handling for image inputs to preserve more visual detail and improve computer use performance. When `image_detail` is unset or set to `auto`, the model now uses `original` behavior, preserving images without resizing up to 10,240,000 pixels or a 6,000-pixel dimension limit. For `high`, specify the value directly; it preserves images without resizing up to 2,500,000 pixels or a 2,048-pixel dimension limit. `low` now focuses on context efficiency and resizes images above a 512-pixel dimension limit more aggressively than previous models. See the [Images and vision documentation](https://developers.openai.com/api/docs/guides/images-vision).

27 

283. **Improved instruction following:** GPT-5.5 interprets prompts in a literal and thorough manner, enabling specific, descriptive instructions when the product requires them. Define success criteria and stopping rules, especially for long-running, tool-heavy, or evidence-gathering workflows. See [Write outcome-first prompts](#outcome-first-prompts-and-stopping-conditions) and [Keep the right specificity](#formatting).

29 

304. **Default style is more concise and direct:** GPT-5.5 tends to be efficient, direct, and task-oriented by default. This is useful for many production workflows, but customer-facing or conversational experiences may need explicit personality, warmth, rationale, and formatting guidance. Use `text.verbosity` intentionally: `medium` is the default, and `low` is often a better starting point for concise responses. See [Prompting best practices](#prompting-best-practices).

31 

325. **Coding workflows need stronger orchestration:** GPT-5.5 is better suited to complex coding tasks that require planning, tool use, codebase navigation, verification, and multi-step execution. For coding agents, be explicit about reuse, subagent delegation, test expectations, acceptance criteria, and when to continue versus ask for help.

33 

34## Migration quickstart

35 

36### Automated migration with Codex

37 

38Codex can apply the recommended changes in this guide with the [OpenAI Docs skill](https://github.com/openai/skills/tree/main/skills/.curated/openai-docs).

39 

40```text

41$openai-docs migrate this project to gpt-5.5

42```

43 

44To use this skill in other coding agents, download it from the [OpenAI skills repository](https://github.com/openai/skills/tree/main/skills/.curated/openai-docs).

45 

46### API and model parameters

47 

48- Update the model slug to `gpt-5.5`.

49- Use the Responses API for any reasoning, tool-calling, or multi-turn use case.

50- Tune `reasoning.effort`. Use `low` for efficient reasoning, `medium` for a balanced point on the latency/performance curve, `high` for complex agentic tasks that require hard reasoning and where latency matters less, and `xhigh` for the hardest asynchronous agentic tasks or evals that test the bounds of model intelligence. See the [Reasoning models documentation](https://developers.openai.com/api/docs/guides/reasoning).

51- To configure for more concise responses, set `text.verbosity` to `low`. On GPT-5.5, this will result in proportionally more concise responses than `low` verbosity with GPT-5.4.

52- For tool-heavy or long-running workflows, verify that your application handles `phase`, preambles, and assistant-item replay correctly.

53- Benchmark against other models on accuracy, token consumption, and end-to-end latency.

54 

55### Prompting

56 

57- State the expected outcome and success criteria.

58- Reduce or remove detailed step-by-step process guidance. Let GPT-5.5 choose the path unless the product requires that path.

59- Remove output schema definitions from the prompt where possible. Use [Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs) instead.

60- Optimize your prompt for caching: [static parts first, dynamic parts last](https://developers.openai.com/api/docs/guides/prompt-caching).

61- Drop the current date. The model is already aware of the current UTC date.

62- Review and optimize your prompts with [Prompting best practices](#prompting-best-practices).

63 

64## Using reasoning models

65 

66This guidance applies to GPT-5 series models and is worth revisiting whenever teams move workloads onto reasoning models. GPT-5.5 carries forward many capabilities that first appeared in earlier models, but they're still worth reviewing if you are moving from an earlier GPT-5 model, GPT-4.1, or a reasoning model such as o3.

67 

68Teams can overlook these features because they sit partly in API configuration and orchestration rather than in the prompt itself. Used together, the Responses API, reasoning controls, verbosity, structured outputs, prompt caching, tool design, hosted tools, and state management help reasoning models deliver their best intelligence, reliability, latency, and cost profile.

69 

70- **Responses API:** GPT-5.5 works best in the [Responses API](https://developers.openai.com/api/docs/guides/migrate-to-responses). Use `previous_response_id` for multi-turn state handling. For stateless or Zero Data Retention flows, pass back the relevant returned output items each turn. See [Passing context from the previous response](https://developers.openai.com/api/docs/guides/conversation-state#passing-context-from-the-previous-response) for details.

71- **Reasoning effort:** Use `reasoning.effort` to choose between `low`, `medium`, `high`, or `xhigh`. The default is `medium`, but many workloads will perform well with `low`. Reserve `none` for use cases where low latency is more important than intelligence. See [Reasoning Models](https://developers.openai.com/api/docs/guides/reasoning) for detailed recommendations.

72- **Verbosity:** Use `text.verbosity` to control output length. Treat final answer length as separate from reasoning quality; specify word budgets, section counts, table widths, or JSON-only output where needed.

73- **Structured Outputs:** Avoid describing the expected output schema in the prompt. Use [Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs) for automatic validation and increased accuracy.

74- **Prompt caching:** [Prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching) works automatically for eligible long prompts and can reduce latency and input-token cost. To maximize cache hits, keep stable content at the beginning of the request. Put dynamic user-specific context near the end. For repeated traffic with common prefixes, use `prompt_cache_key` consistently and track `usage.prompt_tokens_details.cached_tokens`.

75- **Tool calling:** GPT-5.5 supports the same tool-calling patterns as GPT-5.4, including function tools and tool-heavy agent workflows. Put most tool-specific guidance in the tool descriptions themselves: what the tool does, when to use it, required inputs, side effects, retry safety, and common error modes. Add tool-specific context to system instructions only when it applies across tools or materially changes the agent's operating policy.

76- **Hosted tools and tool search:** Prefer [OpenAI-hosted tools](https://developers.openai.com/api/docs/guides/tools) where they fit the workflow, such as web search, file search, code interpreter, image generation, and computer use. Hosted tools reduce custom orchestration burden and keep common tool patterns aligned with the Responses API and Agents SDK. Use custom function tools when you need to call your own systems, enforce domain-specific side effects, or expose internal business workflows. For large tool catalogs, consider using [tool search](https://developers.openai.com/api/docs/guides/tools-tool-search) to defer tool definitions and load only the relevant subset.

77- **Tool preambles:** Preambles can improve chat UX because the user sees an initial, useful status update before the model generates the final response. They also make tool use easier to follow: the model can state what it's about to check or do, then continue from that same assistant state after tool results arrive.

78- **`phase` handling:** If your application manually manages Responses state by passing output items back each turn instead of using `previous_response_id`, preserve the `phase` parameter on returned assistant output items and pass it back unchanged. This is especially important when using reasoning effort, preambles, or repeated tool calls. See [Phase parameter](https://developers.openai.com/api/docs/guides/reasoning#phase-parameter).

79- **Compaction:** For long-running agents, use [conversation/state compaction](https://developers.openai.com/api/docs/guides/compaction) intentionally. Preserve completed actions, active assumptions, IDs, tool outcomes, unresolved blockers, and the next concrete goal.

80- **Agents SDK:** For new agentic systems, use the latest [Agents SDK](https://developers.openai.com/api/docs/guides/agents) patterns for tool orchestration, tracing, handoffs, and state management rather than rebuilding orchestration from scratch.

81- **Current date:** GPT-5.5 is aware of the current date in UTC. You don't need to add the current date to system instructions. Add explicit date or timezone context only when the application needs a business-specific timezone, policy-effective date, user-local date, or other non-UTC reference point.

82 

83## Prompting best practices

84 

85GPT-5.5 works best when prompts define the outcome and leave room for the model to choose an efficient solution path. Compared with earlier models, you can often use shorter, more outcome-oriented prompts: describe what good looks like, what constraints matter, what evidence is available, and what the final answer should contain.

86 

87Avoid carrying over every instruction from an older prompt stack. Legacy prompts often over-specify the process because earlier models needed more help staying on track. With GPT-5.5, that can add noise, narrow the model's search space, or lead to overly mechanical answers.

88 

89The patterns here are starting points. Adapt them to your product surface, tools, evals, and user experience goals.

90 

91### Personality and behavior

92 

93GPT-5.5's default style is efficient, direct, and task-oriented. This is useful for production systems: responses stay focused, behavior is easier to steer, and the model avoids unnecessary conversational padding.

94 

95For customer-facing assistants, support workflows, coaching experiences, and other conversational products, define both personality and collaboration style.

96 

97- **Personality** controls how the assistant sounds: tone, warmth, directness, formality, humor, empathy, and level of polish.

98- **Collaboration style** controls how the assistant works: when it asks questions, when it makes assumptions, how proactive it should be, how much context it gives, when it checks work, and how it handles uncertainty or risk.

99 

100Keep both short. Personality instructions should shape the user experience. Collaboration instructions should shape task behavior. Neither should replace clear goals, success criteria, tool rules, or stopping conditions.

101 

102Example personality block for a steady task-focused assistant:

103 

104```text

105# Personality

106You are a capable collaborator: approachable, steady, and direct. Assume the user is competent and acting in good faith, and respond with patience, respect, and practical helpfulness.

107 

108Prefer making progress over stopping for clarification when the request is already clear enough to attempt. Use context and reasonable assumptions to move forward. Ask for clarification only when the missing information would materially change the answer or create meaningful risk, and keep any question narrow.

109 

110Stay concise without becoming curt. Give enough context for the user to understand and trust the answer, then stop. Use examples, comparisons, or simple analogies when they make the point easier to grasp. When correcting the user or disagreeing, be candid but constructive. When an error is pointed out, acknowledge it plainly and focus on fixing it.

111 

112Match the user's tone within professional bounds. Avoid emojis and profanity by default, unless the user explicitly asks for that style or has clearly established it as appropriate for the conversation.

113```

114 

115Example personality block for an expressive collaborative assistant:

116 

117```text

118# Personality

119Adopt a vivid conversational presence: intelligent, curious, playful when appropriate, and attentive to the user's thinking. Ask good questions when the problem is blurry, then become decisive once there is enough context.

120 

121Be warm, collaborative, and polished. Conversation should feel easy and alive, but not chatty for its own sake. Offer a real point of view rather than merely mirroring the user, while staying responsive to their goals and constraints.

122 

123Be thoughtful and grounded when the task calls for synthesis or advice. State a clear recommendation when you have enough context, explain important tradeoffs, and name uncertainty without becoming evasive.

124```

125 

126For more expressive products, add warmth, curiosity, humor, or point of view explicitly, but keep the block short. Use personality to shape the experience, not to compensate for unclear goals or missing task instructions.

127 

128### Improve time to first visible token with a preamble

129 

130In streaming applications, users notice how long it takes before the first visible response appears. GPT-5.5 may spend time reasoning, planning, or preparing tool calls before emitting visible text.

131 

132For longer or tool-heavy tasks, prompt the model to start with a short preamble: a brief visible update that acknowledges the request and states the first step. This can improve perceived responsiveness without changing the underlying task.

133 

134Use this pattern when the task may take more than one step, require tool calls, or involve a long-running agent workflow.

135 

136```text

137Before any tool calls for a multi-step task, send a short user-visible update that acknowledges the request and states the first step. Keep it to one or two sentences.

138```

139 

140For coding agents that expose separate message phases, you can be more explicit:

141 

142```text

143You must always start with an intermediary update before any content in the analysis channel if the task will require calling tools. The user update should acknowledge the request and explain your first step.

144```

145 

146### Outcome-first prompts and stopping conditions

147 

148GPT-5.5 is strongest when the prompt defines the target outcome, success criteria, constraints, and available context, then lets the model choose the path.

149 

150For many tasks, describe the destination rather than every step. This gives the model room to choose the right search, tool, or reasoning strategy for the task.

151 

152Prefer this:

153 

154```text

155Resolve the customer's issue end to end.

156 

157Success means:

158- the eligibility decision is made from the available policy and account data

159- any allowed action is completed before responding

160- the final answer includes completed_actions, customer_message, and blockers

161- if evidence is missing, ask for the smallest missing field

162```

163 

164**Avoid unnecessary absolute rules.** Older prompts often use strict instructions like `ALWAYS`, `NEVER`, `must`, and `only` to control model behavior. Use those words for true invariants, such as safety rules, required output fields, or actions that should never happen. For judgment calls, such as when to search, ask for clarification, use a tool, or keep iterating, prefer decision rules instead.

165 

166Avoid this style of instruction unless every step is truly required:

167 

168```text

169First inspect A, then inspect B, then compare every field, then think through

170all possible exceptions, then decide which tool to call, then call the tool,

171then explain the entire process to the user.

172```

173 

174Add explicit stopping conditions:

175 

176```text

177Resolve the user query in the fewest useful tool loops, but do not let loop minimization outrank correctness, accessible fallback evidence, calculations, or required citation tags for factual claims.

178 

179After each result, ask: "Can I answer the user's core request now with useful evidence and citations for the factual claims?" If yes, answer.

180```

181 

182Define missing-evidence behavior:

183 

184```text

185Use the minimum evidence sufficient to answer correctly, cite it precisely, then stop.

186```

187 

188### Formatting

189 

190GPT-5.5 is highly steerable on output format and structure. Use that control when it improves comprehension or product fit.

191 

192Set `text.verbosity`, describe the expected output shape, and reserve heavier structure for cases where it improves comprehension or your product UI needs a stable artifact. The API default for `text.verbosity` is `medium`; use `low` when you prefer shorter, more concise responses.

193 

194Plain conversational formatting:

195 

196```text

197Let formatting serve comprehension. Use plain paragraphs as the default format for normal conversation, explanations, reports, documentation, and technical writeups. Keep the presentation clean and readable without making the structure feel heavier than the content.

198 

199Use headers, bold text, bullets, and numbered lists sparingly. Reach for them when the user requests them, when the answer needs clear comparison or ranking, or when the information would be harder to scan as prose. Otherwise, favor short paragraphs and natural transitions.

200 

201Respect formatting preferences from the user. If they ask for a terse answer, minimal formatting, no bullets, no headers, or a specific structure, follow that preference unless there is a strong reason not to.

202```

203 

204Add explicit audience and length guidance:

205 

206```text

207Write for a senior business audience. Keep the answer under 400 words. Use short paragraphs and only include bullets when they improve scannability. Prioritize the conclusion first, then the reasoning, then caveats.

208```

209 

210For editing, rewriting, summaries, or customer-facing messages, tell the model what to preserve before asking it to improve style. This pattern is useful when you want polish without expansion.

211 

212```text

213Preserve the requested artifact, length, structure, and genre first. Quietly improve clarity, flow, and correctness. Do not add new claims, extra sections, or a more promotional tone unless explicitly requested.

214```

215 

216### Grounding, citations, and retrieval budgets

217 

218For grounded answers, citation behavior should be part of the prompt. Define what needs support, what counts as enough evidence, and how the model should behave when evidence is missing. Absence of evidence shouldn't automatically become a factual "no." For more details and examples, see the [citation formatting guide](https://developers.openai.com/api/docs/guides/citation-formatting).

219 

220#### Add an explicit retrieval budget

221 

222Retrieval budgets are stopping rules for search. They tell the model when enough evidence is enough.

223 

224```text

225For ordinary Q&A, start with one broad search using short, discriminative keywords. If the top results contain enough citable support for the core request, answer from those results instead of searching again.

226 

227Make another retrieval call only when:

228- The top results do not answer the core question.

229- A required fact, parameter, owner, date, ID, or source is missing.

230- The user asked for exhaustive coverage, a comparison, or a comprehensive list.

231- A specific document, URL, email, meeting, record, or code artifact must be read.

232- The answer would otherwise contain an important unsupported factual claim.

233 

234Do not search again to improve phrasing, add examples, cite nonessential details, or support wording that can safely be made more generic.

235```

236 

237### Creative drafting guardrails

238 

239For drafting tasks, tell the model which claims must come from sources and which parts may be creatively written. This is especially important for slides, launch copy, customer summaries, talk tracks, leadership blurbs, and narrative framing.

240 

241```text

242For creative or generative requests such as slides, leadership blurbs, outbound copy, summaries for sharing, talk tracks, or narrative framing, distinguish source-backed facts from creative wording.

243 

244- Use retrieved or provided facts for concrete product, customer, metric, roadmap, date, capability, and competitive claims, and cite those claims.

245- Do not invent specific names, first-party data claims, metrics, roadmap status, customer outcomes, or product capabilities to make the draft sound stronger.

246- If there is little or no citable support, write a useful generic draft with placeholders or clearly labeled assumptions rather than unsupported specifics.

247```

248 

249### Frontend engineering and visual taste

250 

251For frontend work, refer to the [example instructions](https://developers.openai.com/api/docs/guides/frontend-prompt) for practical ways to steer UI quality. They cover product and user context, design-system alignment, first-screen usability, familiar controls, expected states, responsive behavior, and common generated-UI defaults to avoid, such as generic heroes, nested cards, decorative gradients, visible instructional text, and broken layouts.

252 

253### Prompt the model to check its work

254 

255Give GPT-5.5 access to tools that let it check outputs when validation is possible.

256 

257For coding agents, ask for concrete validation commands:

258 

259```text

260After making changes, run the most relevant validation available:

261- targeted unit tests for changed behavior

262- type checks or lint checks when applicable

263- build checks for affected packages

264- a minimal smoke test when full validation is too expensive

265 

266If validation cannot be run, explain why and describe the next best check.

267```

268 

269For visual artifacts, ask for inspection after rendering:

270 

271```text

272Render the artifact before finalizing. Inspect the rendered output for layout, clipping, spacing, missing content, and visual consistency. Revise until the rendered output matches the requirements.

273```

274 

275For engineering and planning tasks, make implementation plans traceable:

276 

277```text

278For implementation plans, include:

279- requirements and where each is addressed

280- named resources, files, APIs, or systems involved

281- state transitions or data flow where relevant

282- validation commands or checks

283- failure behavior

284- privacy and security considerations

285- open questions that materially affect implementation

286```

287 

288### Phase parameter

289 

290Starting with GPT-5.4, long-running or tool-heavy Responses workflows can use assistant-item `phase` values to distinguish intermediate updates from final answers. GPT-5.5 uses the same pattern.

291 

292If you use `previous_response_id`, the API preserves prior assistant state automatically. If your application manually replays assistant output items into the next request, preserve each original `phase` value and pass it back unchanged. This matters most when a response includes preambles, repeated tool calls, or a final answer after intermediate assistant updates.

293 

294```text

295If manually replaying assistant items:

296- Preserve assistant `phase` values exactly.

297- Use `phase: "commentary"` for intermediate user-visible updates.

298- Use `phase: "final_answer"` for the completed answer.

299- Do not add `phase` to user messages.

300```

301 

302### Suggested prompt structure

303 

304Use this structure as a starting point for complex prompts. Keep each section short. Add detail only where it changes behavior.

305 

306```text

307Role: [1-2 sentences defining the model's function, context, and job]

308 

309# Personality

310[tone, demeanor, and collaboration style]

311 

312# Goal

313[user-visible outcome]

314 

315# Success criteria

316[what must be true before the final answer]

317 

318# Constraints

319[policy, safety, business, evidence, and side-effect limits]

320 

321# Output

322[sections, length, and tone]

323 

324# Stop rules

325[when to retry, fallback, abstain, ask, or stop]

326```

guides/latest-model/gpt-5.6.md +224 −0 created

Details

1---

2latestModelInfo:

3 model: gpt-5.6-sol

4 migrationGuide: /api/docs/guides/upgrading-to-gpt-5p6-sol.md

5 promptingGuide: /api/docs/guides/prompt-guidance-gpt-5p6.md

6---

7 

8# Using GPT-5.6

9 

10## Introduction

11 

12GPT-5.6 sets a new quality and efficiency baseline for complex production workflows. GPT-5.6 is especially token-efficient and improves frontend aesthetics, including layout, visual hierarchy, and design judgment.

13 

14GPT-5.6 also introduces a new naming scheme. The `gpt-5.6` alias routes requests to `gpt-5.6-sol`, the model for flagship capability. Use `gpt-5.6-terra` for strong performance at a lower price and `gpt-5.6-luna` for efficient, high-volume workloads.

15 

16When migrating from GPT-5.5 or GPT-5.4, start with your current GPT-5.5 or GPT-5.4 reasoning setting, then test the same setting and one level lower on representative tasks. GPT-5.6 can often maintain or improve quality with fewer tokens, but the best setting depends on your workload.

17 

18## What is new

19 

20- **Programmatic Tool Calling:** GPT-5.6 can write JavaScript to call eligible tools, pass results between calls, and process intermediate outputs in a hosted runtime. Use [Programmatic Tool Calling](https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling) for bounded, tool-heavy workflows that do not require fresh model judgment between each step. Programmatic Tool Calling is ZDR-compatible with no additional container costs.

21- **Multi-agent [beta]:** [Multi-agent](https://developers.openai.com/api/docs/guides/responses-multi-agent) lets a GPT-5.6 instance coordinate multiple subagents in parallel and synthesize their results. Similar to ultra mode in Codex, this can reduce wall-clock time and improve performance for complex tasks that divide cleanly into independent workstreams. Multi-agent is available as a beta feature in the Responses API as we iterate on developer feedback.

22- **Explicit prompt caching:** GPT-5.6 lets you mark exactly which reusable prompt prefixes OpenAI caches. You can still use automatic caching in implicit mode. OpenAI bills cache writes at 1.25× the uncached input rate, while cache reads remain discounted. Learn how to [configure prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching).

23- **Persisted reasoning:** GPT-5.6 can reuse available reasoning items across turns to improve multi-turn quality and cache efficiency. Use `reasoning.context` to select the behavior. Learn how to [preserve reasoning across calls](https://developers.openai.com/api/docs/guides/reasoning#preserve-reasoning-across-calls).

24- **Max reasoning effort:** GPT-5.6 supports `max` reasoning effort for demanding tasks that need more exploration and verification. If you currently use `xhigh`, compare both settings on representative workloads.

25- **Pro mode:** GPT-5.6 can perform more model work to improve reliability on difficult tasks and return a single final answer. Enable it with `reasoning.mode: "pro"` when quality matters more than latency and token usage. Learn how to [use pro mode](https://developers.openai.com/api/docs/guides/reasoning#reasoning-mode).

26- **Token efficiency:** GPT-5.6 reaches frontier performance with fewer output tokens.

27- **Frontend design:** GPT-5.6 creates more polished and usable websites and applications, with stronger layout, visual hierarchy, and design judgment.

28- **Intent understanding:** GPT-5.6 can better infer the user's underlying goal and intended level of work from context, so you often do not need to prescribe every step. Continue to provide domain context, hard constraints, approval boundaries, and success criteria. Tell the model when an important ambiguity should trigger a question.

29- **Original image detail:** GPT-5.6 preserves the original dimensions of images sent with `original` or `auto` detail instead of resizing them to a patch budget or pixel-dimension limit. Large images can use more input tokens and increase latency. Learn how to [choose an image detail level](https://developers.openai.com/api/docs/guides/images-vision#choose-an-image-detail-level).

30 

31## Safeguards

32 

33When using GPT-5.6 models, users may encounter safeguards that block or refuse some requests due to real-time cyber and biology misuse classifiers that are run as model outputs are generated. Other requests may take longer because generation is paused for several seconds mid-stream while these classifiers synchronously review outputs. Safeguards may occasionally intervene on legitimate work, particularly in dual-use areas where defensive and offensive activity can initially look similar.

34 

35If your application serves individual end users, send a stable, privacy-preserving `safety_identifier` with each request. See [Implement safety identifiers](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers) for guidance.

36 

37We are continuously evolving these safeguards so that they are robust and effective in holding up to adversarial pressure, while preserving access to legitimate work such as code review, vulnerability research, patch development, debugging, security education, and defensive testing.

38 

39<div id="migrate-to-gpt-56" aria-hidden="true"></div>

40 

41## Migration quickstart

42 

43### Migrate with Codex

44 

45Codex can apply the recommended changes in this guide with the [OpenAI Docs skill](https://github.com/openai/skills/tree/main/skills/.curated/openai-docs).

46 

47```text

48$openai-docs migrate this project to the GPT-5.6 model family

49```

50 

51To use this skill in other coding agents, download it from the [OpenAI skills repository](https://github.com/openai/skills/tree/main/skills/.curated/openai-docs).

52 

53### Update API and model parameters

54 

55- Choose the target model for the workload. Use `gpt-5.6-sol` for frontier capability, `gpt-5.6-terra` for a balance of intelligence and cost, or `gpt-5.6-luna` for efficient, high-volume workloads. The `gpt-5.6` alias routes requests to `gpt-5.6-sol`.

56- Use the [Responses API](https://developers.openai.com/api/docs/guides/migrate-to-responses) for reasoning, tool-calling, and multi-turn workflows.

57- Set `reasoning.effort` intentionally. GPT-5.6 supports `none`, `low`, `medium`, `high`, `xhigh`, and `max`.

58 - If you are migrating from GPT-5.5 or GPT-5.4, preserve your current reasoning effort as the baseline, then compare one level lower.

59 - If you use `none`, keep it as your latency baseline and also test `low` when the workflow benefits from reasoning or tool use.

60 - Use `medium` as a balanced starting point and `low` for latency-sensitive workloads.

61 - Use `high` or `xhigh` when more reasoning produces a measured quality gain.

62 - Reserve `max` for the hardest quality-first workloads. Compare `max` and `xhigh` to find the best quality, latency, and cost tradeoff for your use case.

63- To use pro mode, keep your selected GPT-5.6 model and set `reasoning.mode` to `pro` in the Responses API; do not switch to a separate Pro model slug. Choose `reasoning.effort` independently. If you omit it, GPT-5.6 defaults to `medium` in both standard and pro modes. See [reasoning mode](https://developers.openai.com/api/docs/guides/reasoning#reasoning-mode) for a request example and billing details.

64- Configure persisted reasoning based on how much prior reasoning is still relevant.

65 - Omit `reasoning.context` or set it to `auto` to use the model's default. Check the response's `reasoning.context` field to confirm the effective mode.

66 - Set `reasoning.context` to `all_turns` when the task's goals, assumptions, and priorities stay stable across turns.

67 - With `all_turns`, continue with `previous_response_id` to make reasoning from earlier responses available to the model.

68 - When managing history manually, preserve and resend previous user inputs and every response output item. For `store: false` or Zero Data Retention, add `include: ["reasoning.encrypted_content"]` and replay the returned encrypted reasoning items.

69 - Set `reasoning.context` to `current_turn` when earlier reasoning is no longer relevant.

70- Review prompt caching. You do not need to change code to keep using implicit caching. Because GPT-5.6 cache writes cost 1.25× the uncached input rate, track `cached_tokens` and `cache_write_tokens` to understand net cost. Use explicit breakpoints or `prompt_cache_options.mode: "explicit"` to avoid unnecessary writes, and replace `prompt_cache_retention` with `prompt_cache_options.ttl`.

71- To use Programmatic Tool Calling, add the `programmatic_tool_calling` tool and opt eligible tools in with `allowed_callers`. Update your application to handle `program` items, program-issued function calls, and `program_output` items while preserving each call's `call_id` and `caller` linkage. See the [Programmatic Tool Calling guide](https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling) for request and continuation examples.

72 - Benchmark the PTC-enabled workflow on representative tasks. Compare task success, final-answer completeness, required evidence, total tokens, latency, and cost. Fewer calls, turns, or intermediate outputs are improvements only when the final answer still meets the required quality bar.

73 

74## Prompting best practices

75 

76### Favor leaner prompts

77 

78Removing repeated instructions and examples and simplifying tool descriptions can improve task performance and token efficiency. In a sample of internal coding-agent eval runs, configurations with leaner system prompts improved evaluation scores by roughly 10–15% while reducing total tokens by 41–66% and cost by 33–67%. Results will vary by workload, so treat these ranges as directional and validate changes on representative tasks from your own application.

79 

80To simplify prompts without losing important guidance:

81 

82- Start with a prompt and tool set that already works. Remove one group of instructions, examples, or tools at a time, then rerun the same evals.

83- State each instruction once.

84- Expose only tools relevant to the task, and keep their descriptions concise and precise.

85- Keep examples and style guidance when they encode a product requirement or correct a measured gap.

86- Track context both at the start of a run and as the conversation grows. Long sessions can amplify repeated prompt and tool content.

87 

88### Define autonomy and approval boundaries

89 

90GPT-5.6 can be proactive and persistent when carrying out multi-step tasks. Define what level of action each request authorizes so the model can continue safe, in-scope work without unnecessary pauses while stopping before external, destructive, costly, or scope-expanding actions.

91 

92A compact policy is usually sufficient:

93 

94```text

95For requests to answer, explain, review, diagnose, or plan, inspect the relevant

96materials and report the result. Do not implement changes unless the request also

97asks for them.

98 

99For requests to change, build, or fix, make the requested in-scope local changes

100and run relevant non-destructive validation without asking first.

101 

102Require confirmation for external writes, destructive actions, purchases, or a

103material expansion of scope.

104```

105 

106Name safe local actions explicitly, such as reading files, inspecting logs, editing in-scope code, and running tests. Keep the policy in one place and state each rule once. Repeating instructions such as “ask first,” “do not mutate,” or “wait for approval” can cause unnecessary approval requests for safe, expected actions.

107 

108### Set response length and style

109 

110GPT-5.6 tends to be more concise by default than GPT-5.5. When migrating, check whether broad brevity instructions such as “Be concise” or “Keep it short” are still useful. They may be unnecessary for some tasks and can sometimes make responses too brief. Keep them when they reliably produce the output your application needs.

111 

112For more consistent control across requests, use `text.verbosity` to set the default level of detail, then use the prompt for task-specific requirements.

113 

114#### Set a default with `text.verbosity`

115 

116Choose `low`, `medium`, or `high` as the default level of detail for a request. In the prompt, specify any task-specific length, structure, or required content. See [Set up `text.verbosity`](https://developers.openai.com/api/docs/guides/deployment-checklist#set-up-textverbosity) for an API example.

117 

118#### Specify what a short answer must include

119 

120When a task calls for a shorter answer, identify the information the model must preserve and the detail it can omit. For example:

121 

122```text

123Lead with the conclusion. Include the evidence needed to support it, any material

124caveat, and the next action. Omit secondary detail and repetition.

125 

126Keep all required facts, decisions, caveats, and next steps. Trim introductions,

127repetition, generic reassurance, and optional background first.

128```

129 

130This gives the model a clear priority order: preserve the content needed to complete the task, then remove lower-value detail.

131 

132#### Define the tone

133 

134Broad labels such as “friendly” or “empathetic” can be ambiguous. Describe the writing choices that define your product's tone, such as how directly to state the answer, when to acknowledge a problem, and whether reassurance or a sign-off is appropriate.

135 

136```text

137State the answer directly. If the user reports a problem, acknowledge the

138specific issue before giving the next step. Use reassurance only when it is

139relevant. Omit generic praise and unnecessary sign-offs.

140```

141 

142### Pro mode

143 

144#### Choose pro mode when quality matters most

145 

146Pro mode is a Responses API execution mode that applies more model work to a request before returning a single final answer. It can improve reliability on difficult tasks, but it increases latency and aggregates the tokens from that work in reported usage. Those tokens are billed at the selected model's standard token rates.

147 

148Use pro mode when a marginal quality improvement materially affects the outcome and the task is difficult enough to benefit, such as complex optimization, high-value coding or review, or deep analysis with clear evaluation criteria. Prefer standard mode for routine, latency-sensitive, or high-volume work, and whenever your evaluations do not show a meaningful gain from pro mode.

149 

150Reasoning mode and reasoning effort are independent. Pro mode works with any GPT-5.6 model and its supported reasoning efforts. Start with the same model and effort as your standard-mode baseline, then compare configurations on representative tasks instead of assuming that the highest effort is always the best tradeoff.

151 

152#### Configure pro mode in the API

153 

154Enable pro mode in the API request. Keep the same outcome-focused prompt you use in standard mode: state the goal, relevant context, constraints, required evidence, success criteria, and output format. You do not need to ask the model to “use pro mode,” “think harder,” or generate several candidate answers.

155 

156For example:

157 

158```text

159Review this database migration plan for failure modes that could cause data loss

160or extended downtime. For each finding, cite the relevant step, estimate impact

161and likelihood, and recommend a specific mitigation. Return the five most

162important risks in severity order.

163```

164 

165#### Compare quality and cost

166 

167Compare standard and pro modes on the same representative tasks. Measure task success, answer completeness, required evidence, total tokens, latency, and cost. Use pro mode selectively where its quality or reliability gain justifies the extra model work.

168 

169Learn more in the [reasoning mode guide](https://developers.openai.com/api/docs/guides/reasoning#reasoning-mode).

170 

171### Programmatic Tool Calling

172 

173#### Choose Programmatic Tool Calling by task shape

174 

175Programmatic Tool Calling (PTC) works best for bounded workflows where code can process several tool results or large intermediate outputs and return a much smaller structured result. Use it for filtering, joining, ranking, deduplication, aggregation, validation, or other predictable processing.

176 

177Multiple, parallel, or dependent calls alone do not justify Programmatic Tool Calling. Prefer direct, non-PTC tool calls when:

178 

179- One call is sufficient

180- The intermediate outputs are already small

181- Each result may change the model’s next decision

182- An action requires approval

183- The final output must preserve citations or native artifacts

184 

185#### Make routing instructions task-specific

186 

187Do not rely on tool availability or generic instructions such as “use Programmatic Tool Calling efficiently” to produce the right route. When both direct and programmatic calling are available, explicitly state:

188 

189- Which bounded stage should use Programmatic Tool Calling.

190- Which tools it may call.

191- The exact output schema and required evidence.

192- Concurrency, retry, and stopping limits.

193- Which work should remain direct.

194 

195Tool descriptions should document their expected return fields, types, and error behavior. If the model cannot determine the return shape before writing the program, prefer direct tool calling so it can inspect the result before deciding how to use it.

196 

197If both routes are needed, define one clear handoff and tell the model not to switch routes or repeat completed work.

198 

199For example:

200 

201```text

202<tool_orchestration>

203Use Programmatic Tool Calling for [bounded stage] using only [eligible tools].

204Run independent calls concurrently when safe. Use only documented tool input

205and output fields.

206 

207Process and reduce the intermediate results, then emit exactly [output schema],

208including the evidence needed for the final answer.

209 

210Stop when [condition] is met. Retry transient failures at most [R] times.

211Do not repeat completed calls or perform side-effecting actions. If a required

212result is still missing, return a clear structured failure.

213 

214Use direct tool calls for [semantic judgment, approval, or final validation].

215</tool_orchestration>

216```

217 

218#### Assess the final answer

219 

220The `program_output` item and final assistant `message` are separate outputs; make sure to test both. In theory, a program can return the correct records while the message omits a required field, citation, or caveat.

221 

222Compare direct and programmatic calling on the same representative tasks. Check whether the final response is correct, complete, and includes the required evidence. Then compare total tokens, latency, cost, calls, turns, and retries. Count lower resource use as an improvement only when the response still passes your existing evals.

223 

224Learn more in the [Programmatic Tool Calling guide](https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling).

Details

164- `gpt-5-codex`164- `gpt-5-codex`

165- `gpt-4.1`165- `gpt-4.1`

166 166 

167Extended prompt cache retention keeps cached prefixes active for longer, up to a maximum of 24 hours. Extended Prompt Caching works by offloading the key/value tensors to GPU-local storage when memory is full, significantly increasing the storage capacity available for caching.167Extended prompt cache retention keeps cached prefixes active for longer, up to a maximum of 24 hours. Extended Prompt Caching works by offloading the key/value tensors to GPU-local storage when memory is full, significantly increasing the storage capacity available for caching. Note that only key/value tensors are cached in GPU-local storage, not the prompts themselves.

168 168 

169Key/value tensors are the intermediate representation from the model's attention layers produced during prefill. Only the key/value tensors may be persisted in local storage; the original customer content, such as prompt text, is only retained in memory.169Key/value tensors are the intermediate representation from the model's attention layers produced during prefill. Only the key/value tensors may be persisted in local storage; the original customer content, such as prompt text, is only retained in memory.

170 170 

Details

2 2 

3**Reasoning models** like [GPT-5.5](https://developers.openai.com/api/docs/models/gpt-5.5) use internal reasoning tokens before producing a response. This helps the model plan, use tools effectively, inspect alternatives, recover from ambiguity, and solve harder multi-step tasks. Reasoning models work especially well for complex problem solving, coding, scientific reasoning, and multi-step agentic workflows. They're also the best models for [Codex CLI](https://github.com/openai/codex), our lightweight coding agent.3**Reasoning models** like [GPT-5.5](https://developers.openai.com/api/docs/models/gpt-5.5) use internal reasoning tokens before producing a response. This helps the model plan, use tools effectively, inspect alternatives, recover from ambiguity, and solve harder multi-step tasks. Reasoning models work especially well for complex problem solving, coding, scientific reasoning, and multi-step agentic workflows. They're also the best models for [Codex CLI](https://github.com/openai/codex), our lightweight coding agent.

4 4 

5Start with `gpt-5.6` for most reasoning workloads. If you need the highest-intelligence API option for more challenging problems that can tolerate more latency, use <a href="/api/docs/models/gpt-5.6-sol"><code>gpt-5.6-sol</code></a> in the Responses API with `reasoning.mode` set to `pro`. For lower cost, consider `gpt-5.4` and for lower cost and latency, consider `gpt-5.4-mini`.5Start with `gpt-5.6` for most reasoning workloads. If you need the highest-intelligence API option for more challenging problems that can tolerate more latency, use <a href="/api/docs/models/gpt-5.6-sol"><code>gpt-5.6-sol</code></a> in the Responses API with `reasoning.mode` set to `pro`. For lower cost, consider [`gpt-5.6-terra`](https://developers.openai.com/api/docs/models/gpt-5.6-terra), or [`gpt-5.6-luna`](https://developers.openai.com/api/docs/models/gpt-5.6-luna) for the lowest cost and latency.

6 6 

7**Reasoning models work better with the [Responses7**Reasoning models work better with the [Responses

8 API](https://developers.openai.com/api/docs/guides/migrate-to-responses)**. While the Chat Completions API8 API](https://developers.openai.com/api/docs/guides/migrate-to-responses)**. While the Chat Completions API

Details

104 104 

105 return response.output105 return response.output

106 .flatMap((item) =>106 .flatMap((item) =>

107 item.type === "message" && item.agent?.agent_name === "/root"107 item.type === "message" &&

108 item.agent?.agent_name === "/root" &&

109 item.phase === "final_answer"

108 ? item.content110 ? item.content

109 : [],111 : [],

110 )112 )

Details

256class WorkspaceEditor:256class WorkspaceEditor:

257 async def create_file(self, operation):257 async def create_file(self, operation):

258 # convert the diff to the file content258 # convert the diff to the file content

259 content = apply_diff("", operation.diff, create=True)259 content = apply_diff("", operation.diff, mode="create")

260 # write the file content to the file system260 # write the file content to the file system

261 return {"status": "completed", "output": f"Created {operation.path}"}261 return {"status": "completed", "output": f"Created {operation.path}"}

262 262