SpyBara
Go Premium

Documentation 2026-11-08 22:59 UTC to 2026-11-09 23:02 UTC

51 files changed +391 −530. View all changes and history on the product overview
2026
Fri 13 23:58 Thu 12 22:57 Wed 11 23:57 Tue 10 23:02 Mon 9 23:02 Sun 8 22:59 Sat 7 22:59 Fri 6 23:00 Thu 5 23:00 Wed 4 22:58 Tue 3 22:58 Mon 2 23:58 Sun 1 23:00
Details

15 15 

16Sometimes, determinism may be impacted due to necessary changes OpenAI makes to model configurations on our end. To help you keep track of these changes, we expose the [`system_fingerprint`](https://developers.openai.com/api/reference/resources/chat#chat/object-system_fingerprint) field. If this value is different, you may see different outputs due to changes we've made on our systems.16Sometimes, determinism may be impacted due to necessary changes OpenAI makes to model configurations on our end. To help you keep track of these changes, we expose the [`system_fingerprint`](https://developers.openai.com/api/reference/resources/chat#chat/object-system_fingerprint) field. If this value is different, you may see different outputs due to changes we've made on our systems.

17 17 

18[Deterministic outputs18[Deterministic outputs](https://developers.openai.com/cookbook/examples/reproducible_outputs_with_the_seed_parameter)

19 19 

20Explore the new seed parameter in the OpenAI cookbook

20 21 

21 22 

22 Explore the new seed parameter in the OpenAI cookbook](https://developers.openai.com/cookbook/examples/reproducible_outputs_with_the_seed_parameter)

23 23 

24## Managing tokens24## Managing tokens

25 25 

Details

34 34 

35## Related evaluation surfaces35## Related evaluation surfaces

36 36 

37[Getting started with evals: Datasets37[Getting started with evals: Datasets](https://developers.openai.com/api/docs/guides/evaluation-getting-started)

38 38 

39Operate a flywheel of continuous improvement using evaluations.

39 40 

40 41 

41 Operate a flywheel of continuous improvement using evaluations.](https://developers.openai.com/api/docs/guides/evaluation-getting-started)

42 42 

43[Working with evals43[Working with evals](https://developers.openai.com/api/docs/guides/evals)

44 44 

45Evaluate against external models, interact with evals via API, and more.

45 46 

46 47 

47 Evaluate against external models, interact with evals via API, and more.](https://developers.openai.com/api/docs/guides/evals)

48 48 

49[Prompt optimizer49[Prompt optimizer](https://developers.openai.com/api/docs/guides/prompt-optimizer)

50 50 

51Use your dataset to automatically improve your prompts.

51 52 

52 53 

53 Use your dataset to automatically improve your prompts.](https://developers.openai.com/api/docs/guides/prompt-optimizer)

54 54 

55[Cookbook: Building resilient prompts with evals55[Cookbook: Building resilient prompts with evals](https://developers.openai.com/cookbook/examples/evaluation/building_resilient_prompts_using_an_evaluation_flywheel)

56 56 

57 57Operate a flywheel of continuous improvement using evaluations.

58 

59 Operate a flywheel of continuous improvement using evaluations.](https://developers.openai.com/cookbook/examples/evaluation/building_resilient_prompts_using_an_evaluation_flywheel)

Details

30openssl rand -hex 3230openssl rand -hex 32

31```31```

32 32 

33Deploy the Worker in your Cloudflare account:

34 

35 

36 

37Deploy to Cloudflare

38 33 

34Deploy the Worker in your Cloudflare account:

39 35 

36[Deploy to Cloudflare](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/sandbox-sdk/tree/main/openai/agents-api)

40 37 

41Enter these values when prompted:38Enter these values when prompted:

42 39 

Details

134if err != nil {134if err != nil {

135 panic(err)135 panic(err)

136}136}

137fmt.Println(automation)137fmt.Println(automation.ID)

138```138```

139 139 

140```java140```java


710if err != nil {710if err != nil {

711 panic(err)711 panic(err)

712}712}

713fmt.Println(automation)713fmt.Println(automation.ID)

714```714```

715 715 

716```java716```java


912if err != nil {912if err != nil {

913 panic(err)913 panic(err)

914}914}

915fmt.Println(automation)915fmt.Println(automation.ID)

916```916```

917 917 

918```java918```java


1150if err != nil {1150if err != nil {

1151 panic(err)1151 panic(err)

1152}1152}

1153fmt.Println(automation)1153fmt.Println(automation.ID)

1154```1154```

1155 1155 

1156```java1156```java


1426if err != nil {1426if err != nil {

1427 panic(err)1427 panic(err)

1428}1428}

1429fmt.Println(automation)1429fmt.Println(automation.ID)

1430```1430```

1431 1431 

1432```java1432```java


1673if err != nil {1673if err != nil {

1674 panic(err)1674 panic(err)

1675}1675}

1676fmt.Println(automation)1676fmt.Println(automation.ID)

1677```1677```

1678 1678 

1679```java1679```java


1900if err != nil {1900if err != nil {

1901 panic(err)1901 panic(err)

1902}1902}

1903fmt.Println(automation)1903fmt.Println(automation.ID)

1904```1904```

1905 1905 

1906```java1906```java


2075if err != nil {2075if err != nil {

2076 panic(err)2076 panic(err)

2077}2077}

2078fmt.Println(automation)2078fmt.Println(automation.ID)

2079```2079```

2080 2080 

2081```java2081```java


2442if err != nil {2442if err != nil {

2443 panic(err)2443 panic(err)

2444}2444}

2445fmt.Println(automation)2445fmt.Println(automation.ID)

2446```2446```

2447 2447 

2448```java2448```java


2706if err != nil {2706if err != nil {

2707 panic(err)2707 panic(err)

2708}2708}

2709fmt.Println(automation)2709fmt.Println(automation.ID)

2710```2710```

2711 2711 

2712```java2712```java

Details

227 227 

228 228 

229 229 

230 [Models and providers230 [Models and providers](https://developers.openai.com/api/docs/guides/agents/models)

231 231 

232Choose models, defaults, and transport strategy for this agent.

232 233 

233 234 

234 Choose models, defaults, and transport strategy for this agent.](https://developers.openai.com/api/docs/guides/agents/models)235 [Using tools](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)

235 [Using tools

236 236 

237Add capabilities the agent can call directly.

237 238 

238 239 

239 Add capabilities the agent can call directly.](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)240 [Orchestration and handoffs](https://developers.openai.com/api/docs/guides/agents/orchestration)

240 [Orchestration and handoffs

241 241 

242Choose how specialists collaborate once one agent is no longer enough.

242 243 

243 244 

244 Choose how specialists collaborate once one agent is no longer enough.](https://developers.openai.com/api/docs/guides/agents/orchestration)245 [Running agents](https://developers.openai.com/api/docs/guides/agents/running-agents)

245 [Running agents

246 246 

247 247Understand the runtime loop, state, and streaming behavior.

248 

249 Understand the runtime loop, state, and streaming behavior.](https://developers.openai.com/api/docs/guides/agents/running-agents)

Details

262 262 

263 263 

264 264 

265 [Running agents265 [Running agents](https://developers.openai.com/api/docs/guides/agents/running-agents)

266 266 

267See how interruptions and resumptions fit into the runtime loop.

267 268 

268 269 

269 See how interruptions and resumptions fit into the runtime loop.](https://developers.openai.com/api/docs/guides/agents/running-agents)270 [Results and state](https://developers.openai.com/api/docs/guides/agents/results)

270 [Results and state

271 271 

272Learn which result surfaces paused runs return to your application.

272 273 

273 274 

274 Learn which result surfaces paused runs return to your application.](https://developers.openai.com/api/docs/guides/agents/results)275 [Using tools](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)

275 [Using tools

276 276 

277 277Decide which tool surfaces need validation or approval before side effects happen.

278 

279 Decide which tool surfaces need validation or approval before side effects

280 happen.](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)

Details

194 194 

195 195 

196 196 

197 [Using tools197 [Using tools](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)

198 198 

199See how hosted tools, function tools, and agents-as-tools fit beside MCP.

199 200 

200 201 

201 See how hosted tools, function tools, and agents-as-tools fit beside MCP.](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)202 [Guardrails and human review](https://developers.openai.com/api/docs/guides/agents/guardrails-approvals)

202 [Guardrails and human review

203 203 

204Add approval or validation boundaries around sensitive capabilities.

204 205 

205 206 

206 Add approval or validation boundaries around sensitive capabilities.](https://developers.openai.com/api/docs/guides/agents/guardrails-approvals)207 [Agent workflow evaluation](https://developers.openai.com/api/docs/guides/agent-evals)

207 [Agent workflow evaluation

208 208 

209 209Move from one-off traces into repeatable grading once behavior stabilizes.

210 

211 Move from one-off traces into repeatable grading once behavior stabilizes.](https://developers.openai.com/api/docs/guides/agent-evals)

Details

118 118 

119 119 

120 120 

121 [Agent definitions121 [Agent definitions](https://developers.openai.com/api/docs/guides/agents/define-agents)

122 122 

123Keep model choices aligned with the responsibilities of each specialist.

123 124 

124 125 

125 Keep model choices aligned with the responsibilities of each specialist.](https://developers.openai.com/api/docs/guides/agents/define-agents)126 [Running agents](https://developers.openai.com/api/docs/guides/agents/running-agents)

126 [Running agents

127 127 

128See how transport and model choices affect the runtime loop.

128 129 

129 130 

130 See how transport and model choices affect the runtime loop.](https://developers.openai.com/api/docs/guides/agents/running-agents)131 [External models](https://developers.openai.com/api/docs/guides/external-models)

131 [External models

132 132 

133 133Compare broader provider options when a mixed-model stack matters.

134 

135 Compare broader provider options when a mixed-model stack matters.](https://developers.openai.com/api/docs/guides/external-models)

Details

113 113 

114 114 

115 115 

116 [Agent definitions116 [Agent definitions](https://developers.openai.com/api/docs/guides/agents/define-agents)

117 117 

118Refine each specialist's instructions, tools, and output contract.

118 119 

119 120 

120 Refine each specialist's instructions, tools, and output contract.](https://developers.openai.com/api/docs/guides/agents/define-agents)121 [Running agents](https://developers.openai.com/api/docs/guides/agents/running-agents)

121 [Running agents

122 122 

123Understand how handoffs and tools behave inside a run.

123 124 

124 125 

125 Understand how handoffs and tools behave inside a run.](https://developers.openai.com/api/docs/guides/agents/running-agents)126 [Results and state](https://developers.openai.com/api/docs/guides/agents/results)

126 [Results and state

127 127 

128 128See how `lastAgent` in TypeScript or `last_agent` in Python and resumable state affect the next turn.

129 

130 See how

131 `lastAgent` in TypeScript or `last_agent` in Python

132 and resumable state affect the next turn.](https://developers.openai.com/api/docs/guides/agents/results)

Details

8 8 

9Create a project, install the SDK, and set your API key.9Create a project, install the SDK, and set your API key.

10 10 

11 11[Create an API Key](https://platform.openai.com/api-keys)

12 

13Create an API Key

14 

15 

16 12 

17 13 

18 14 


233 230 

234 231 

235 232 

236 [Agent definitions233 [Agent definitions](https://developers.openai.com/api/docs/guides/agents/define-agents)

237 

238 

239 234 

240 Shape one specialist cleanly before you scale the workflow.](https://developers.openai.com/api/docs/guides/agents/define-agents)235Shape one specialist cleanly before you scale the workflow.

241 [Using tools

242 236 

243 237 

238 [Using tools](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)

244 239 

245 Add hosted tools, function tools, and agents-as-tools.](https://developers.openai.com/api/docs/guides/tools#usage-in-the-agents-sdk)240Add hosted tools, function tools, and agents-as-tools.

246 [Running agents

247 241 

248 242 

243 [Running agents](https://developers.openai.com/api/docs/guides/agents/running-agents)

249 244 

250 Learn the agent loop, streaming, and continuation strategies.](https://developers.openai.com/api/docs/guides/agents/running-agents)245Learn the agent loop, streaming, and continuation strategies.

251 [Orchestration and handoffs

252 246 

253 247 

248 [Orchestration and handoffs](https://developers.openai.com/api/docs/guides/agents/orchestration)

254 249 

255 Decide when specialists should take over the conversation.](https://developers.openai.com/api/docs/guides/agents/orchestration)250Decide when specialists should take over the conversation.

Details

52 52 

53 53 

54 54 

55 [Running agents55 [Running agents](https://developers.openai.com/api/docs/guides/agents/running-agents)

56 56 

57Connect result handling back to the runtime loop and continuation strategy.

57 58 

58 59 

59 Connect result handling back to the runtime loop and continuation60 [Guardrails and human review](https://developers.openai.com/api/docs/guides/agents/guardrails-approvals)

60 strategy.](https://developers.openai.com/api/docs/guides/agents/running-agents)

61 [Guardrails and human review

62 61 

62See how paused runs return interruptions and resumable state.

63 63 

64 64 

65 See how paused runs return interruptions and resumable state.](https://developers.openai.com/api/docs/guides/agents/guardrails-approvals)65 [Integrations and observability](https://developers.openai.com/api/docs/guides/agents/integrations-observability)

66 [Integrations and observability

67 66 

68 67Use traces when you need to inspect the richer workflow record.

69 

70 Use traces when you need to inspect the richer workflow record.](https://developers.openai.com/api/docs/guides/agents/integrations-observability)

Details

229 229 

230 230 

231 231 

232 [Results and state232 [Results and state](https://developers.openai.com/api/docs/guides/agents/results)

233 233 

234Learn which result surfaces your application should carry into the next turn.

234 235 

235 236 

236 Learn which result surfaces your application should carry into the next237 [Orchestration and handoffs](https://developers.openai.com/api/docs/guides/agents/orchestration)

237 turn.](https://developers.openai.com/api/docs/guides/agents/results)

238 [Orchestration and handoffs

239 238 

239Decide how multiple specialists behave inside the same runtime loop.

240 240 

241 241 

242 Decide how multiple specialists behave inside the same runtime loop.](https://developers.openai.com/api/docs/guides/agents/orchestration)242 [Guardrails and human review](https://developers.openai.com/api/docs/guides/agents/guardrails-approvals)

243 [Guardrails and human review

244 243 

245 244Add validation and approval pauses without breaking turn continuity.

246 

247 Add validation and approval pauses without breaking turn continuity.](https://developers.openai.com/api/docs/guides/agents/guardrails-approvals)

Details

14 14 

15 15 

16 16 

17 [TypeScript SDK17 [TypeScript SDK](https://github.com/openai/openai-agents-js)

18 18 

19Open the TypeScript SDK repository on GitHub.

19 20 

20 21 

21 Open the TypeScript SDK repository on GitHub.](https://github.com/openai/openai-agents-js)22 [Python SDK](https://github.com/openai/openai-agents-python)

22 [Python SDK

23 23 

24Open the Python SDK repository on GitHub.

24 25 

25 26 

26 Open the Python SDK repository on GitHub.](https://github.com/openai/openai-agents-python)

27 27 

28 28 

29 29 

guides/chatkit.md +19 −19

Details

275 275 

2763. In your project directory, install the ChatKit React bindings:2763. In your project directory, install the ChatKit React bindings:

277 277 

278```bash278 ```bash

279 npm install @openai/chatkit-react279 npm install @openai/chatkit-react

280```280 ```

281 

281 282 

2824. Add the ChatKit JS script to your page. Drop this snippet into your page’s `<head>` or wherever you load scripts, and the browser will fetch and run ChatKit for you.2834. Add the ChatKit JS script to your page. Drop this snippet into your page’s `<head>` or wherever you load scripts, and the browser will fetch and run ChatKit for you.

283 284 


362 363 

363#### Build your implementation364#### Build your implementation

364 365 

365[ChatKit docs on GitHub366[ChatKit docs on GitHub](https://openai.github.io/chatkit-python)

366 367 

368Learn to handle authentication, add theming and customization, and more.

367 369 

368 370 

369 Learn to handle authentication, add theming and customization, and more.](https://openai.github.io/chatkit-python)371[ChatKit Python SDK](https://github.com/openai/chatkit-python)

370[ChatKit Python SDK

371 372 

373Add server-side storage, access control, tools, and other backend functionality.

372 374 

373 375 

374 Add server-side storage, access control, tools, and other backend

375 functionality.](https://github.com/openai/chatkit-python)

376 376 

377[ChatKit JS SDK377[ChatKit JS SDK](https://github.com/openai/chatkit-js)

378 378 

379Check out the ChatKit JS repo.

379 380 

380 381 

381 Check out the ChatKit JS repo.](https://github.com/openai/chatkit-js)

382 382 

383#### Explore ChatKit UI383#### Explore ChatKit UI

384 384 

385[chatkit.world385[chatkit.world](https://chatkit.world)

386 386 

387Play with an interactive demo of ChatKit.

387 388 

388 389 

389 Play with an interactive demo of ChatKit.](https://chatkit.world)

390 390 

391[Widget builder391[Widget builder](https://widgets.chatkit.studio)

392 392 

393Browse available widgets.

393 394 

394 395 

395 Browse available widgets.](https://widgets.chatkit.studio)

396 396 

397[ChatKit playground397[ChatKit playground](https://chatkit.studio/playground)

398 398 

399Play with an interactive demo to learn by doing.

399 400 

400 401 

401 Play with an interactive demo to learn by doing.](https://chatkit.studio/playground)

402 402 

403#### See working examples403#### See working examples

404 404 

405[Samples on GitHub405[Samples on GitHub](https://github.com/openai/openai-chatkit-advanced-samples)

406 406 

407See working examples of ChatKit and get inspired.

407 408 

408 409 

409 See working examples of ChatKit and get inspired.](https://github.com/openai/openai-chatkit-advanced-samples)

410 410 

411[Starter app repo411[Starter app repo](https://github.com/openai/openai-chatkit-starter-app)

412 412 

413Clone a repo to start with a fully working template.

413 414 

414 415 

415 Clone a repo to start with a fully working template.](https://github.com/openai/openai-chatkit-starter-app)

416 416 

417## Next steps417## Next steps

418 418 

Details

19 19 

20#### Explore ChatKit UI20#### Explore ChatKit UI

21 21 

22[chatkit.world22[chatkit.world](https://chatkit.world)

23 23 

24Play with an interactive demo of ChatKit.

24 25 

25 26 

26 Play with an interactive demo of ChatKit.](https://chatkit.world)

27 27 

28[Widget builder28[Widget builder](https://widgets.chatkit.studio)

29 29 

30Browse available widgets.

30 31 

31 32 

32 Browse available widgets.](https://widgets.chatkit.studio)

33 33 

34[ChatKit playground34[ChatKit playground](https://chatkit.studio/playground)

35 35 

36Play with an interactive demo to learn by doing.

36 37 

37 38 

38 Play with an interactive demo to learn by doing.](https://chatkit.studio/playground)

39 39 

40#### See working examples40#### See working examples

41 41 

42[Samples on GitHub42[Samples on GitHub](https://github.com/openai/openai-chatkit-advanced-samples)

43 43 

44See working examples of ChatKit and get inspired.

44 45 

45 46 

46 See working examples of ChatKit and get inspired.](https://github.com/openai/openai-chatkit-advanced-samples)

47 47 

48[Starter app repo48[Starter app repo](https://github.com/openai/openai-chatkit-starter-app)

49 49 

50Clone a repo to start with a fully working template.

50 51 

51 52 

52 Clone a repo to start with a fully working template.](https://github.com/openai/openai-chatkit-starter-app)

53 53 

54## Change the theme54## Change the theme

55 55 


197 197 

198You can customize the appearance of entity tags on mouseover using widgets. Show rich previews such as a business card, document summary, or image when the user hovers over an entity tag.198You can customize the appearance of entity tags on mouseover using widgets. Show rich previews such as a business card, document summary, or image when the user hovers over an entity tag.

199 199 

200[Widget builder200[Widget builder](https://widgets.chatkit.studio)

201 201 

202Browse available widgets.

202 203 

203 204 

204 Browse available widgets.](https://widgets.chatkit.studio)

205 205 

206```javascript206```javascript

207const options = {207const options = {

Details

9 9 

10Compaction helps you balance quality, cost, and latency as conversations grow.10Compaction helps you balance quality, cost, and latency as conversations grow.

11For guidance on preserving reasoning when changing conversation history, see11For guidance on preserving reasoning when changing conversation history, see

12[Preserved reasoning](https://developers.openai.com/api/docs/guides/preserved-reasoning).12[Keep the prefix unchanged](https://developers.openai.com/api/docs/guides/preserved-reasoning).

13 13 

14## Server-side compaction14## Server-side compaction

15 15 

Details

175 175 

176For stateless reasoning-model requests, preserve every item in the response's `output` array. The Responses API returns encrypted reasoning items by default. Replaying the complete output keeps reasoning items and assistant `phase` values intact. Models that support persisted reasoning can use `reasoning.context: "all_turns"` to render the available reasoning from earlier turns into the next sample. See [preserve reasoning across calls](https://developers.openai.com/api/docs/guides/reasoning#preserve-reasoning-across-calls).176For stateless reasoning-model requests, preserve every item in the response's `output` array. The Responses API returns encrypted reasoning items by default. Replaying the complete output keeps reasoning items and assistant `phase` values intact. Models that support persisted reasoning can use `reasoning.context: "all_turns"` to render the available reasoning from earlier turns into the next sample. See [preserve reasoning across calls](https://developers.openai.com/api/docs/guides/reasoning#preserve-reasoning-across-calls).

177 177 

178When replaying reasoning items, preserve the history that produced them. See [Preserved reasoning](https://developers.openai.com/api/docs/guides/preserved-reasoning) for details on how edits to conversation history affect reasoning.178When replaying reasoning items, preserve the history that produced them. See [Keep the prefix unchanged](https://developers.openai.com/api/docs/guides/preserved-reasoning) for details on how edits to conversation history affect reasoning.

179 179 

180In the following example, we ask the model to tell a joke, followed by a request for another joke. Appending previous responses to new requests in this way helps ensure conversations feel natural and retain the context of previous interactions.180In the following example, we ask the model to tell a joke, followed by a request for another joke. Appending previous responses to new requests in this way helps ensure conversations feel natural and retain the context of previous interactions.

181 181 

Details

1800The JavaScript sample uses `npm install openai@^7.10.0 ws`.1800The JavaScript sample uses `npm install openai@^7.10.0 ws`.

1801The Ruby sample uses `gem install openai async-websocket`.1801The Ruby sample uses `gem install openai async-websocket`.

1802 1802 

1803For Go, run `go get github.com/openai/openai-go/v3@v3.96.0`.1803For Go, run `go get github.com/openai/openai-go/v3@v3.97.0`.

1804For Java, add the Maven dependency `com.openai:openai-java:4.101.0`.1804For Java, add the Maven dependency `com.openai:openai-java:4.101.0`.

1805These Go and Java SDK versions provide native Responses WebSocket support.1805These Go and Java SDK versions provide native Responses WebSocket support.

1806 1806 

Details

273 274 

274Now that you know the basics of DPO, explore these other methods as well.275Now that you know the basics of DPO, explore these other methods as well.

275 276 

276[Supervised fine-tuning277[Supervised fine-tuning](https://developers.openai.com/api/docs/guides/supervised-fine-tuning)

277 

278 

279 278 

280 Fine-tune a model by providing correct outputs for sample inputs.](https://developers.openai.com/api/docs/guides/supervised-fine-tuning)279Fine-tune a model by providing correct outputs for sample inputs.

281 280 

282[Vision fine-tuning

283 281 

284 282 

283[Vision fine-tuning](https://developers.openai.com/api/docs/guides/vision-fine-tuning)

285 284 

286 Learn to fine-tune for computer vision with image inputs.](https://developers.openai.com/api/docs/guides/vision-fine-tuning)285Learn to fine-tune for computer vision with image inputs.

Details

545 545 

546 546 

547 547 

548 [

549Question_answering_using_embeddings.ipynb

550 ](https://developers.openai.com/cookbook/examples/question_answering_using_embeddings)

548 551 

549 552 

550Question_answering_using_embeddings.ipynb553 

551 There are many common cases where the model is not trained on data which contains key facts and information you want to make accessible when generating responses to a user query. One way of solving this, as shown below, is to put additional information into the context window of the model. This is effective in many use cases but leads to higher token costs. In this notebook, we explore the tradeoff between this approach and embeddings bases search.554There are many common cases where the model is not trained on data which contains key facts and information you want to make accessible when generating responses to a user query. One way of solving this, as shown below, is to put additional information into the context window of the model. This is effective in many use cases but leads to higher token costs. In this notebook, we explore the tradeoff between this approach and embeddings bases search.

552 555 

553```javascript556```javascript

554import OpenAI from "openai";557import OpenAI from "openai";


720 723 

721 724 

722 725 

726 [

727Semantic_text_search_using_embeddings.ipynb

728 ](https://developers.openai.com/cookbook/examples/semantic_text_search_using_embeddings)

729 

723 730 

724 731 

725Semantic_text_search_using_embeddings.ipynb732To retrieve the most relevant documents we use the cosine similarity between the embedding vectors of the query and each document, and return the highest scored documents.

726 To retrieve the most relevant documents we use the cosine similarity between the embedding vectors of the query and each document, and return the highest scored documents.

727 733 

728```javascript734```javascript

729import OpenAI from "openai";735import OpenAI from "openai";


977 983 

978 984 

979 985 

986 [

987Code_search.ipynb

988 ](https://developers.openai.com/cookbook/examples/code_search_using_embeddings)

980 989 

981 990 

982Code_search.ipynb991 

983 Code search works similarly to embedding-based text search. We provide a method to extract Python functions from all the Python files in a given repository. Each function is then indexed by the `text-embedding-3-small` model.992Code search works similarly to embedding-based text search. We provide a method to extract Python functions from all the Python files in a given repository. Each function is then indexed by the `text-embedding-3-small` model.

984 993 

985To perform a code search, we embed the query in natural language using the same model. Then we calculate cosine similarity between the resulting query embedding and each of the function embeddings. The highest cosine similarity results are most relevant.994To perform a code search, we embed the query in natural language using the same model. Then we calculate cosine similarity between the resulting query embedding and each of the function embeddings. The highest cosine similarity results are most relevant.

986 995 


1237 1246 

1238 1247 

1239 1248 

1249 [

1250Recommendation_using_embeddings.ipynb

1251 ](https://developers.openai.com/cookbook/examples/recommendation_using_embeddings)

1252 

1240 1253 

1241 1254 

1242Recommendation_using_embeddings.ipynb1255Because shorter distances between embedding vectors represent greater similarity, embeddings can be useful for recommendation.

1243 Because shorter distances between embedding vectors represent greater similarity, embeddings can be useful for recommendation.

1244 1256 

1245Below, we illustrate a basic recommender. It takes in a list of strings and one 'source' string, computes their embeddings, and then returns a ranking of the strings, ranked from most similar to least similar. As a concrete example, the linked notebook below applies a version of this function to the [AG news dataset](http://groups.di.unipi.it/~gulli/AG_corpus_of_news_articles.html) (sampled down to 2,000 news article descriptions) to return the top 5 most similar articles to any given source article.1257Below, we illustrate a basic recommender. It takes in a list of strings and one 'source' string, computes their embeddings, and then returns a ranking of the strings, ranked from most similar to least similar. As a concrete example, the linked notebook below applies a version of this function to the [AG news dataset](http://groups.di.unipi.it/~gulli/AG_corpus_of_news_articles.html) (sampled down to 2,000 news article descriptions) to return the top 5 most similar articles to any given source article.

1246 1258 


1509 1521 

1510 1522 

1511 1523 

1524 [

1525Visualizing_embeddings_in_2D.ipynb

1526 ](https://developers.openai.com/cookbook/examples/visualizing_embeddings_in_2d)

1512 1527 

1513 1528 

1514Visualizing_embeddings_in_2D.ipynb1529 

1515 The size of the embeddings varies with the complexity of the underlying model. In order to visualize this high dimensional data we use the t-SNE algorithm to transform the data into two dimensions.1530The size of the embeddings varies with the complexity of the underlying model. In order to visualize this high dimensional data we use the t-SNE algorithm to transform the data into two dimensions.

1516 1531 

1517We color the individual reviews based on the star rating which the reviewer has given:1532We color the individual reviews based on the star rating which the reviewer has given:

1518 1533 


1564 1579 

1565 1580 

1566 1581 

1582 [

1583Regression_using_embeddings.ipynb

1584 ](https://developers.openai.com/cookbook/examples/regression_using_embeddings)

1585 

1567 1586 

1568 1587 

1569Regression_using_embeddings.ipynb1588An embedding can be used as a general free-text feature encoder within a machine learning model. Incorporating embeddings will improve the performance of any machine learning model, if some of the relevant inputs are free text. An embedding can also be used as a categorical feature encoder within a ML model. This adds most value if the names of categorical variables are meaningful and numerous, such as job titles. Similarity embeddings generally perform better than search embeddings for this task.

1570 An embedding can be used as a general free-text feature encoder within a machine learning model. Incorporating embeddings will improve the performance of any machine learning model, if some of the relevant inputs are free text. An embedding can also be used as a categorical feature encoder within a ML model. This adds most value if the names of categorical variables are meaningful and numerous, such as job titles. Similarity embeddings generally perform better than search embeddings for this task.

1571 1589 

1572We observed that generally the embedding representation is very rich and information dense. For example, reducing the dimensionality of the inputs using SVD or PCA, even by 10%, generally results in worse downstream performance on specific tasks.1590We observed that generally the embedding representation is very rich and information dense. For example, reducing the dimensionality of the inputs using SVD or PCA, even by 10%, generally results in worse downstream performance on specific tasks.

1573 1591 


1609 1627 

1610 1628 

1611 1629 

1630 [

1631Classification_using_embeddings.ipynb

1632 ](https://developers.openai.com/cookbook/examples/classification_using_embeddings)

1612 1633 

1613 1634 

1614Classification_using_embeddings.ipynb1635 

1615 This time, instead of having the algorithm predict a value anywhere between 1 and 5, we will attempt to classify the exact number of stars for a review into 5 buckets, ranging from 1 to 5 stars.1636This time, instead of having the algorithm predict a value anywhere between 1 and 5, we will attempt to classify the exact number of stars for a review into 5 buckets, ranging from 1 to 5 stars.

1616 1637 

1617After the training, the model learns to predict 1 and 5-star reviews much better than the more nuanced reviews (2-4 stars), likely due to more extreme sentiment expression.1638After the training, the model learns to predict 1 and 5-star reviews much better than the more nuanced reviews (2-4 stars), likely due to more extreme sentiment expression.

1618 1639 


1638 1659 

1639 1660 

1640 1661 

1662 [

1663Zero-shot_classification_with_embeddings.ipynb

1664 ](https://developers.openai.com/cookbook/examples/zero-shot_classification_with_embeddings)

1665 

1641 1666 

1642 1667 

1643Zero-shot_classification_with_embeddings.ipynb1668We can use embeddings for zero shot classification without any labeled training data. For each class, we embed the class name or a short description of the class. To classify some new text in a zero-shot manner, we compare its embedding to all class embeddings and predict the class with the highest similarity.

1644 We can use embeddings for zero shot classification without any labeled training data. For each class, we embed the class name or a short description of the class. To classify some new text in a zero-shot manner, we compare its embedding to all class embeddings and predict the class with the highest similarity.

1645 1669 

1646```javascript1670```javascript

1647import OpenAI from "openai";1671import OpenAI from "openai";


1842 1866 

1843 1867 

1844 1868 

1869 [

1870User_and_product_embeddings.ipynb

1871 ](https://developers.openai.com/cookbook/examples/user_and_product_embeddings)

1845 1872 

1846 1873 

1847User_and_product_embeddings.ipynb1874 

1848 We can obtain a user embedding by averaging over all of their reviews. Similarly, we can obtain a product embedding by averaging over all the reviews about that product. In order to showcase the usefulness of this approach we use a subset of 50k reviews to cover more reviews per user and per product.1875We can obtain a user embedding by averaging over all of their reviews. Similarly, we can obtain a product embedding by averaging over all the reviews about that product. In order to showcase the usefulness of this approach we use a subset of 50k reviews to cover more reviews per user and per product.

1849 1876 

1850We evaluate the usefulness of these embeddings on a separate test set, where we plot similarity of the user and product embedding as a function of the rating. Interestingly, based on this approach, even before the user receives the product we can predict better than random whether they would like the product.1877We evaluate the usefulness of these embeddings on a separate test set, where we plot similarity of the user and product embedding as a function of the rating. Interestingly, based on this approach, even before the user receives the product we can predict better than random whether they would like the product.

1851 1878 


1867 1894 

1868 1895 

1869 1896 

1897 [

1898Clustering.ipynb

1899 ](https://developers.openai.com/cookbook/examples/clustering)

1900 

1870 1901 

1871 1902 

1872Clustering.ipynb1903Clustering is one way of making sense of a large volume of textual data. Embeddings are useful for this task, as they provide semantically meaningful vector representations of each text. Thus, in an unsupervised way, clustering will uncover hidden groupings in our dataset.

1873 Clustering is one way of making sense of a large volume of textual data. Embeddings are useful for this task, as they provide semantically meaningful vector representations of each text. Thus, in an unsupervised way, clustering will uncover hidden groupings in our dataset.

1874 1904 

1875In this example, we discover four distinct clusters: one focusing on dog food, one on negative reviews, and two on positive reviews.1905In this example, we discover four distinct clusters: one focusing on dog food, one on negative reviews, and two on positive reviews.

1876 1906 

guides/evals.md +10 −13

Details

970 977 

971Now you know how to create and run evals via API, and using the dashboard! Here are a few other resources that may be useful to you as you continue to improve your model results.978Now you know how to create and run evals via API, and using the dashboard! Here are a few other resources that may be useful to you as you continue to improve your model results.

972 979 

973[Cookbook: Detecting prompt regressions980[Cookbook: Detecting prompt regressions](https://developers.openai.com/cookbook/examples/evaluation/use-cases/regression)

974 

975 

976 981 

977 Keep tabs on the performance of your prompts as you iterate on them.](https://developers.openai.com/cookbook/examples/evaluation/use-cases/regression)982Keep tabs on the performance of your prompts as you iterate on them.

978 983 

979[Cookbook: Bulk model and prompt experimentation

980 984 

981 985 

986[Cookbook: Bulk model and prompt experimentation](https://developers.openai.com/cookbook/examples/evaluation/use-cases/bulk-experimentation)

982 987 

983 Compare the results of many different prompts and models at once.](https://developers.openai.com/cookbook/examples/evaluation/use-cases/bulk-experimentation)988Compare the results of many different prompts and models at once.

984 989 

985[Cookbook: Monitoring stored completions

986 990 

987 991 

992[Cookbook: Monitoring stored completions](https://developers.openai.com/cookbook/examples/evaluation/use-cases/completion-monitoring)

988 993 

989 Examine stored completions to test for prompt regressions.](https://developers.openai.com/cookbook/examples/evaluation/use-cases/completion-monitoring)994Examine stored completions to test for prompt regressions.

990 995 

991[Fine-tuning

992 996 

993 997 

998[Fine-tuning](https://developers.openai.com/api/docs/guides/model-optimization)

994 999 

995 Improve a model's ability to generate responses tailored to your use case.](https://developers.openai.com/api/docs/guides/model-optimization)1000Improve a model's ability to generate responses tailored to your use case.

996[Model distillation

997 1001 

998 1002 

1003[Model distillation](https://developers.openai.com/api/docs/guides/supervised-fine-tuning#distilling-from-a-larger-model)

999 1004 

1000 Learn how to distill large model results to smaller, cheaper, and faster1005Learn how to distill large model results to smaller, cheaper, and faster models.

1001 models.](https://developers.openai.com/api/docs/guides/supervised-fine-tuning#distilling-from-a-larger-model)

Details

154 154 

155For more inspiration, visit the [OpenAI Cookbook](https://developers.openai.com/cookbook/topic/evals), which contains example code and links to third-party resources, or learn more about our evaluation tools:155For more inspiration, visit the [OpenAI Cookbook](https://developers.openai.com/cookbook/topic/evals), which contains example code and links to third-party resources, or learn more about our evaluation tools:

156 156 

157[Cookbook: Building resilient prompts with evals157[Cookbook: Building resilient prompts with evals](https://developers.openai.com/cookbook/examples/evaluation/building_resilient_prompts_using_an_evaluation_flywheel)

158 158 

159Operate a flywheel of continuous improvement using evaluations.

159 160 

160 161 

161 Operate a flywheel of continuous improvement using evaluations.](https://developers.openai.com/cookbook/examples/evaluation/building_resilient_prompts_using_an_evaluation_flywheel)

162 162 

163[Working with evals163[Working with evals](https://developers.openai.com/api/docs/guides/evals)

164 164 

165Evaluate against external models, interact with evals via API, and more.

165 166 

166 167 

167 Evaluate against external models, interact with evals via API, and more.](https://developers.openai.com/api/docs/guides/evals)

168 168 

169[Prompt optimizer169[Prompt optimizer](https://developers.openai.com/api/docs/guides/prompt-optimizer)

170 170 

171Use your dataset to automatically improve your prompts.

171 172 

172 173 

173 Use your dataset to automatically improve your prompts.](https://developers.openai.com/api/docs/guides/prompt-optimizer)

174 174 

175[Graders175[Graders](https://developers.openai.com/api/docs/guides/graders)

176 176 

177 177Build sophisticated graders to improve the effectiveness of your evals.

178 

179 Build sophisticated graders to improve the effectiveness of your evals.](https://developers.openai.com/api/docs/guides/graders)

Details

70 70 

71For more inspiration, visit the [OpenAI Cookbook](https://developers.openai.com/cookbook), which contains example code and links to third-party resources, or learn more about our tools for evals:71For more inspiration, visit the [OpenAI Cookbook](https://developers.openai.com/cookbook), which contains example code and links to third-party resources, or learn more about our tools for evals:

72 72 

73[Getting started with evals73[Getting started with evals](https://developers.openai.com/api/docs/guides/evaluation-getting-started)

74 74 

75Uses Datasets to quickly build evals and iterate on prompts.

75 76 

76 77 

77 Uses Datasets to quickly build evals and iterate on prompts.](https://developers.openai.com/api/docs/guides/evaluation-getting-started)

78 78 

79[Working with evals79[Working with evals](https://developers.openai.com/api/docs/guides/evals)

80 80 

81 81Evaluate against external models, interact with evals via API, and more.

82 

83 Evaluate against external models, interact with evals via API, and more.](https://developers.openai.com/api/docs/guides/evals)

Details

864 865 

865 866 

866 867 

867 [Experiment with file inputs in the Playground868 [Experiment with file inputs in the Playground](https://platform.openai.com/chat/edit)

868 

869 

870 869 

871 Use the Playground to develop and iterate on prompts with file inputs.](https://platform.openai.com/chat/edit)870Use the Playground to develop and iterate on prompts with file inputs.

872 871 

873 872 

874 873 

875 874 

876 875 

877 [Full API reference

878 876 

879 877 

878 [Full API reference](https://developers.openai.com/api/reference/resources/responses)

880 879 

881 Check out the API reference for more options.](https://developers.openai.com/api/reference/resources/responses)880Check out the API reference for more options.

882 881 

883 882 

884 883 

885 884 

886 885 

887 [Use File Search for large corpora

888 886 

889 887 

888 [Use File Search for large corpora](https://developers.openai.com/api/docs/guides/tools-file-search)

890 889 

891 Use retrieval over chunked files when you need scalable search instead of890Use retrieval over chunked files when you need scalable search instead of sending whole files in a single context window.

892 sending whole files in a single context window.](https://developers.openai.com/api/docs/guides/tools-file-search)

893 891 

894 892 

895 893 

896 894 

897 895 

898 [Use Hosted Shell for deep spreadsheet analysis

899 896 

900 897 

898 [Use Hosted Shell for deep spreadsheet analysis](https://developers.openai.com/api/docs/guides/tools-shell#hosted-shell-quickstart)

901 899 

902 Use Hosted Shell for advanced spreadsheet workflows such as joins,900Use Hosted Shell for advanced spreadsheet workflows such as joins, aggregations, and charting.

903 aggregations, and charting.](https://developers.openai.com/api/docs/guides/tools-shell#hosted-shell-quickstart)

Details

211 212 

212Before uploading your data, you may want to check formatting and potential token costs - an example of how to do this can be found in the cookbook.213Before uploading your data, you may want to check formatting and potential token costs - an example of how to do this can be found in the cookbook.

213 214 

214[Fine-tuning data format validation215[Fine-tuning data format validation](https://developers.openai.com/cookbook/examples/chat_finetuning_data_prep)

215 

216 

217 216 

218 Learn about fine-tuning data formatting](https://developers.openai.com/cookbook/examples/chat_finetuning_data_prep)217Learn about fine-tuning data formatting

Details

474Note that for reasoning models like GPT-5 or o4-mini, any reasoning items474Note that for reasoning models like GPT-5 or o4-mini, any reasoning items

475 returned in model responses with tool calls must also be passed back with tool475 returned in model responses with tool calls must also be passed back with tool

476 call outputs. For guidance on preserving the history that produced those476 call outputs. For guidance on preserving the history that produced those

477 items, see [Preserved reasoning](https://developers.openai.com/api/docs/guides/preserved-reasoning).477 items, see [Best practices for prefix

478 changes](https://developers.openai.com/api/docs/guides/preserved-reasoning).

478 479 

479## Defining functions480## Defining functions

480 481 

Details

410 410 

411- Your uploaded code must be less than `256kB` and will not have network access.411- Your uploaded code must be less than `256kB` and will not have network access.

412- The grading execution itself is limited to 2 minutes.412- The grading execution itself is limited to 2 minutes.

413- At runtime you will be given a limit of 2Gb of memory and 1Gb of disk space to use.413- At runtime you will be given a limit of 2GB of memory and 1GB of disk space to use.

414- There's a limit of 2 CPU cores—any usage above this amount will result in throttling414- There's a limit of 2 CPU cores—any usage above this amount will result in throttling

415 415 

416The following third-party packages are available at execution time for the image tag `2025-05-08`416The following third-party packages are available at execution time for the image tag `2025-05-08`

Details

35 35 

36Run your evals against test inputs like you expect to see in production. Using one of several available [graders](https://developers.openai.com/api/docs/guides/graders), measure the results of a prompt against your test data set.36Run your evals against test inputs like you expect to see in production. Using one of several available [graders](https://developers.openai.com/api/docs/guides/graders), measure the results of a prompt against your test data set.

37 37 

38[Learn about evals38[Learn about evals](https://developers.openai.com/api/docs/guides/evals)

39 39 

40Run tests on your model outputs to ensure you're getting the right results.

40 41 

41 42 

42 Run tests on your model outputs to ensure you're getting the right results.](https://developers.openai.com/api/docs/guides/evals)

43 43 

44## Write effective prompts44## Write effective prompts

45 45 


49- **Provide clear instructions** - your prompt should contain clear goals about what kind of output you want. Start with [`gpt-6-astra`](https://developers.openai.com/api/docs/models/gpt-6-astra) for new work, and use [reasoning model guidance](https://developers.openai.com/api/docs/guides/reasoning) to tune outcome-level instructions, reasoning effort, and verbosity.49- **Provide clear instructions** - your prompt should contain clear goals about what kind of output you want. Start with [`gpt-6-astra`](https://developers.openai.com/api/docs/models/gpt-6-astra) for new work, and use [reasoning model guidance](https://developers.openai.com/api/docs/guides/reasoning) to tune outcome-level instructions, reasoning effort, and verbosity.

50- **Provide example outputs** - give the model a few examples of correct output for a given prompt (a process called few-shot learning). The model can extrapolate from these examples how it should respond for other prompts.50- **Provide example outputs** - give the model a few examples of correct output for a given prompt (a process called few-shot learning). The model can extrapolate from these examples how it should respond for other prompts.

51 51 

52[Learn about prompt engineering52[Learn about prompt engineering](https://developers.openai.com/api/docs/guides/text)

53 53 

54Learn the basics of writing good prompts for the model.

54 55 

55 56 

56 Learn the basics of writing good prompts for the model.](https://developers.openai.com/api/docs/guides/text)

57 57 

58## Fine-tune a model58## Fine-tune a model

59 59 

Details

1# Preserved reasoning1# Keep the prefix unchanged

2 2 

3> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.3> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

4 4 

5When you continue a conversation with the Responses API, a model can reuse5In agentic and multi-turn applications, our models work best when [thinking is preserved](https://developers.openai.com/api/docs/guides/reasoning?api-mode=responses#preserve-reasoning-across-calls) across API requests, where new actions and instructions are always appended to the model’s context. Keeping the prefix intact has long been a best practice for [prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching). The cache matches requests from the beginning, so a change to the prefix can cut cache reuse from that point onward. Appending changes keeps more of the conversation eligible for cache reuse, which can substantially **lower input costs and speed up responses**.

6reasoning items from an earlier response. To preserve that reasoning when you

7manage conversation history, keep the history that produced it intact and append

8new messages and tool results at the end. The selected model and

9[`reasoning.context` setting](https://developers.openai.com/api/docs/guides/reasoning#preserve-reasoning-across-calls)

10determine which available reasoning items the model can use.

11 6 

12## How history changes affect reasoning7Starting with newer frontier models, the API **will drop reasoning items** that follow a prefix change as part of our anti-distillation safeguards. When reasoning items are dropped, the model may have to redo some reasoning, which can increase token usage, cost, and latency. If the model can't recover the lost reasoning, output quality may also drop.

13 8 

14For newer frontier models, the API checks the conversation history before each9To get the best performance from our models, we recommend avoiding changes to the prefix and adopting an append-only integration pattern as far as possible.

15reasoning item you send back. This history is the item's _prefix_. If you edit,

16shorten, or insert a message in that prefix, the API drops the affected

17reasoning. The request can continue with the conversation you provide, and the

18model can generate new reasoning.

19 10 

20For example, an agent calls a ledger tool and uses the returned rows to11## What is a prefix change?

21investigate a discrepancy. On the next request, your app replaces those rows

22with a subtotal. The model can still reuse reasoning it used to choose the tool,

23but the API drops reasoning that depended on the original rows, even if you send the

24reasoning item back unchanged.

25 12 

26## Append new instructions13A reasoning item’s prefix is the conversation history that comes before it. A prefix change modifies that earlier history—for example, by shortening a tool result, rewriting a developer message, or replacing older turns with a summary.

27 14 

28When you manage history yourself, keep the previous input and the response's15## How to update integrations to avoid prefix changes

29output items in their original order. Add new instructions at the point where

30they take effect.

31 16 

32This example uses the Python SDK in stateless mode with a model that supports17You can change the prefix unintentionally by updating Responses API parameters such as `tools`, `instructions`, or `text.format`, or by editing earlier `input` items. Audit your integration for these changes.

33`reasoning.context` set to `all_turns`. Stateless responses

34include encrypted reasoning content by default. See

35[Preserve reasoning without stored responses](https://developers.openai.com/api/docs/guides/reasoning#preserve-reasoning-without-stored-responses).

36 18 

37Append instructions to a conversation19The table below shows common ways integrations change the prefix and how to achieve the same goals by appending to the context where possible.

38 20 

39```python21| Common reason to change prefix | How to avoid prefix change |

40from openai import OpenAI22| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

23| Changing reasoning effort | Instead of changing the `reasoning.effort` parameter in the Responses API, append a [`configuration_update` item](https://developers.openai.com/api/docs/guides/reasoning#change-reasoning-mid-conversation) with the new reasoning effort to the input items list. Keep the original request-level setting the same. |

24| Changing structured output schemas | Instead of changing the `text.format` parameter in the Responses API, append a [`configuration_update` item](https://developers.openai.com/api/docs/guides/structured-outputs#change-the-response-format-mid-conversation) with the new schema to the input items list. Keep the original request-level setting the same. |

25| Changing the tools available to the agent | Instead of changing the `tools` parameter in the Responses API, use an [`additional_tools` item](https://developers.openai.com/api/docs/guides/prompt-caching#manage-tools-with-append-only-updates) to add tools, or `tool_choice` with `allowed_tools` to restrict which tools the model can call on a turn. Keep existing tool definitions in order. Append `additional_tools` with the `developer` role and a `tools` array, and replay it in its original position. |

26| Updating developer instructions | Instead of editing the original developer message, append a new `developer` message asking the model to ignore older instructions and follow the new ones you provide. For instructions scoped to a single turn, place an [explicit cache breakpoint](https://developers.openai.com/api/docs/guides/prompt-caching#how-prefix-matching-works) immediately before the latest developer message so the reusable prefix ends before that message. |

27| Compaction | Compaction changes the prefix, so cache misses are difficult to avoid in these cases.<br /><br />**OpenAI compaction:** If you use [OpenAI compaction](https://developers.openai.com/api/docs/guides/compaction) via `/responses/compact` or `context_management`, our systems retain subsequent reasoning items despite the prefix being changed. An OpenAI compaction item can appear anywhere in context. When calling `/responses/compact`, omit `instructions` and pass the returned window to the next request in its original order. If your history contains `configuration_update` items, follow the [configuration-update compaction requirements](https://developers.openai.com/api/docs/guides/reasoning#change-reasoning-mid-conversation).<br /><br />**Custom compaction:** If you use a different or home-grown compaction strategy, place the compacted item at the end of the model’s context, instead of before recent turns. Alternatively, you can accept the trade-off and have the reasoning items from the original history that follow it dropped. |

28| Shortening past tool outputs or downsizing past files / images | Some integrations truncate past items, such as tool outputs, files, or images, instead of using compaction. These modifications change the prefix. We strongly recommend either using compaction, or shortening long tool outputs and downsizing images or files before they’re sent to the model for the first time. |

41 29 

42client = OpenAI()30## Auditing your integration for prefix changes

43model = "gpt-6.1-sol"

44history = [{"role": "user", "content": "Compare invoice A ($80) and B ($95)."}]

45 31 

46first = client.responses.create(32Use [Prompt Cache Diagnostics](https://developers.openai.com/api/docs/guides/prompt-caching/diagnostics) to see when cache misses occur and investigate prefix changes. Compare a request with an earlier response by setting `prompt_cache_options.comparison_response_id` to the earlier response ID, then inspect the diagnostic reason and cached token count. Use this information to reduce prefix changes in your integration. Diagnostics report the first identified difference on a best-effort basis; they can’t verify whether the model reused reasoning.

47 model=model,

48 reasoning={"context": "all_turns"},

49 input=history,

50 store=False,

51)

52 

53next_input = [

54 *history,

55 *(item.to_dict() for item in first.output),

56 {

57 "role": "developer",

58 "content": "For the reconciliation report, use a Markdown table.",

59 },

60 {"role": "user", "content": "Add invoice C ($110) and show the total."},

61]

62report = client.responses.create(

63 model=model,

64 reasoning={"context": "all_turns"},

65 input=next_input,

66 store=False,

67)

68print(report.output_text)

69```

70 

71 

72If you use stored responses, you can continue from the prior response with

73`previous_response_id` and send only the new input items. See

74[Conversation state](https://developers.openai.com/api/docs/guides/conversation-state).

75 

76## Migrate away from prefix edits

77 

78Compare two consecutive requests in a workflow that reuses reasoning. Find the

79first place your app changes an item it already sent, then choose the migration

80that matches the edit.

81 

82| If your app edits… | Migrate to… |

83| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

84| Older turns during compaction | Use OpenAI compaction and continue from the returned context. If you create a portable text summary, let the model reason from it. Replacing the prefix can invalidate reasoning you replay after the summary. If the history includes `configuration_update` items, use an explicit `compaction_trigger`, then append a fresh update before the next user message. Restate every setting you changed, including the format if applicable. Automatic compaction, automatic truncation, and standalone `/responses/compact` don't support histories containing these updates. |

85| Developer instructions | Append a developer message when the instruction takes effect. If the response is already running, use mid-turn steering where supported. |

86| The tool list when switching modes | Keep known tool definitions stable. Restrict the next request with `tool_choice` of type `allowed_tools`. To introduce new tools, append an `additional_tools` input item with role `developer` and the definitions in `tools`. Replay it in its original position. |

87| A tool result the model has already seen | Filter the result before sending `function_call_output` the first time. If the data changes, append a correction or return it from a new tool call. |

88 

89For more on managing long conversations, see

90[Compaction](https://developers.openai.com/api/docs/guides/compaction).

Details

2 2 

3> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.3> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

4 4 

5li+li]:mt-2! [&_ul>li>p]:my-0! [&_#built-with-three-principles+ol>li+li]:mt-2! [&_#check-storage-status]:mt-0!">

6 

7Zero Data Retention with Private Safety Processing (ZDR with PSP) enables offline, automated safety review without OpenAI retaining customer prompts or responses. This guide provides an overview of how ZDR with PSP works and your operating responsibilities. For the full architecture and security model, see the [Private Safety Processing technical white paper](https://openaiassets.blob.core.windows.net/$web/pdf/c7284810-2252-462f-803e-075b0c95bccb/psp-whitepaper.pdf).5Zero Data Retention with Private Safety Processing (ZDR with PSP) enables offline, automated safety review without OpenAI retaining customer prompts or responses. This guide provides an overview of how ZDR with PSP works and your operating responsibilities. For the full architecture and security model, see the [Private Safety Processing technical white paper](https://openaiassets.blob.core.windows.net/$web/pdf/c7284810-2252-462f-803e-075b0c95bccb/psp-whitepaper.pdf).

8 6 

9<figure>7<figure>

Details

829 831 

830GPT models like [`gpt-6-astra`](https://developers.openai.com/api/docs/models/gpt-6-astra) benefit from precise instructions that explicitly provide the logic and data required to complete the task in the prompt. To get the most out of the latest model, start with the current prompting guide.832GPT models like [`gpt-6-astra`](https://developers.openai.com/api/docs/models/gpt-6-astra) benefit from precise instructions that explicitly provide the logic and data required to complete the task in the prompt. To get the most out of the latest model, start with the current prompting guide.

831 833 

832[834[](https://developers.openai.com/api/docs/guides/latest-model)

835 

836Get the most out of prompting the latest model with current guidance, practical examples, and migration notes.

837 

833 838 

834 Get the most out of prompting the latest model with current guidance,

835 practical examples, and migration notes.](https://developers.openai.com/api/docs/guides/latest-model)

836 839 

837 840 

838 841 


975 981 

976Now that you know the basics of text inputs and outputs, you might want to check out one of these resources next.982Now that you know the basics of text inputs and outputs, you might want to check out one of these resources next.

977 983 

978[Build a prompt in the Playground984[Build a prompt in the Playground](https://platform.openai.com/chat/edit)

979 985 

986Use the Playground to develop and iterate on prompts.

980 987 

981 988 

982 Use the Playground to develop and iterate on prompts.](https://platform.openai.com/chat/edit)

983 989 

984[Generate JSON data with Structured Outputs990[Generate JSON data with Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs)

985 991 

992Ensure JSON data emitted from a model conforms to a JSON schema.

986 993 

987 994 

988 Ensure JSON data emitted from a model conforms to a JSON schema.](https://developers.openai.com/api/docs/guides/structured-outputs)

989 995 

990[Full API reference996[Full API reference](https://developers.openai.com/api/reference/resources/responses)

991 997 

998Check out all the options for text generation in the API reference.

992 999 

993 1000 

994 Check out all the options for text generation in the API reference.](https://developers.openai.com/api/reference/resources/responses)

995 1001 

996## Other resources1002## Other resources

997 1003 

Details

42 42 

43For more inspiration, visit the [OpenAI Cookbook](https://developers.openai.com/cookbook), which contains example code and links to third-party resources, or learn more about our tools for evals:43For more inspiration, visit the [OpenAI Cookbook](https://developers.openai.com/cookbook), which contains example code and links to third-party resources, or learn more about our tools for evals:

44 44 

45[Cookbook: Building resilient prompts with evals45[Cookbook: Building resilient prompts with evals](https://developers.openai.com/cookbook/examples/evaluation/building_resilient_prompts_using_an_evaluation_flywheel)

46 46 

47Operate a flywheel of continuous improvement using evaluations.

47 48 

48 49 

49 Operate a flywheel of continuous improvement using evaluations.](https://developers.openai.com/cookbook/examples/evaluation/building_resilient_prompts_using_an_evaluation_flywheel)

50 50 

51[Working with evals51[Working with evals](https://developers.openai.com/api/docs/guides/evals)

52 52 

53Evaluate against external models, interact with evals via API, and more.

53 54 

54 55 

55 Evaluate against external models, interact with evals via API, and more.](https://developers.openai.com/api/docs/guides/evals)

56 56 

57[Graders57[Graders](https://developers.openai.com/api/docs/guides/graders)

58 58 

59Build sophisticated graders to improve the effectiveness of your evals.

59 60 

60 61 

61 Build sophisticated graders to improve the effectiveness of your evals.](https://developers.openai.com/api/docs/guides/graders)

62 62 

63[Fine-tuning63[Fine-tuning](https://developers.openai.com/api/docs/guides/model-optimization)

64 64 

65 65Improve a model's ability to generate responses tailored to your use case.

66 

67 Improve a model's ability to generate responses tailored to your use case.](https://developers.openai.com/api/docs/guides/model-optimization)

Details

44 44 

45When you feel confident in your prompts, you might want to check out the following guides and resources.45When you feel confident in your prompts, you might want to check out the following guides and resources.

46 46 

47[Text generation47[Text generation](https://developers.openai.com/api/docs/guides/text)

48 48 

49Learn how to prompt a model to generate text.

49 50 

50 51 

51 Learn how to prompt a model to generate text.](https://developers.openai.com/api/docs/guides/text)

52 52 

53[Engineer better prompts53[Engineer better prompts](https://developers.openai.com/api/docs/guides/prompt-engineering)

54 54 

55 55Learn about OpenAI's prompt engineering tools and techniques.

56 

57 Learn about OpenAI's prompt engineering tools and techniques.](https://developers.openai.com/api/docs/guides/prompt-engineering)

Details

276 279 

277## Related guides280## Related guides

278 281 

279[Realtime and audio overview282[Realtime and audio overview](https://developers.openai.com/api/docs/guides/realtime)

280 

281 

282 283 

283 Compare voice-agent, translation, and transcription sessions.](https://developers.openai.com/api/docs/guides/realtime)284Compare voice-agent, translation, and transcription sessions.

284 285 

285[Realtime translation

286 286 

287 287 

288[Realtime translation](https://developers.openai.com/api/docs/guides/realtime-translation)

288 289 

289 Translate live speech with a dedicated translation session.](https://developers.openai.com/api/docs/guides/realtime-translation)290Translate live speech with a dedicated translation session.

290 291 

291[WebSocket connection

292 292 

293 293 

294[WebSocket connection](https://developers.openai.com/api/docs/guides/voice-websockets?api=realtime)

294 295 

295 Stream raw audio through a server-side media pipeline.](https://developers.openai.com/api/docs/guides/voice-websockets?api=realtime)296Stream raw audio through a server-side media pipeline.

296 297 

297[Voice activity detection

298 298 

299 299 

300[Voice activity detection](https://developers.openai.com/api/docs/guides/realtime-vad)

300 301 

301 Configure turn detection for live audio streams.](https://developers.openai.com/api/docs/guides/realtime-vad)302Configure turn detection for live audio streams.

Details

717 720 

718## Related guides721## Related guides

719 722 

720[Realtime and audio overview723[Realtime and audio overview](https://developers.openai.com/api/docs/guides/realtime)

721 

722 

723 724 

724 Compare voice-agent, translation, and transcription sessions.](https://developers.openai.com/api/docs/guides/realtime)725Compare voice-agent, translation, and transcription sessions.

725 726 

726[WebRTC connection

727 727 

728 728 

729[WebRTC connection](https://developers.openai.com/api/docs/guides/voice-webrtc?api=realtime)

729 730 

730 Connect browser media to a realtime session.](https://developers.openai.com/api/docs/guides/voice-webrtc?api=realtime)731Connect browser media to a realtime session.

731 732 

732[WebSocket connection

733 733 

734 734 

735[WebSocket connection](https://developers.openai.com/api/docs/guides/voice-websockets?api=realtime)

735 736 

736 Stream raw audio through a server-side media pipeline.](https://developers.openai.com/api/docs/guides/voice-websockets?api=realtime)737Stream raw audio through a server-side media pipeline.

737 738 

738[Realtime transcription

739 739 

740 740 

741[Realtime transcription](https://developers.openai.com/api/docs/guides/realtime-transcription)

741 742 

742 Stream transcript deltas from live audio.](https://developers.openai.com/api/docs/guides/realtime-transcription)743Stream transcript deltas from live audio.

Details

944 945 

945You can carry reasoning items forward using `previous_response_id`. If you manage conversation history yourself, include the original input and all [output](https://developers.openai.com/api/reference/resources/responses#responses/object-output) items from each response in the [input](https://developers.openai.com/api/reference/resources/responses/methods/create#responses-create-input) of the next request. Keep those items in their original order and append new items.946You can carry reasoning items forward using `previous_response_id`. If you manage conversation history yourself, include the original input and all [output](https://developers.openai.com/api/reference/resources/responses#responses/object-output) items from each response in the [input](https://developers.openai.com/api/reference/resources/responses/methods/create#responses-create-input) of the next request. Keep those items in their original order and append new items.

946 947 

947For newer frontier models, changes to the history preceding a reasoning item can cause the API to drop that reasoning. See [Preserved reasoning](https://developers.openai.com/api/docs/guides/preserved-reasoning) for guidance on changing instructions and tool outputs, and managing long conversations.948For newer frontier models, changes to the history preceding a reasoning item can cause the API to drop that reasoning. See [Keep the prefix unchanged](https://developers.openai.com/api/docs/guides/preserved-reasoning) for guidance on changing instructions and tool outputs, and managing long conversations.

948 949 

949## Change reasoning mid-conversation950## Change reasoning mid-conversation

950 951 


2106 2127 

2107Some examples of using reasoning models for real-world use cases can be found in [the cookbook](https://developers.openai.com/cookbook).2128Some examples of using reasoning models for real-world use cases can be found in [the cookbook](https://developers.openai.com/cookbook).

2108 2129 

2109[Using reasoning for data validation2130[Using reasoning for data validation](https://developers.openai.com/cookbook/examples/o1/using_reasoning_for_data_validation)

2110 

2111 

2112 2131 

2113 Evaluate a synthetic medical data set for discrepancies.](https://developers.openai.com/cookbook/examples/o1/using_reasoning_for_data_validation)2132Evaluate a synthetic medical data set for discrepancies.

2114 2133 

2115[Using reasoning for routine generation

2116 2134 

2117 2135 

2136[Using reasoning for routine generation](https://developers.openai.com/cookbook/examples/o1/using_reasoning_for_routine_generation)

2118 2137 

2119 Use help center articles to generate actions that an agent could perform.](https://developers.openai.com/cookbook/examples/o1/using_reasoning_for_routine_generation)2138Use help center articles to generate actions that an agent could perform.

Details

587 598 

588Now that you know the basics of supervised fine-tuning, explore these other methods as well.599Now that you know the basics of supervised fine-tuning, explore these other methods as well.

589 600 

590[Vision fine-tuning601[Vision fine-tuning](https://developers.openai.com/api/docs/guides/vision-fine-tuning)

591 

592 

593 602 

594 Learn to fine-tune for computer vision with image inputs.](https://developers.openai.com/api/docs/guides/vision-fine-tuning)603Learn to fine-tune for computer vision with image inputs.

595 604 

596[Direct preference optimization

597 605 

598 606 

607[Direct preference optimization](https://developers.openai.com/api/docs/guides/direct-preference-optimization)

599 608 

600 Fine-tune a model using direct preference optimization (DPO).](https://developers.openai.com/api/docs/guides/direct-preference-optimization)609Fine-tune a model using direct preference optimization (DPO).

guides/text.md +6 −8

Details

573 574 

574Now that you know the basics of text inputs and outputs, you might want to check out one of these resources next.575Now that you know the basics of text inputs and outputs, you might want to check out one of these resources next.

575 576 

576[Build a prompt in the Playground577[Build a prompt in the Playground](https://platform.openai.com/chat/edit)

577 

578 

579 578 

580 Use the Playground to develop and iterate on prompts.](https://platform.openai.com/chat/edit)579Use the Playground to develop and iterate on prompts.

581 580 

582[Generate JSON data with Structured Outputs

583 581 

584 582 

583[Generate JSON data with Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs)

585 584 

586 Ensure JSON data emitted from a model conforms to a JSON schema.](https://developers.openai.com/api/docs/guides/structured-outputs)585Ensure JSON data emitted from a model conforms to a JSON schema.

587 586 

588[Full API reference

589 587 

590 588 

589[Full API reference](https://developers.openai.com/api/reference/resources/responses)

591 590 

592 Check out all the options for text generation in the API reference.](https://developers.openai.com/api/reference/resources/responses)591Check out all the options for text generation in the API reference.

Details

421 421 

422## Related guides422## Related guides

423 423 

424[Realtime and audio overview424[Realtime and audio overview](https://developers.openai.com/api/docs/guides/realtime)

425 425 

426Choose the right path for voice agents, translation, transcription, and speech generation.

426 427 

427 428 

428 Choose the right path for voice agents, translation, transcription, and

429 speech generation.](https://developers.openai.com/api/docs/guides/realtime)

430 429 

431[Audio and speech concepts430[Audio and speech concepts](https://developers.openai.com/api/docs/guides/audio)

432 431 

433 432Review audio modalities, speech tasks, streaming, and request-based APIs.

434 

435 Review audio modalities, speech tasks, streaming, and request-based APIs.](https://developers.openai.com/api/docs/guides/audio)

guides/tools.md +20 −25

Details

1002 1002 

1003Here's an overview of the tools available in the OpenAI platform—select one of them for further guidance on usage.1003Here's an overview of the tools available in the OpenAI platform—select one of them for further guidance on usage.

1004 1004 

1005[Function calling1005[Function calling](https://developers.openai.com/api/docs/guides/function-calling)

1006 1006 

1007Call custom code to give the model access to additional data and capabilities.

1007 1008 

1008 1009 

1009 Call custom code to give the model access to additional data and

1010 capabilities.](https://developers.openai.com/api/docs/guides/function-calling)

1011 1010 

1012[Web search1011[Web search](https://developers.openai.com/api/docs/guides/tools-web-search)

1013 1012 

1013Include data from the Internet in model response generation.

1014 1014 

1015 1015 

1016 Include data from the Internet in model response generation.](https://developers.openai.com/api/docs/guides/tools-web-search)

1017 1016 

1018[Remote MCP servers1017[Remote MCP servers](https://developers.openai.com/api/docs/guides/tools-connectors-mcp)

1019 1018 

1019Give the model access to new capabilities via Model Context Protocol (MCP) servers.

1020 1020 

1021 1021 

1022 Give the model access to new capabilities via Model Context Protocol (MCP)

1023 servers.](https://developers.openai.com/api/docs/guides/tools-connectors-mcp)

1024 1022 

1025[Skills1023[Skills](https://developers.openai.com/api/docs/guides/tools-skills)

1026 1024 

1025Upload and reuse versioned skill bundles in hosted shell environments.

1027 1026 

1028 1027 

1029 Upload and reuse versioned skill bundles in hosted shell environments.](https://developers.openai.com/api/docs/guides/tools-skills)

1030 1028 

1031[Shell1029[Shell](https://developers.openai.com/api/docs/guides/tools-shell)

1032 1030 

1031Run shell commands in hosted containers or in your own local runtime.

1033 1032 

1034 1033 

1035 Run shell commands in hosted containers or in your own local runtime.](https://developers.openai.com/api/docs/guides/tools-shell)

1036 1034 

1037[Computer use1035[Computer use](https://developers.openai.com/api/docs/guides/tools-computer-use)

1038 1036 

1037Create agentic workflows that enable a model to control a computer interface.

1039 1038 

1040 1039 

1041 Create agentic workflows that enable a model to control a computer

1042 interface.](https://developers.openai.com/api/docs/guides/tools-computer-use)

1043 1040 

1044[Image generation1041[Image generation](https://developers.openai.com/api/docs/guides/tools-image-generation)

1045 1042 

1043Generate or edit images using GPT Image.

1046 1044 

1047 1045 

1048 Generate or edit images using GPT Image.](https://developers.openai.com/api/docs/guides/tools-image-generation)

1049 1046 

1050[File search1047[File search](https://developers.openai.com/api/docs/guides/tools-file-search)

1051 1048 

1049Search the contents of uploaded files for context when generating a response.

1052 1050 

1053 1051 

1054 Search the contents of uploaded files for context when generating a

1055 response.](https://developers.openai.com/api/docs/guides/tools-file-search)

1056 1052 

1057[Tool search1053[Tool search](https://developers.openai.com/api/docs/guides/tools-tool-search)

1058 1054 

1055Dynamically load relevant tools into the model’s context to optimize token usage.

1059 1056 

1060 1057 

1061 Dynamically load relevant tools into the model’s context to optimize token

1062 usage.](https://developers.openai.com/api/docs/guides/tools-tool-search)

1063 1058 

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

1065 1060 

1061Let models compose and run JavaScript that orchestrates tool calls.

1066 1062 

1067 1063 

1068 Let models compose and run JavaScript that orchestrates tool calls.](https://developers.openai.com/api/docs/guides/tools-programmatic-tool-calling)

1069 1064 

1070## Usage in the API1065## Usage in the API

1071 1066 

Details

588 588 

589You can find full working examples on GitHub.589You can find full working examples on GitHub.

590 590 

591[Apply patch tool example - TypeScript591[Apply patch tool example - TypeScript](https://github.com/openai/openai-agents-js/blob/main/examples/tools/applyPatch.ts)

592 592 

593Example of how to use the apply patch tool with the Agents SDK in TypeScript

593 594 

594 595 

595 Example of how to use the apply patch tool with the Agents SDK in TypeScript](https://github.com/openai/openai-agents-js/blob/main/examples/tools/applyPatch.ts)

596 596 

597[Apply patch tool example - Python597[Apply patch tool example - Python](https://github.com/openai/openai-agents-python/blob/main/examples/tools/apply_patch.py)

598 598 

599Example of how to use the apply patch tool with the Agents SDK in Python

599 600 

600 601 

601 Example of how to use the apply patch tool with the Agents SDK in Python](https://github.com/openai/openai-agents-python/blob/main/examples/tools/apply_patch.py)

602 602 

603## Handling common errors603## Handling common errors

604 604 

Details

2111 2111 

2112You can find working examples in the SDK repositories.2112You can find working examples in the SDK repositories.

2113 2113 

2114[Shell tool example - TypeScript2114[Shell tool example - TypeScript](https://github.com/openai/openai-agents-js/blob/main/examples/tools/shell.ts)

2115 2115 

2116TypeScript example for the shell tool in the Agents SDK.

2116 2117 

2117 2118 

2118 TypeScript example for the shell tool in the Agents SDK.](https://github.com/openai/openai-agents-js/blob/main/examples/tools/shell.ts)

2119 2119 

2120[Shell tool example - Python2120[Shell tool example - Python](https://github.com/openai/openai-agents-python/blob/main/examples/tools/shell.py)

2121 2121 

2122Python example for the shell tool in the Agents SDK.

2122 2123 

2123 2124 

2124 Python example for the shell tool in the Agents SDK.](https://github.com/openai/openai-agents-python/blob/main/examples/tools/shell.py)

2125 2125 

2126## Handling common errors2126## Handling common errors

2127 2127 

Details

187 189 

188Now that you know the basics of vision fine-tuning, explore these other methods as well.190Now that you know the basics of vision fine-tuning, explore these other methods as well.

189 191 

190[Supervised fine-tuning192[Supervised fine-tuning](https://developers.openai.com/api/docs/guides/supervised-fine-tuning)

191 

192 

193 193 

194 Fine-tune a model by providing correct outputs for sample inputs.](https://developers.openai.com/api/docs/guides/supervised-fine-tuning)194Fine-tune a model by providing correct outputs for sample inputs.

195 195 

196[Direct preference optimization

197 196 

198 197 

198[Direct preference optimization](https://developers.openai.com/api/docs/guides/direct-preference-optimization)

199 199 

200 Fine-tune a model using direct preference optimization (DPO).](https://developers.openai.com/api/docs/guides/direct-preference-optimization)200Fine-tune a model using direct preference optimization (DPO).

Details

149 149 

150## Next steps150## Next steps

151 151 

152[Audio and voice overview152[Audio and voice overview](https://developers.openai.com/api/docs/guides/audio)

153 153 

154Choose the right realtime or audio guide for your use case.

154 155 

155 156 

156 Choose the right realtime or audio guide for your use case.](https://developers.openai.com/api/docs/guides/audio)

157 157 

158[Managing conversations158[Managing conversations](https://developers.openai.com/api/docs/guides/realtime-conversations)

159 159 

160Work with the Realtime session lifecycle and event model.

160 161 

161 162 

162 Work with the Realtime session lifecycle and event model.](https://developers.openai.com/api/docs/guides/realtime-conversations)

163 163 

164[WebRTC connection164[WebRTC connection](https://developers.openai.com/api/docs/guides/voice-webrtc)

165 165 

166Connect browser and mobile audio directly to a Realtime session.

166 167 

167 168 

168 Connect browser and mobile audio directly to a Realtime session.](https://developers.openai.com/api/docs/guides/voice-webrtc)

169 169 

170[Realtime prompting guide170[Realtime prompting guide](https://developers.openai.com/api/docs/guides/voice-prompting)

171 171 

172 172Tune reasoning, preambles, tools, entity capture, and voice behavior.

173 

174 Tune reasoning, preambles, tools, entity capture, and voice behavior.](https://developers.openai.com/api/docs/guides/voice-prompting)

Details

1019 1021 

1020To learn more about managing Realtime conversations, refer to the [Realtime conversations guide](https://developers.openai.com/api/docs/guides/realtime-conversations).1022To learn more about managing Realtime conversations, refer to the [Realtime conversations guide](https://developers.openai.com/api/docs/guides/realtime-conversations).

1021 1023 

1022[Realtime Console1024[Realtime Console](https://github.com/openai/openai-realtime-console/)

1023 

1024 

1025 1025 

1026 Check out the WebRTC Realtime API in this light weight example app.](https://github.com/openai/openai-realtime-console/)1026Check out the WebRTC Realtime API in this light weight example app.

Details

10 10 

11For Agents API sessions, see [Session webhooks](https://developers.openai.com/api/docs/guides/agents-api/sessions/webhooks) for session events and recovery patterns. Use the endpoint setup, signature verification, and delivery guidance on this page for the webhook receiver.11For Agents API sessions, see [Session webhooks](https://developers.openai.com/api/docs/guides/agents-api/sessions/webhooks) for session events and recovery patterns. Use the endpoint setup, signature verification, and delivery guidance on this page for the webhook receiver.

12 12 

13[API reference for webhook events13[API reference for webhook events](https://developers.openai.com/api/reference/resources/webhooks)

14 14 

15View the full list of webhook events.

15 16 

16 17 

17 View the full list of webhook events.](https://developers.openai.com/api/reference/resources/webhooks)

18 18 

19Below are examples of servers capable of ingesting webhooks from OpenAI, specifically for the [`response.completed`](https://developers.openai.com/api/reference/resources/webhooks) event.19Below are examples of servers capable of ingesting webhooks from OpenAI, specifically for the [`response.completed`](https://developers.openai.com/api/reference/resources/webhooks) event.

20 20 

Details

16 16 

17Install the WebSocket dependencies with `pip install "openai[realtime]>=3.8.0"` for Python, `npm install openai@^7.10.0 ws` for JavaScript, or `gem install openai async-websocket` for Ruby.17Install the WebSocket dependencies with `pip install "openai[realtime]>=3.8.0"` for Python, `npm install openai@^7.10.0 ws` for JavaScript, or `gem install openai async-websocket` for Ruby.

18 18 

19For Go, run `go get github.com/openai/openai-go/v3@v3.96.0`.19For Go, run `go get github.com/openai/openai-go/v3@v3.97.0`.

20For Java, add the Maven dependency `com.openai:openai-java:4.101.0` and use Java 17 or later for these examples.20For Java, add the Maven dependency `com.openai:openai-java:4.101.0` and use Java 17 or later for these examples.

21These Go and Java SDK versions provide native Responses WebSocket support.21These Go and Java SDK versions provide native Responses WebSocket support.

22 22 

libraries.md +21 −27

Details

69```70```

70 71 

71 72 

72Execute the code with `node example.mjs` (or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request.

73 

74[Learn more on GitHub

75 73 

74Execute the code with `node example.mjs` (or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request.

76 75 

76[Learn more on GitHub](https://github.com/openai/openai-node)

77 77 

78 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-node)78Discover more SDK capabilities and options on the library's GitHub README.

79 79 

80 80 

81 81


114```115```

115 116 

116 117 

117Execute the code with `python example.py`. In a few moments, you should see the output of your API request.

118 

119[Learn more on GitHub

120 118 

119Execute the code with `python example.py`. In a few moments, you should see the output of your API request.

121 120 

121[Learn more on GitHub](https://github.com/openai/openai-python)

122 122 

123 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-python)123Discover more SDK capabilities and options on the library's GitHub README.

124 124 

125 125 

126 126


173<dependency>175<dependency>

174 <groupId>com.openai</groupId>176 <groupId>com.openai</groupId>

175 <artifactId>openai-java</artifactId>177 <artifactId>openai-java</artifactId>

176 <version>4.101.0</version>178 <version>4.102.0</version>

177</dependency>179</dependency>

178```180```

179 181 


206```209```

207 210 

208 211 

209To learn more about using the OpenAI API in Java, check out the GitHub repo linked below!

210 

211[Learn more on GitHub

212 212 

213To learn more about using the OpenAI API in Java, check out the GitHub repo linked below!

213 214 

215[Learn more on GitHub](https://github.com/openai/openai-java)

214 216 

215 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-java)217Discover more SDK capabilities and options on the library's GitHub README.

216 218 

217 219 

218 220


264```267```

265 268 

266 269 

267To learn more about using the OpenAI API in Go, check out the GitHub repo linked below!

268 

269[Learn more on GitHub

270 270 

271To learn more about using the OpenAI API in Go, check out the GitHub repo linked below!

271 272 

273[Learn more on GitHub](https://github.com/openai/openai-go)

272 274 

273 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-go)275Discover more SDK capabilities and options on the library's GitHub README.

274 276 

275 277 

276 278


309```312```

310 313 

311 314 

312Execute the code with `ruby example.rb`. In a few moments, you should see the output of your API request.

313 

314[Learn more on GitHub

315 315 

316Execute the code with `ruby example.rb`. In a few moments, you should see the output of your API request.

316 317 

318[Learn more on GitHub](https://github.com/openai/openai-ruby)

317 319 

318 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-ruby)320Discover more SDK capabilities and options on the library's GitHub README.

319 321 

320 322 

321 323


349```352```

350 353 

351 354 

352Use the CLI for repeatable terminal workflows such as extracting structured data from files, generating images, creating speech, and composing API calls with shell tools like `jq`.

353 

354[OpenAI CLI guide

355 355 

356Use the CLI for repeatable terminal workflows such as extracting structured data from files, generating images, creating speech, and composing API calls with shell tools like `jq`.

356 357 

358[OpenAI CLI guide](https://developers.openai.com/api/docs/libraries/openai-cli)

357 359 

358 Learn more about CLI workflows and command patterns.](https://developers.openai.com/api/docs/libraries/openai-cli)360Learn more about CLI workflows and command patterns.

359 361 

360 362 

361 363 


368If you are deciding between direct API requests and code-first orchestration,370If you are deciding between direct API requests and code-first orchestration,

369see [how the Responses API compares with the Agents SDK](https://developers.openai.com/api/docs/guides/agents#agents-sdk-vs-responses-api).371see [how the Responses API compares with the Agents SDK](https://developers.openai.com/api/docs/guides/agents#agents-sdk-vs-responses-api).

370 372 

371[Agents SDK quickstart373[Agents SDK quickstart](https://developers.openai.com/api/docs/guides/agents/quickstart)

372 374 

375Build your first agent with the Agents SDK.

373 376 

374 377 

375 Build your first agent with the Agents SDK.](https://developers.openai.com/api/docs/guides/agents/quickstart)

376 378 

377- [OpenAI Agents SDK for TypeScript](https://github.com/openai/openai-agents-js)379- [OpenAI Agents SDK for TypeScript](https://github.com/openai/openai-agents-js)

378- [OpenAI Agents SDK for Python](https://github.com/openai/openai-agents-python)380- [OpenAI Agents SDK for Python](https://github.com/openai/openai-agents-python)

mcp.md +2 −2

Details

157 161 

158You can try this example MCP server in a [browser-based development environment](https://replit.com/). Configure the sample with your own API credentials and vector store information.162You can try this example MCP server in a [browser-based development environment](https://replit.com/). Configure the sample with your own API credentials and vector store information.

159 163 

160[Example MCP server on Replit164[Example MCP server on Replit](https://replit.com/@kwhinnery-oai/DeepResearchServer?v=1#README.md)

161 165 

166Remix the server example on Replit to test live.

162 167 

163 168 

164 Remix the server example on Replit to test live.](https://replit.com/@kwhinnery-oai/DeepResearchServer?v=1#README.md)

165 169 

166A full implementation of both the `search` and `fetch` tools in FastMCP is below also for convenience.170A full implementation of both the `search` and `fetch` tools in FastMCP is below also for convenience.

167 171 

quickstart.md +40 −68

Details

6 6 

7## Create and export an API key7## Create and export an API key

8 8 

9 9[Create an API Key](https://platform.openai.com/api-keys)

10 

11StatsigClient.logEvent("quickstart_create_api_key_click", null, null)

12 }

13>

14 Create an API Key

15 

16 

17 10 

18 11 

19 12 


86```80```

87 81 

88 82 

89Execute the code with `node example.mjs` (or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request.

90 

91[Learn more on GitHub

92 83 

84Execute the code with `node example.mjs` (or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request.

93 85 

86[Learn more on GitHub](https://github.com/openai/openai-node)

94 87 

95 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-node)88Discover more SDK capabilities and options on the library's GitHub README.

96 89 

97 90 

98 91


131```125```

132 126 

133 127 

134Execute the code with `python example.py`. In a few moments, you should see the output of your API request.

135 

136[Learn more on GitHub

137 128 

129Execute the code with `python example.py`. In a few moments, you should see the output of your API request.

138 130 

131[Learn more on GitHub](https://github.com/openai/openai-python)

139 132 

140 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-python)133Discover more SDK capabilities and options on the library's GitHub README.

141 134 

142 135 

143 136


190<dependency>185<dependency>

191 <groupId>com.openai</groupId>186 <groupId>com.openai</groupId>

192 <artifactId>openai-java</artifactId>187 <artifactId>openai-java</artifactId>

193 <version>4.101.0</version>188 <version>4.102.0</version>

194</dependency>189</dependency>

195```190```

196 191 


223```219```

224 220 

225 221 

226To learn more about using the OpenAI API in Java, check out the GitHub repo linked below!

227 

228[Learn more on GitHub

229 222 

223To learn more about using the OpenAI API in Java, check out the GitHub repo linked below!

230 224 

225[Learn more on GitHub](https://github.com/openai/openai-java)

231 226 

232 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-java)227Discover more SDK capabilities and options on the library's GitHub README.

233 228 

234 229 

235 230


281```277```

282 278 

283 279 

284To learn more about using the OpenAI API in Go, check out the GitHub repo linked below!

285 

286[Learn more on GitHub

287 280 

281To learn more about using the OpenAI API in Go, check out the GitHub repo linked below!

288 282 

283[Learn more on GitHub](https://github.com/openai/openai-go)

289 284 

290 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-go)285Discover more SDK capabilities and options on the library's GitHub README.

291 286 

292 287 

293 288


326```322```

327 323 

328 324 

329Execute the code with `ruby example.rb`. In a few moments, you should see the output of your API request.

330 

331[Learn more on GitHub

332 325 

326Execute the code with `ruby example.rb`. In a few moments, you should see the output of your API request.

333 327 

328[Learn more on GitHub](https://github.com/openai/openai-ruby)

334 329 

335 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-ruby)330Discover more SDK capabilities and options on the library's GitHub README.

336 331 

337 332 

338[Responses starter app333[Responses starter app](https://github.com/openai/openai-responses-starter-app)

339 334 

335Start building with the Responses API.

340 336 

341 337 

342 Start building with the Responses API.](https://github.com/openai/openai-responses-starter-app)

343 338 

344[Text generation and prompting339[Text generation and prompting](https://developers.openai.com/api/docs/guides/text)

345 340 

341Learn more about prompting, message roles, and building conversational apps.

346 342 

347 343 

348 Learn more about prompting, message roles, and building conversational apps.](https://developers.openai.com/api/docs/guides/text)

349 344 

350## Add credits to keep building345## Add credits to keep building

351 346 

352 347[Go to billing](https://platform.openai.com/account/billing/overview)

353 

354StatsigClient.logEvent("quickstart_add_credits_billing_click", null, null)

355 }

356>

357 Go to billing

358 

359 

360 348 

361Congrats on running a free test API request! Start building real applications with higher limits and use [our models](https://developers.openai.com/api/docs/models) to generate text, audio, images, videos and more.349Congrats on running a free test API request! Start building real applications with higher limits and use [our models](https://developers.openai.com/api/docs/models) to generate text, audio, images, videos and more.

362 350 


366 Explore tools and docs designed to help you ship faster:354 Explore tools and docs designed to help you ship faster:

367 355 

368 356 

369[StatsigClient.logEvent(357[Chat Playground](https://platform.openai.com/chat)

370 "quickstart_add_credits_chat_playground_click",

371 null,

372 null

373 )

374 }

375>

376 Chat Playground

377 358 

359Build & test conversational prompts and embed them in your app.

378 360 

379 361 

380 Build & test conversational prompts and embed them in your app.](https://platform.openai.com/chat)362[Build agents](https://developers.openai.com/api/docs/guides/agents)

381[Build agents

382 363 

364Use the Agents SDK to build, run, and observe agent workflows.

383 365 

384 366 

385 Use the Agents SDK to build, run, and observe agent workflows.](https://developers.openai.com/api/docs/guides/agents)

386 367 

387## Analyze images and files368## Analyze images and files

388 369 


1094 1075 

1095 1076 

1096 1077 

1097[Image inputs guide1078[Image inputs guide](https://developers.openai.com/api/docs/guides/images-vision)

1098 1079 

1080Learn to use image inputs to the model and extract meaning from images.

1099 1081 

1100 1082 

1101 Learn to use image inputs to the model and extract meaning from images.](https://developers.openai.com/api/docs/guides/images-vision)

1102 1083 

1103[File inputs guide1084[File inputs guide](https://developers.openai.com/api/docs/guides/file-inputs)

1104 1085 

1086Learn to use file inputs to the model and extract meaning from documents.

1105 1087 

1106 1088 

1107 Learn to use file inputs to the model and extract meaning from documents.](https://developers.openai.com/api/docs/guides/file-inputs)

1108 1089 

1109## Extend the model with tools1090## Extend the model with tools

1110 1091 


1993 1974 

1994 1975 

1995 1976 

1996[Use built-in tools1977[Use built-in tools](https://developers.openai.com/api/docs/guides/tools)

1997 1978 

1979Learn about powerful built-in tools like web search and file search.

1998 1980 

1999 1981 

2000 Learn about powerful built-in tools like web search and file search.](https://developers.openai.com/api/docs/guides/tools)

2001 1982 

2002[Function calling guide1983[Function calling guide](https://developers.openai.com/api/docs/guides/function-calling)

2003 1984 

1985Learn to enable the model to call your own custom code.

2004 1986 

2005 1987 

2006 Learn to enable the model to call your own custom code.](https://developers.openai.com/api/docs/guides/function-calling)

2007 1988 

2008## Stream responses and build real-time apps1989## Stream responses and build real-time apps

2009 1990 


2137```2118```

2138 2119 

2139 2120 

2140[Use streaming events2121[Use streaming events](https://developers.openai.com/api/docs/guides/streaming-responses)

2141 2122 

2123Use server-sent events to stream model responses to users fast.

2142 2124 

2143 2125 

2144 Use server-sent events to stream model responses to users fast.](https://developers.openai.com/api/docs/guides/streaming-responses)

2145 2126 

2146[Get started with the Realtime API2127[Get started with the Realtime API](https://developers.openai.com/api/docs/guides/realtime)

2147 2128 

2129Use WebRTC or WebSockets for super fast speech-to-speech AI apps.

2148 2130 

2149 2131 

2150 Use WebRTC or WebSockets for super fast speech-to-speech AI apps.](https://developers.openai.com/api/docs/guides/realtime)

2151 2132 

2152## Build agents2133## Build agents

2153 2134 


2210```2191```

2211 2192 

2212 2193 

2213[Build agents that can take action2194[Build agents that can take action](https://developers.openai.com/api/docs/guides/agents)

2214 

2215 

2216 2195 

2217 Learn how to use the OpenAI platform to build powerful, capable AI agents.](https://developers.openai.com/api/docs/guides/agents)2196Learn how to use the OpenAI platform to build powerful, capable AI agents.