Skip to content

Commit 4d1746d

Browse files
infjdeepakidsdeepak
authored andcommitted
Fix: allow handling of text/plain error responses from OpenAI
1 parent 5092eca commit 4d1746d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Transporters/HttpTransporter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ private function throwIfJsonError(ResponseInterface $response, string|ResponseIn
163163
return;
164164
}
165165

166-
if (! str_contains($response->getHeaderLine('Content-Type'), ContentType::JSON->value)) {
166+
$contentType = $response->getHeaderLine('Content-Type');
167+
168+
// Allow JSON or plain text containing JSON (OpenAI often sends text/plain for errors)
169+
if (
170+
! str_contains($contentType, ContentType::JSON->value) &&
171+
! str_contains($contentType, ContentType::TEXT_PLAIN->value)
172+
) {
167173
return;
168174
}
169175

0 commit comments

Comments
 (0)