Skip to content

fix(client): serialize headers in APIError.toJSON() so rate-limit headers are visible#1837

Closed
anishesg wants to merge 1 commit intoopenai:masterfrom
anishesg:fix/ph-issue-1477
Closed

fix(client): serialize headers in APIError.toJSON() so rate-limit headers are visible#1837
anishesg wants to merge 1 commit intoopenai:masterfrom
anishesg:fix/ph-issue-1477

Conversation

@anishesg
Copy link
Copy Markdown

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

Changes being requested

When a 429 (or any non-2xx) response is received, the SDK throws an APIError whose headers property is a native Headers instance. Because Headers has no toJSON method, calling JSON.stringify(error) produces "headers": {}, hiding all headers — including the x-ratelimit-reset-requests, x-ratelimit-reset-tokens, and related headers developers need for custom retry logic.

The fix adds a toJSON() method to APIError in src/core/error.ts that converts this.headers to a plain object via Object.fromEntries(this.headers.entries()). The headers instance itself is unchanged, so error.headers.get('x-ratelimit-reset-requests') continues to work as before; the change only affects serialisation.

Additional context & links

Fixes #1477

…ders are visible

- [x] I understand that this repository is auto-generated and my pull request may not be merged

Signed-off-by: anish k <ak8686@princeton.edu>
@anishesg anishesg requested a review from a team as a code owner April 23, 2026 10:59
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be7d8baeea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/core/error.ts
@anishesg
Copy link
Copy Markdown
Author

Closing — auto-generated SDK repo. The team regenerates from API specs so external PRs rarely land.

@anishesg anishesg closed this Apr 25, 2026
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.

Unable to access rate limit headers due to exceptions

1 participant