Skip to content
Rush Commerce
Software & Dev3 min read

OpenAI Python SDK 3.42: agent compaction and scoped API keys

OpenAI Python SDK 3.42.0 adds agent context compaction, session review and per-request API key scoping. Upgrade multi-tenant code first, then tune compaction.

OpenAI shipped OpenAI Python SDK 3.42.0 on October 31. The headline is agent context compaction: you can now pick whether a long-running agent summarizes its history in the background or blocks while it does. The line we'd act on first is lower in the changelog. If your app picks an API key per customer at request time, this release changes how that key stays attached to its request.

What actually happened

Per the v3.42.0 release notes, the release adds ten features and one fix. The ones that matter for agent builders:

  • Context compaction settings. PR #4209 adds compaction config to beta agents, sessions and scheduled agent runs. An async_ parameter picks background or blocking compaction, and you can read back the effective settings.
  • Session review and tool settings. PR #4217 lets you pass review settings when you create or update a session, and replace a session's tools through agent.tools on update.
  • Callable API keys scoped per request. PR #4216 keeps each callable API-key result with its own HTTP request or WebSocket connection, including Azure key auth. In the PR's words, the change keeps "overlapping requests from using another request's callable API-key result."
  • Also in the box: experimental agent time awareness, organization external key management, SIP DTMF commands for voice, and better WebSocket recovery.

Public signatures stay compatible. The PR warns that private _auth_headers overrides may need updates, and overrides of _configure_realtime must accept a new api_key keyword.

Why the OpenAI Python SDK update matters for your business

Multi-tenant code: upgrade this week. If you pass a function as api_key so each client or store bills to its own key, and you run requests concurrently, read PR #4216 and move to 3.42.0. Then check your usage dashboard per key for anything that looks like cross-billing. If you subclassed the client and touched private auth methods, test before you deploy.

Compaction is a cost and correctness dial. Background compaction keeps the agent responsive. Blocking compaction waits, so the next step sees a clean summary. For a support or order-status agent that runs for hours, compaction decides what the agent "remembers." Pick the mode on purpose, log what got summarized, and test that order numbers and customer names survive.

Session review is your approval hook. Use it for any agent that sends, refunds or edits. A review step costs one click; an unreviewed refund costs real money.

Pin the version. Beta agent APIs move fast. Lock openai==3.42.0 in your requirements and upgrade on a schedule, not by accident.

Key takeaways

  • OpenAI Python SDK 3.42.0 shipped October 31 with agent context compaction for agents, sessions and scheduled runs
  • An async_ parameter picks background or blocking compaction
  • Callable API keys now stay bound to their own request or WebSocket connection, Azure included
  • Custom overrides of private auth methods may need updates
  • Session review settings give you an approval step for agents that act
  • Pin the SDK version and upgrade on purpose

Running one OpenAI integration for many customers? We build multi-tenant agent backends with per-client keys, pinned SDKs and approval steps before anything spends money. See how we build agent systems.

Sources: openai-python v3.42.0 release, PR #4209, PR #4216, PR #4217.

  • #openai
  • #python-sdk
  • #ai-agents
  • #context-compaction
  • #api-keys
TR

Tommy Rush — Founder, Rush Commerce

Operator turned builder. 15+ years running operations — now shipping the systems businesses run on. More

Get The Rush Report weekly — one email, zero fluff.