What this thread does
Do first: Upgrade OpenAI Python SDK to v3.14.0 or a later release containing this fix.
Symptom
AttributeError: 'int' object has no attribute 'strip' appears when downstream error handling calls .strip() on a numeric APIStatusError.code. Reported by emiliyanpavlov. IgorGanapolsky and nightcityblade commented on the issue.
Cause
The loose deserializer could keep a numeric API error code despite the public string-or-null annotation. The merged change converts non-null codes to strings; the original value remains in the error body.
Fix
1. Upgrade OpenAI Python SDK to v3.14.0 or a later release containing this fix; compare exc.code with strings rather than numbers. 2. The change is described in the merged PR.
As of November 2026, the stable release named in the source is v3.58.0 (released 2026-11-23). The implementation at that tag retains string conversion of non-null error codes.
Fixed in
First stable release v3.14.0 (released 2026-09-14). PR #3532, by Sanjays2402, merged 2026-09-14.
If it still fails
- The original HTTP error is not removed. For older versions, the maintainer gives
code = str(exc.code) if exc.code is not None else Nonebefore string operations. After upgrading, useexc.code == "404"rather than a numeric comparison, or inspectexc.bodyfor the original value.
Not for: MCP Python SDK str has no message during unpickling; see mcp-python-sdk-str-no-message-unpickling.
Sources
- [
APIStatusError.codeis typedOptional[str]but can be anintat runtime](https://github.com/openai/openai-python/issues/3531), emiliyanpavlov, opened 2026-07-23; closed as completed on 2026-09-14: "APIStatusError.codeis annotatedOptional[str]`" - Comment by IgorGanapolsky, IgorGanapolsky, 2026-07-24; parent issue closed as completed on 2026-09-14.
- Comment by nightcityblade, nightcityblade, 2026-07-26; parent issue closed as completed on 2026-09-14.
- fix: normalize API error codes to strings, Sanjays2402, merged 2026-09-14 (closed).
- v3.14.0, published 2026-09-14.
- v3.58.0, published 2026-11-23.
- src/openai/_exceptions.py at v3.58.0.
- Maintainer comment by marcuswood-oai, 2026-09-14; parent issue closed as completed on 2026-09-14.
Checked
2026-11-24; read the issue and comment API records, merged PR, release records, and src/openai/_exceptions.py at v3.58.0; no command was run.
Started from a post by @emiliyanpavlov, packaged by the editor. Original post