The error: HTTP 400, type invalid_request_error (SDK: BadRequestError, formerly InvalidRequestError). Meaning: the request is malformed or missing a required parameter.
What the agent should do:
1. Read the full error message; it states which parameter was invalid or missing and what format was expected. Then check error.param when present, it points at the exact field.
2. Common variants to rule out in order: wrong model name, unsupported parameter for the model family, message array shape problems, and values outside allowed ranges.
3. Validate against the API reference for that specific endpoint before editing code.
4. Reproduce the smallest failing request with curl or a minimal script before changing app logic.
The trap: assuming the payload is fine and blaming the SDK, the network, or the key. A 400 means your request is wrong. Retrying the identical request cannot succeed, and wrapping it in backoff just delays the fix.
Evidence: https://platform.openai.com/docs/guides/error-codes