Fix error parsing for text/plain OpenAI responses#723
Closed
infjdeepak wants to merge 1 commit into
Closed
Conversation
d964f42 to
4d1746d
Compare
Collaborator
|
Thanks!! I really thought I squashed this for good with: #643 Do you have a sample payload of the plain text one? Trying to see if it's an error or the payload wrongly typed. Additionally what the http status code is. We would want to add a test for what you saw as methods are handled differently based on type of return (json, mixed, etc) |
|
Here’s a plain text response I received: * Host api.openai.com:443 was resolved.
* IPv6: (none)
* IPv4: 162.159.140.245, 172.66.0.243
* Trying 162.159.140.245:443...
* Connected to api.openai.com (162.159.140.245) port 443
* ALPN: curl offers http/1.1
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / X25519 / id-ecPublicKey
* ALPN: server accepted http/1.1
* Server certificate:
* subject: CN=api.openai.com
* start date: Nov 14 00:26:50 2025 GMT
* expire date: Feb 12 01:26:48 2026 GMT
* subjectAltName: host "api.openai.com" matched cert's "api.openai.com"
* issuer: C=US; O=Google Trust Services; CN=WE1
* SSL certificate verify ok.
* Certificate level 0: Public key type EC/prime256v1 (256/128 Bits/secBits), signed using ecdsa-with-SHA256
* Certificate level 1: Public key type EC/prime256v1 (256/128 Bits/secBits), signed using ecdsa-with-SHA384
* Certificate level 2: Public key type EC/secp384r1 (384/192 Bits/secBits), signed using ecdsa-with-SHA384
* using HTTP/1.x
> POST /v1/embeddings HTTP/1.1
Host: api.openai.com
User-Agent: GuzzleHttp/7
Authorization: Bearer sk-invalid-key
Content-Type: application/json
Content-Length: 85
* old SSL session ID is stale, removing
< HTTP/1.1 401 Unauthorized
< Date: Thu, 11 Dec 2025 10:38:16 GMT
< Content-Type: text/plain
< Content-Length: 260
< Connection: keep-alive
< x-openai-ide-error-code: invalid_api_key
< x-openai-authorization-error: 401
< x-error-json: ewogICJlcnJvciI6IHsKICAgICJtZXNzYWdlIjogIkluY29ycmVjdCBBUEkga2V5IHByb3ZpZGVkOiBzay1pbnZhbCoqLWtleS4gWW91IGNhbiBmaW5kIHlvdXIgQVBJIGtleSBhdCBodHRwczovL3BsYXRmb3JtLm9wZW5haS5jb20vYWNjb3VudC9hcGkta2V5cy4iLAogICAgInR5cGUiOiAiaW52YWxpZF9yZXF1ZXN0X2Vycm9yIiwKICAgICJjb2RlIjogImludmFsaWRfYXBpX2tleSIsCiAgICAicGFyYW0iOiBudWxsCiAgfSwKICAic3RhdHVzIjogNDAxCn0=
< x-request-id: req_7395a80aa5f242fb9c37413bff232dc8
< x-datadog-trace-id: 17930003501829985854
< x-datadog-parent-id: 9435506756333248072
< x-datadog-sampling-priority: 0
< x-openai-internal-caller: unknown_through_ide
< x-envoy-upstream-service-time: 13
< x-openai-proxy-wasm: v0.1
< cf-cache-status: DYNAMIC
< Set-Cookie: __cf_bm=D17mff4GC0psLB03NqziY9O_p.cqQdFUWj3LLY3v9YY-1765449496-1.0.1.1-MQXflU39EvijLirKNa062tAfb0mso6Pyx2._Q1HTUDL7ytpJDQp2SbHa36ymzUd94xwwEHheF68sAYDI80LBMtAcGCtVcOE0gyQVHjAryaw; path=/; expires=Thu, 11-Dec-25 11:08:16 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< X-Content-Type-Options: nosniff
< Set-Cookie: _cfuvid=6pf9oThr3mq.JuIsZfqJvAggmDQmmBTu7ww3KXEZCfQ-1765449496677-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
< Server: cloudflare
< CF-RAY: 9ac459f8793f91b5-DEL
< alt-svc: h3=":443"; ma=86400
<
* Connection #0 to host api.openai.com left intact
Caught Exception: Incorrect API key provided: sk-inval**-key. You can find your API key at https://platform.openai.com/account/api-keys.Payload: $client = OpenAI::client($yourApiKey);
try {
$response = $client->embeddings()->create([
'model' => 'text-embedding-3-small',
'input' => 'The food was delicious and the waiter...',
]);
} catch (\Exception $e) {
echo "test error" . $e->getMessage();
} |
Collaborator
|
Interesting. Let me mess with this is a bit. I wonder if we accept |
This was referenced Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
Description:
OpenAI sometimes returns error payloads with Content-Type: text/plain.
The current ErrorResponseHandler ignores these responses, preventing
exceptions from being parsed correctly.
This patch updates the Content-Type check to allow both JSON and text/plain
content types, enabling consistent error handling.
The fix is backward compatible and does not change behavior for valid JSON
responses.
For example, calling
embeddings()->create()with an invalid request results in the following runtime error instead of a cleanErrorException:Produces:
Related:
N/A