-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAI API integration fails with Brotli compressed responses #2345
Comments
@bullshit Seems to be a case that brotli compression is not supported through spring rest client although Apache Http client 5.x supports it. spring-ai/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java Lines 206 to 207 in 092bbae
Adding this might help after L206 Disclaimer : I've recently discovered this repository, so please take this as an amateur suggestion |
… issues Explicitly set Accept-Encoding header to "gzip, deflate" to prevent OpenAI API from returning Brotli-compressed responses that cannot be properly processed by the client. This resolves JSON parsing errors that occur when trying to handle responses with Content-Encoding: br. Fixes spring-projects#2345
… issues Explicitly set Accept-Encoding header to "gzip, deflate" to prevent OpenAI API from returning Brotli-compressed responses that cannot be properly processed by the client. This resolves JSON parsing errors that occur when trying to handle responses with Content-Encoding: br. Fixes spring-projects#2345 Signed-off-by: bullshit <coding@ow-software.pl>
@tarunkalra it did some testing and you are right. I thought about adding the brotli decomporession instead but on the other hand, is not the right place for that in this project. Let's hope somebody merges the changes or just adds the changes by them self (the CLA signing tool is down :/ ) |
… issues Explicitly set Accept-Encoding header to "gzip, deflate" to prevent OpenAI API from returning Brotli-compressed responses that cannot be properly processed by the client. This resolves JSON parsing errors that occur when trying to handle responses with Content-Encoding: br. Fixes spring-projects#2345 Signed-off-by: bullshit <coding@ow-software.pl>
Bug description
When using Spring-AI to communicate with OpenAI's API, the client fails to properly decode responses that use Brotli compression (
Content-Encoding: br
), resulting in a JSON parsing error. The HTTP response is received successfully (200 OK), but the parser encounters an "Unexpected end-of-input" error.Environment
Steps to reproduce
Expected behavior
The client should successfully decode the response from OpenAI, including responses with Brotli compression, and return the completed prompt content.
Minimal Complete Reproducible example
The above test reproduces the issue. It fails with the following exception:
Further in the logs, i can see the response headers contain:
The root issue appears to be that the Spring RestClient cannot properly decompress Brotli-encoded content before attempting to parse the JSON, resulting in a malformed input to the JSON parser.
This issue occurs with the standard Spring Boot RestClient setup. The HTTP exchange completes successfully, but the JSON cannot be properly decoded after receiving the Brotli-compressed response.
full log
The text was updated successfully, but these errors were encountered: