openai-php / openai-php/client

[Bug]: UnserializableResponse when Files::retrieve() returns HTML 503

Open
#678 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
5.8k
Forks
679
Avg merge
19m
Merged PRs (30d)
2

Description

Description

When calling Files::retrieve($fileId) via the PHP SDK, intermittent 503 responses from the API edge (HTML “503 Service Temporarily Unavailable” from OpenAI's nginx) cause the transporter to attempt json_decode() on the HTML body. This triggers:

OpenAI\Exceptions\UnserializableResponse
Syntax error
vendor/openai-php/client/src/Transporters/HttpTransporter.php:62

Because the response isn’t JSON, the SDK error is misleading and hides the actual HTTP status/body. This makes handling/retrying 5xx conditions difficult.

Steps To Reproduce
  1. Environment (example):

    • PHP: 8.x
    • SDK: openai-php/client (latest at time of issue)
  2. Code (minimal):

    $fileId = 'file_XXXXXXXXXXXX';
    
    // Repro: call retrieve on an existing file id
    $file = $client->files()->retrieve($fileId);
    
  3. Intermittently, the API responds with a 503 HTML page (edge/nginx). If you dump the raw contents in the transporter you’ll see something like:

    <html>
    <head><title>503 Service Temporarily Unavailable</title></head>
    <body>
    <center><h1>503 Service Temporarily Unavailable</h1></center>
    <hr><center>nginx</center>
    </body>
    </html>
    
  4. The SDK attempts to json_decode() this HTML and throws:

    OpenAI\Exceptions\UnserializableResponse (Syntax error)
    at vendor/openai-php/client/src/Transporters/HttpTransporter.php:62
    
OpenAI PHP Client Version

v0.16.0

PHP Version

8.4.6

Notes
  • The error originates here:

    • vendor/openai-php/client/src/Transporters/HttpTransporter.php:62
    • The transporter always tries to decode the body as JSON before considering that it might be an HTML error page.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with vendor/openai-php/client/src/Transporters/HttpTransporter.php:62 and trace how non-JSON HTTP responses are decoded and converted into exceptions. Reproduce the HTML 503 response described in the issue, then verify that the resulting error preserves the HTTP failure details instead of reporting only a JSON syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.