Skip to content

fix: normalize API error codes to strings#3532

Open
Sanjays2402 wants to merge 1 commit into
openai:mainfrom
Sanjays2402:fix/api-error-code-type
Open

fix: normalize API error codes to strings#3532
Sanjays2402 wants to merge 1 commit into
openai:mainfrom
Sanjays2402:fix/api-error-code-type

Conversation

@Sanjays2402

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 so runtime behavior matches the public str | None annotation. A regression test covers numeric error payloads.

Additional context & links

Closes #3531

Numeric API error codes currently contradict the public string annotation. Normalize non-null values and cover the runtime behavior with a regression test.
Copilot AI review requested due to automatic review settings July 23, 2026 07:40
@Sanjays2402
Sanjays2402 requested a review from a team as a code owner July 23, 2026 07:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Normalizes APIError.code to always be a string (when present) so runtime behavior matches the public str | None type annotation and avoids downstream type surprises when servers return numeric error codes.

Changes:

  • Coerce non-None error.code values to str during APIError construction.
  • Add a regression test covering integer error codes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/openai/_exceptions.py Ensures APIError.code is normalized to str when present.
tests/test_client.py Adds a regression test asserting integer error codes become strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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