TheoKanning / openai-java

OpenAI Api Client in Java
MIT License
4.68k stars 1.16k forks source link

[Urgent] Unsupported Content Type `application/json; charset=UTF-8` #465

Open benedictstrube opened 4 months ago

benedictstrube commented 4 months ago

I am getting this error when attempting to execute createThread on an OpenAiService instance.

Unsupported content type: 'application/json; charset=UTF-8'. This API method only accepts 'application/json' requests, but you specified the header 'Content-Type: application/json; charset=UTF-8'. Please try again with a supported content type.

Seems like OpenAI changed something internally. Not tested on other requests yet, but if my assumption is correct, that seems quite urgent. As of now, all our requests to OpenAI are failing.

benedictstrube commented 4 months ago

Attached a PR to fix this for the Assistants API, as those are the requests, that are failing right now without setting the Content-Type explicitly to application/json. However, having a look at the documentation, it seems like setting the Content-Type for all requests is the correct way:

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
     "model": "gpt-3.5-turbo",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
   }'

(example request from their documentation)

propertius commented 4 months ago

Hi @benedictstrube. I was having the same issue but out of nowhere it seems to be working again.

benedictstrube commented 4 months ago

Thanks @propertius for the heads up! I already posted a PR that sets the Content Type explicitly according to specification. I think it still might be a good idea to merge this, as this might happen again anytime in the future, if OpenAI decides to be restrictive regarding that. 😄