Replies: 1 comment
-
|
Yes, for normal server usage I would create the The main reason is that the Python SDK uses HTTP clients under the hood. The current SDK docs describe the sync and async clients as powered by Practical pattern: from openai import OpenAI
client = OpenAI()
def handle_request(prompt: str):
return client.responses.create(
model="gpt-5.5",
input=prompt,
)A few caveats:
Docs: So the short version is: reuse a module-level client for the same API configuration; avoid per-request client construction unless each request genuinely needs a different client configuration. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have recently captured a profile for my service and I see that instantiating Openai client consumes are around 16% of CPU. In order to reduce this overhead I am hoping if I can instantiate the client once at the module level and reuse it across all requests. Is this possible. If yes, are there any cons of doing so?
Beta Was this translation helpful? Give feedback.
All reactions