Skip to content

Conversation

@Limitless2023
Copy link

Summary

Fixes #1734

When an OpenAI-compatible API returns error information in fields other than error (e.g. detail or message), the Node client currently reports 422 status code (no body) instead of showing the actual error content. This differs from the Python client, which falls back to the entire response body.

Changes

  • src/core/error.ts: In APIError.generate(), when errorResponse.error is undefined, fall back to errorResponse itself (the entire parsed JSON body) instead of passing undefined to the error constructor. This is a one-line change: ?? errorResponse.
  • tests/error.test.ts: Added tests covering:
    • Standard OpenAI error response (with error field) — still works as before
    • Non-standard response with detail field — now shows the error content
    • Non-standard response with message field — now shows the error content
    • Truly empty response — still shows (no body)
    • Raw text fallback — still works as before

Before / After

Before: An error response like {"detail": "422: The model gpt-5-gibberish does not exist."} would produce:

UnprocessableEntityError: 422 status code (no body)

After: The same response now produces:

UnprocessableEntityError: 422 {"detail": "422: The model gpt-5-gibberish does not exist."}

This matches the Python client's behavior of falling back to the full response body when the error field is absent.

When an OpenAI-compatible API returns error information in fields other
than 'error' (e.g. 'detail' or 'message'), the client now falls back to
using the entire response body instead of reporting '(no body)'.

This aligns behavior with the Python client, which already falls back to
the full response body when the 'error' field is absent.

Fixes openai#1734
@Limitless2023 Limitless2023 requested a review from a team as a code owner February 11, 2026 12:44
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.

The node.js client only reads errors from the "error" field of a response, with no fallback if it doesn't exist

2 participants