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
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

1 participant