Checks
Strands Version
1.11.0
Python Version
3.11.13
Operating System
15.7.1
Installation Method
pip
Steps to Reproduce
import asyncio
import httpx
from strands import Agent
from strands.models.openai import OpenAIModel
client = httpx.AsyncClient()
agent = Agent(
model=OpenAIModel(
model_id="gpt-4o-mini-2024-07-18",
client_args={
"api_key": "your-openai-key",
"http_client": client
}
)
)
async def chat(prompt: str):
result = await agent.invoke_async(prompt)
print(result)
async def main():
await chat("this works")
await chat("this doesn't work")
if __name__ == "__main__":
asyncio.run(main())
Expected Behavior
As per the documentation, I should be able to pass any parameters supported by the OpenAI client in the constructor of the OpenAIModel.
That should include the http_client parameter, that let me pass a custom HTTPx client to the OpenAI client, as documented in here.
Actual Behavior
When passing a custom HTTPx client, only the first request will pass through, because that client will be automatically closed by Strands right after processing it. Subsequent requests fails.
Additional Context
No response
Possible Solution
No response
Related Issues
No response
Checks
Strands Version
1.11.0
Python Version
3.11.13
Operating System
15.7.1
Installation Method
pip
Steps to Reproduce
Expected Behavior
As per the documentation, I should be able to pass any parameters supported by the OpenAI client in the constructor of the
OpenAIModel.That should include the
http_clientparameter, that let me pass a custom HTTPx client to the OpenAI client, as documented in here.Actual Behavior
When passing a custom HTTPx client, only the first request will pass through, because that client will be automatically closed by Strands right after processing it. Subsequent requests fails.
Additional Context
No response
Possible Solution
No response
Related Issues
No response