Skip to content

fix: coerce numeric API error codes to strings - #3543

Open
nightcityblade wants to merge 1 commit into
openai:mainfrom
nightcityblade:fix/issue-3531
Open

fix: coerce numeric API error codes to strings#3543
nightcityblade wants to merge 1 commit into
openai:mainfrom
nightcityblade:fix/issue-3531

Conversation

@nightcityblade

Copy link
Copy Markdown
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Normalize non-null API error codes to strings when constructing APIError, so the runtime value matches the documented str | None contract even when an endpoint or compatible gateway returns a numeric JSON code.

Add a focused regression test covering a numeric 404 error code.

Fixes #3531

Additional context & links

Validation:

  • .venv/bin/python -m pytest tests/test_exceptions.py -q
  • .venv/bin/ruff check src/openai/_exceptions.py tests/test_exceptions.py
  • .venv/bin/ruff format --check src/openai/_exceptions.py tests/test_exceptions.py
  • .venv/bin/mypy src/openai/_exceptions.py

@nightcityblade
nightcityblade requested a review from a team as a code owner July 26, 2026 15:53

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the error-construction boundary and regression coverage. Normalizing every non-null wire value to str keeps the runtime behavior aligned with the existing str | None public contract while preserving None, and the focused test covers the observed numeric-code case. The full repository lint/typecheck/import gate plus focused tests and formatting checks are clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

APIStatusError.code is typed Optional[str] but can be an int at runtime

2 participants