openai.SyncAPIClient.request and openai.AsyncAPIClient.request — private transport-layer methods that every high-level OpenAI API call passes through.
Requirements
| Requirement | Version |
|---|---|
openai SDK | ≥ 1.76.0 |
| Python | ≥ 3.9 |
Why 1.76.0? TheInstall or upgrade:request()signature changed across SDK versions. Prior to 1.76.0 it included aremaining_retriesparameter that our replacement does not accept, creating a potentialTypeError. Version 1.76.0 removed that parameter, making the signature an exact match for the patched version. Installing an older SDK will trigger aUserWarningat runtime.
What gets patched
Chat completions (non-streaming)
Chat completions (streaming)
For streaming, actguard automatically injectsstream_options={"include_usage": true} into chat completion requests so the final chunk includes usage data. This injection only applies to /chat/completions endpoints and is harmless to existing code.
Async client
Responses API
The Responses API is also tracked. Usage is read from theresponse.completed event chunk when streaming, or from response.usage for non-streaming calls.
Version warning
If you have an older OpenAI SDK installed, actguard emits a warning whenpatch_openai() runs (i.e., the first time you enter a BudgetGuard):
