OpenAI released version 3.58.0 of the openai-python library on 23 November 2026, introducing spending controls for beta agent sessions alongside a bug fix for completion choice counts, according to the release notes. The release packages pull request 4315, which adds the spend_control feature across both synchronous and asynchronous clients, including streaming creation, where the server sends session events incrementally as they occur. The same release also includes pull request 4298, which clarifies when callers should omit the completion choice count in API requests.12
Null values distinguish unlimited budgets from missing data
In practice, the pull request explains that the spending limit is best-effort rather than a hard guarantee, and builders express it in USD cents. When a session response arrives, both the limit and consumed keys are required in response fixtures, which are the predefined sample payloads used to validate API shapes. A null value for limit indicates unlimited spending, while a null value for consumed signals that the spent amount is unavailable. If a builder updates an existing session, omitting spend_control preserves the current cap, whereas passing a null limit removes it.2
Typed events and errors signal when a session hits its cap
When a beta agent session reaches its configured spending cap, the SDK surfaces three specific signals, according to the pull request. Sessions expose a budget_reached status, turns can return a session_budget_exceeded error, and streaming consumers receive a typed AgentSessionBudgetReachedEvent. During code review, a reviewer verified that the SDK's response models and event discriminators, which are fields that identify each event type in a stream, match the API schema. The reviewer also confirmed that existing stream collectors handle these budget-reached boundaries across both streaming surfaces.2
Local validation ran 581 Pydantic v2 agent tests
Before the change merged into the main branch, the contributor reported passing local validation with 581 focused agent tests on Pydantic v2 and 493 on Pydantic v1, referring to the Python data-validation library. Those local checks also included whole-tree type checking and whole-tree linting with Ruff, a Python code linter, exercising nullable spending values, omitted updates, and typed budget events. In hosted continuous integration, a reviewer noted 17 checks passed and 9 were skipped, while the merge queue recorded 26 passing checks before commit fc36aef landed.2