OpenAIResponsesModel: accept a pre-configured client like OpenAIModel does
OpenAIModel accepts an optional client ("Pre-configured OpenAI-compatible client to reuse across requests", strands-py/src/strands/models/openai.py). OpenAIResponsesModel has no such parameter: each request creates a new openai.AsyncOpenAI(**client_args) in an async with block (strands-py/src/strands/models/openai_responses.py, around lines 278, 332 and 526), so every model call opens a new TCP + TLS connection and closes it.
Impact
- An agent loop with several model rounds per invocation (we see 4-7 rounds for a diagnostic report) pays a new handshake each round, about 0.1-0.3 s.
- On AWS Lambda, warm invocations can never reuse a pooled connection.
- Custom HTTP settings (proxy, timeouts, connection limits) that users can set on
OpenAIModelthrough its client are not possible here.
Proposal
Mirror OpenAIModel: add client: Client | None = None to OpenAIResponsesModel.__init__. When a client is given, use it as-is and do not close it (the caller owns it). When it is not given, keep today's behaviour. The _get_client() pattern in OpenAIModel fits directly.
I am happy to send a PR.
@dajiaohuang are you still planning to take this? If not, I'm happy to pick it up: mirror OpenAIModel's client parameter and _get_client context manager, so an injected client is reused across requests and never closed by the model, and client / client_args are mutually exclusive. I'll hold off for a couple of days so we don't duplicate work.
Hello @sidxh ! Are you still planning to take this? If not, I'd love to pick this up
client= for OpenAIResponsesModel landed on main in #5914 (not released yet), and #4967 covers the remaining connection reuse, so no other PR is needed here.