SpyBara
Go Premium

Documentation 2026-11-22 23:57 UTC to 2026-11-23 23:58 UTC

11 files changed +99 −80. View all changes and history on the product overview
2026
Thu 26 22:58 Wed 25 23:57 Tue 24 23:00 Mon 23 23:58 Sat 21 23:57 Fri 20 23:59 Thu 19 22:59 Wed 18 22:59 Tue 17 22:57 Mon 16 23:00 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

88| ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |88| ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

89| `invalid_request` | **Cause:** Input or configuration is invalid. <br /> **Solution:** Correct the input described in the message before trying again. |89| `invalid_request` | **Cause:** Input or configuration is invalid. <br /> **Solution:** Correct the input described in the message before trying again. |

90| `context_length_exceeded` | **Cause:** Input exceeds the model's context window. <br /> **Solution:** Reduce the input. If the conversation is too long, start a new session with a shorter summary. |90| `context_length_exceeded` | **Cause:** Input exceeds the model's context window. <br /> **Solution:** Reduce the input. If the conversation is too long, start a new session with a shorter summary. |

91| `session_budget_exceeded` | **Cause:** The session reached its usage budget. <br /> **Solution:** Start a new session to continue. |91| `session_budget_exceeded` | **Cause:** The turn stopped because the session reached its spending limit. <br /> **Solution:** [Increase or remove the session limit](https://developers.openai.com/api/docs/guides/agents-api/sessions/manage#set-a-session-budget) to continue unfinished work. |

92| `credit_balance_exhausted` | **Cause:** The organization has no API credits remaining. <br /> **Solution:** See [credit balance guidance](https://developers.openai.com/api/docs/guides/error-codes#api-errors). |92| `credit_balance_exhausted` | **Cause:** The organization has no API credits remaining. <br /> **Solution:** See [credit balance guidance](https://developers.openai.com/api/docs/guides/error-codes#api-errors). |

93| `project_spend_limit_exceeded` | **Cause:** The project reached its enforced spend limit. <br /> **Solution:** See [project spend limit guidance](https://developers.openai.com/api/docs/guides/error-codes#api-errors). |93| `project_spend_limit_exceeded` | **Cause:** The project reached its enforced spend limit. <br /> **Solution:** See [project spend limit guidance](https://developers.openai.com/api/docs/guides/error-codes#api-errors). |

94| `organization_spend_limit_exceeded` | **Cause:** The organization reached its enforced spend limit. <br /> **Solution:** See [organization spend limit guidance](https://developers.openai.com/api/docs/guides/error-codes#api-errors). |94| `organization_spend_limit_exceeded` | **Cause:** The organization reached its enforced spend limit. <br /> **Solution:** See [organization spend limit guidance](https://developers.openai.com/api/docs/guides/error-codes#api-errors). |

Details

562 562 

563Cached tokens are included in `input_tokens`, and reasoning tokens are included in `output_tokens`.563Cached tokens are included in `input_tokens`, and reasoning tokens are included in `output_tokens`.

564 564 

565### Control session spending

566 

567To set a best-effort spending limit and learn how to continue after a session reaches it, see [Set a session budget](https://developers.openai.com/api/docs/guides/agents-api/sessions/manage#set-a-session-budget).

568 

565### Inspect subagent token usage569### Inspect subagent token usage

566 570 

567List or retrieve [session turns](https://developers.openai.com/api/docs/guides/agents-api/sessions/manage#inspect-session-turns) and inspect each turn's `usage`. The `subagent_id` identifies the subagent; it is `null` for root-agent turns. When `has_more` is `true`, pass `last_id` as `after` with the same `order` to read the remaining turns.571List or retrieve [session turns](https://developers.openai.com/api/docs/guides/agents-api/sessions/manage#inspect-session-turns) and inspect each turn's `usage`. The `subagent_id` identifies the subagent; it is `null` for root-agent turns. When `has_more` is `true`, pass `last_id` as `after` with the same `order` to read the remaining turns.

Details

175 175 

176For saved messages, tool calls, and turn outcomes, see [Fetch items and turns](https://developers.openai.com/api/docs/guides/agents-api/sessions/events#fetch-items-and-turns). To identify which agent ran a command, see [Observe delegation](https://developers.openai.com/api/docs/guides/agents-api/multi-agent#observe-delegation).176For saved messages, tool calls, and turn outcomes, see [Fetch items and turns](https://developers.openai.com/api/docs/guides/agents-api/sessions/events#fetch-items-and-turns). To identify which agent ran a command, see [Observe delegation](https://developers.openai.com/api/docs/guides/agents-api/multi-agent#observe-delegation).

177 177 

178## Set a session budget

179 

180A `spend_control` object must include `limit`. Set it to a positive integer in USD cents, such as `500` for $5, or `null` for no limit.

181 

182Budget control makes a best-effort attempt to limit spending. Spend readings can lag, and work that has already started can continue to incur charges. Actual spend can exceed the limit. If the API cannot check spend, work can continue.

183 

184### Create a session with a limit

185 

186Send a `POST` request to `/v1/agents/sessions`. For a session without an execution environment, include initial input:

187 

188```json snippet=reference reason="Session creation request body with a $5 spending limit"

189{

190 "agent": { "model": "gpt-6.1-terra" },

191 "environment": { "type": "none" },

192 "input": "Reply with exactly OK.",

193 "spend_control": { "limit": 500 }

194}

195```

196 

197To create an unlimited session, omit `spend_control` or set it to `null`.

198 

199### Read the limit and recorded spend

200 

201Send a `GET` request to `/v1/agents/sessions/{session_id}`. Replace `{session_id}` with the ID returned by creation. The session response always includes a `spend_control` object:

202 

203```json snippet=output reason="Session response excerpt with a $5 limit and unknown consumption"

204{

205 "id": "sess_example",

206 "object": "agent.session",

207 "spend_control": {

208 "limit": 500,

209 "consumed": null

210 }

211}

212```

213 

214`limit` is the total session limit, or `null` if no limit is set. `consumed` is the best-effort recorded spend, rounded down to whole USD cents. It is `null` if no usable reading is available. If budget control is unavailable for the project, both values are `null`.

215 

216This unlimited session has recorded $1.23.

217 

218```json snippet=output reason="Session response excerpt with no limit and $1.23 in recorded spend"

219{

220 "spend_control": {

221 "limit": null,

222 "consumed": 123

223 }

224}

225```

226 

227### Change or remove the limit

228 

229Send a `POST` request to `/v1/agents/sessions/{session_id}` with the new total limit. This request changes the total limit to $10 without resetting recorded spend:

230 

231```json snippet=reference reason="Session update request body with a $10 total spending limit"

232{

233 "spend_control": { "limit": 1000 }

234}

235```

236 

237Omit `spend_control` from an update to keep the current limit. To remove the limit, set `spend_control` to `null` or send the following request.

238 

239```json snippet=reference reason="Session update request body that removes the spending limit"

240{

241 "spend_control": { "limit": null }

242}

243```

244 

245Retrieve the session again to confirm the change. An unlimited session has `spend_control.limit: null`. Recorded spend can change between reads.

246 

247### Continue after reaching the budget

248 

249Watch for session status `budget_reached` or the `agent.session.budget_reached` event. The API rejects new input when it detects that the session has reached its limit. A turn stopped by the budget fails with `session_budget_exceeded`.

250 

251Increase or remove the total limit to continue. Work stopped by the budget can resume automatically. Follow session events before sending more input.

252 

178## Delete a session253## Delete a session

179 254 

180Delete a session when your application no longer needs it. Deletion removes the session from the API. Physical cleanup may continue asynchronously.255Delete a session when your application no longer needs it. Deletion removes the session from the API. Physical cleanup may continue asynchronously.

Details

30Choose a voice when you create the session. Set `audio.output.voice` to the API name, such as `"quartz"`. GPT-Live includes these additional voice options:30Choose a voice when you create the session. Set `audio.output.voice` to the API name, such as `"quartz"`. GPT-Live includes these additional voice options:

31 31 

32| Voice | API name | Language | Regional influence | Presentation | Source |32| Voice | API name | Language | Regional influence | Presentation | Source |

33| -------- | ---------- | ---------- | ------------------ | ------------ | --------- |33| ---------- | ------------ | ---------- | ------------------ | ------------ | --------- |

34| Pearl | `pearl` | English | Australian | Feminine | Natural |

34| Quartz | `quartz` | English | Australian | Feminine | Generated |35| Quartz | `quartz` | English | Australian | Feminine | Generated |

35| Ripple | `ripple` | English | Australian | Masculine | Natural |36| Ripple | `ripple` | English | Australian | Masculine | Natural |

37| Halo | `halo` | English | British | Feminine | Natural |

36| Vesper | `vesper` | English | British | Masculine | Natural |38| Vesper | `vesper` | English | British | Masculine | Natural |

37| Willow | `willow` | English | Irish | Feminine | Natural |39| Willow | `willow` | English | Irish | Feminine | Natural |

38| Stone | `stone` | English | Irish | Masculine | Natural |40| Stone | `stone` | English | Irish | Masculine | Natural |


43| Beacon | `beacon` | English | Filipino | Masculine | Generated |45| Beacon | `beacon` | English | Filipino | Masculine | Generated |

44| Delta | `delta` | English | Southern U.S. | Feminine | Generated |46| Delta | `delta` | English | Southern U.S. | Feminine | Generated |

45| Cinder | `cinder` | English | Southern U.S. | Masculine | Generated |47| Cinder | `cinder` | English | Southern U.S. | Masculine | Generated |

48| Calandria | `calandria` | Spanish | Argentine | Feminine | Natural |

49| Compás | `compas` | Spanish | Argentine | Masculine | Natural |

50| Hornero | `hornero` | Spanish | Argentine | Masculine | Natural |

51| Luciérnaga | `luciernaga` | Spanish | Mexican | Feminine | Natural |

52| Destello | `destello` | Spanish | Mexican | Masculine | Natural |

46| Nuri | `nuri` | German | — | Feminine | Natural |53| Nuri | `nuri` | German | — | Feminine | Natural |

47| Juni | `juni` | German | — | Feminine | Natural |54| Juni | `juni` | German | — | Feminine | Natural |

48| Flitz | `flitz` | German | — | Masculine | Natural |55| Flitz | `flitz` | German | — | Masculine | Natural |

Details

20export default User;20export default User;

21```21```

22 22 

23```ruby

24class User

25 attr_accessor :first_name, :last_name, :username

26 

27 def initialize

28 @first_name = ""

29 @last_name = ""

30 @username = ""

31 end

32end

33```

34 

35 23 

36Most of the file will be unchanged, except for line 4 above. If you use the current text of the code file as your prediction, you can regenerate the entire file with lower latency. These time savings add up quickly for larger files.24Most of the file will be unchanged, except for line 4 above. If you use the current text of the code file as your prediction, you can regenerate the entire file with lower latency. These time savings add up quickly for larger files.

37 25 


613});601});

614```602```

615 603 

616```ruby

617require "webrick"

618 

619server = WEBrick::HTTPServer.new(Port: Integer(ENV.fetch("PORT", "3000")), BindAddress: "127.0.0.1")

620# Build your client first and place its static files in dist/.

621static_files = WEBrick::HTTPServlet::FileHandler.new(server, File.expand_path("dist"))

622server.mount_proc("/") do |request, response|

623 response["Content-Type"] = "text/plain"

624 if !%w[GET HEAD].include?(request.request_method)

625 response.status = 404

626 response.body = "404 Not Found"

627 elsif request.path == "/api"

628 response.body = "Hello Hono!"

629 else

630 begin

631 static_files.service(request, response)

632 rescue WEBrick::HTTPStatus::NotFound

633 response.status = 404

634 response.body = "404 Not Found"

635 end

636 end

637end

638trap("INT") { server.shutdown }

639trap("TERM") { server.shutdown }

640server.start

641```

642 

643 604 

644You could prompt the model to regenerate the file with a prompt like:605You could prompt the model to regenerate the file with a prompt like:

645 606 


684});645});

685```646```

686 647 

687```ruby

688require "webrick"

689 

690server = WEBrick::HTTPServer.new(Port: Integer(ENV.fetch("PORT", "3000")), BindAddress: "127.0.0.1")

691# Build your client first and place its static files in dist/.

692static_files = WEBrick::HTTPServlet::FileHandler.new(server, File.expand_path("dist"))

693server.mount_proc("/") do |request, response|

694 response["Content-Type"] = "text/plain"

695 if !%w[GET HEAD].include?(request.request_method)

696 response.status = 404

697 response.body = "404 Not Found"

698 elsif request.path == "/api"

699 response.body = "Hello Hono!"

700 elsif request.path == "/hello"

701 response.body = "hello world"

702 else

703 begin

704 static_files.service(request, response)

705 rescue WEBrick::HTTPStatus::NotFound

706 response.status = 404

707 response.body = "404 Not Found"

708 end

709 end

710end

711trap("INT") { server.shutdown }

712trap("TERM") { server.shutdown }

713server.start

714```

715 

716 648 

717An abridged model response without the `choices` field would still show accepted prediction tokens, even though the prediction text appeared both before and after the new content added to the response:649An abridged model response without the `choices` field would still show accepted prediction tokens, even though the prediction text appeared both before and after the new content added to the response:

718 650 

Details

53 53 

54If your application identifies individual end users, include a [safety identifier](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers) with Realtime API requests. OpenAI recommends safety identifiers but doesn't require them. They help OpenAI detect harmful behavior and target enforcement to an individual user rather than your entire organization. Use a stable, privacy-preserving value, such as a hashed internal user ID.54If your application identifies individual end users, include a [safety identifier](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers) with Realtime API requests. OpenAI recommends safety identifiers but doesn't require them. They help OpenAI detect harmful behavior and target enforcement to an individual user rather than your entire organization. Use a stable, privacy-preserving value, such as a hashed internal user ID.

55 55 

56For Realtime API requests, send the identifier in the `OpenAI-Safety-Identifier` header. When using ephemeral tokens, set the header on the server-side request that creates the client secret to associate the identifier with the session. When connecting from a trusted server with WebSocket or the unified WebRTC interface, set the header on the connection request.56For Realtime API requests, send the identifier in the `OpenAI-Safety-Identifier` header. Use an identifier of 128 characters or fewer. When using ephemeral tokens, set the header on the server-side request that creates the client secret to associate the identifier with the session. When connecting from a trusted server with WebSocket or the unified WebRTC interface, set the header on the connection request.

57 57 

58Safety identifiers don't carry over from Responses API requests or other sessions. If you use the Responses API `safety_identifier` parameter elsewhere in your application, pass the same stable value when you create or connect each Realtime session.58Safety identifiers don't carry over from Responses API requests or other sessions. If you use the Responses API `safety_identifier` parameter elsewhere in your application, pass the same stable value when you create or connect each Realtime session.

59 59 

Details

142 142 

143 143 

144 144 

145Before running this example, install `openai` version 0.121.0 and `async-websocket` for Ruby (`gem install openai -v 0.121.0` and `gem install async-websocket`).145Before running this example, install `openai` and `async-websocket` for Ruby (`gem install openai` and `gem install async-websocket`).

146 146 

147 147 

148 148 

Details

38 38 

39## Compare returned image sizes as strings39## Compare returned image sizes as strings

40 40 

41Image responses and image generation and edit stream events return size strings such as `"1024x1024"`. Use `image.size&.to_s` in code that supports both SDK versions or needs to handle an omitted size. The size constants and `Size.values` also use strings.41Image responses and image generation and edit stream events return size strings such as `"1024x1024"`. Use `image.size == "1024x1024"` to compare the size. The size constants and `Size.values` also use strings.

42 42 

43## Replace retired model constants43## Replace retired model constants

44 44 

Details

832If your application assigns a [safety identifier](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers)832If your application assigns a [safety identifier](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers)

833for each end user, include it as the `OpenAI-Safety-Identifier` header in this833for each end user, include it as the `OpenAI-Safety-Identifier` header in this

834server-side request. Use a stable, privacy-preserving value, such as a hashed834server-side request. Use a stable, privacy-preserving value, such as a hashed

835internal user ID. The header should be set by your trusted backend, not by the835internal user ID. Keep the identifier to 128 characters or fewer. The header

836browser.836should be set by your trusted backend, not by the browser.

837 837 

838#### Connecting to the server838#### Connecting to the server

839 839 


1021You can create a server endpoint like this one on any platform that can send and receive HTTP requests. Just ensure that **you only use standard OpenAI API keys on the server, not in the browser.**1021You can create a server endpoint like this one on any platform that can send and receive HTTP requests. Just ensure that **you only use standard OpenAI API keys on the server, not in the browser.**

1022 1022 

1023When using ephemeral tokens, set `OpenAI-Safety-Identifier` on the server-side1023When using ephemeral tokens, set `OpenAI-Safety-Identifier` on the server-side

1024request that creates the client secret. The Realtime API binds the identifier to1024request that creates the client secret. Keep the identifier to 128 characters or

1025the resulting ephemeral token, so the browser does not need to send the safety1025fewer. The Realtime API binds the identifier to the resulting ephemeral token,

1026identifier when it later connects with that token.1026so the browser does not need to send the safety identifier when it later

1027connects with that token.

1027 1028 

1028#### Connecting to the server1029#### Connecting to the server

1029 1030 

Details

698 698 

699## Connect via WebSocket699## Connect via WebSocket

700 700 

701Below are several examples of connecting via WebSocket to the Realtime API. In addition to using the WebSocket URL below, you will also need to pass an authentication header using your OpenAI API key. If your application assigns [safety identifiers](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers), pass the stable, privacy-preserving identifier for the end user in the `OpenAI-Safety-Identifier` header.701Below are several examples of connecting via WebSocket to the Realtime API. In addition to using the WebSocket URL below, you will also need to pass an authentication header using your OpenAI API key. If your application assigns [safety identifiers](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers), pass the stable, privacy-preserving identifier for the end user in the `OpenAI-Safety-Identifier` header. Keep the identifier to 128 characters or fewer.

702 702 

703It is possible to use WebSocket in browsers with an ephemeral API token as shown in the [WebRTC connection guide](https://developers.openai.com/api/docs/guides/voice-webrtc?api=realtime), but if you are connecting from a client like a browser or mobile app, WebRTC will be a more robust solution in most cases.703It is possible to use WebSocket in browsers with an ephemeral API token as shown in the [WebRTC connection guide](https://developers.openai.com/api/docs/guides/voice-webrtc?api=realtime), but if you are connecting from a client like a browser or mobile app, WebRTC will be a more robust solution in most cases.

704 704 

Details

427 427 

428 headers = request.header.transform_values(&:first)428 headers = request.header.transform_values(&:first)

429 event = client.webhooks.unwrap(request.body, headers)429 event = client.webhooks.unwrap(request.body, headers)

430 puts "Verified webhook event: #{event.type}"430 puts "Verified webhook event: #{event[:type]}"

431 431 

432 response.status = 200432 response.status = 200

433 response.body = "ok"433 response.body = "ok"