We are getting exactly the same issue, we are obviously send the Content-Type: application/json and the body is json encoded array, yet we get a response saying we are sending application/x-www-form-urlencoded nuts!
Why RESP API returns " Error 400. The request has an invalid header name"?
I'm Trying to access Azure's OpenAI chat completions REST API with SAS proc http. Model is gpt-4 (0613). Access url I'm using is:
https://RESOURSE.openai.azure.com/openai/deployments/DEPLOYMENT/chat/completions?api-version=2023-07-01-preview
Without headers answer from Azure is:
"{"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}"
After adding the key header the answer is:
{
"error": {
"message": "Invalid Content-Type header (application/x-www-form-urlencoded), expected application/json. (HINT: If you're using curl, you can pass -H 'Content-Type: application/json')",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
So far so good, I guess.
Then I add header according to the error message:
Content-Type: application/json
And the answer is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP </p>
</BODY></HTML>
If I add some random header instead of Content-Type, just so I have two headers:
api-key:key
connection: keep-alive
Answer is same as with just the key:
{
"error": {
"message": "Invalid Content-Type header (application/x-www-form-urlencoded), expected application/json. (HINT: If you're using curl, you can pass -H 'Content-Type: application/json')",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
All the example codes and even the error message says I should add 'Content-Type: application/json'.
But why that gives the: " Error 400. The request has an invalid header name."?
I'm not even sure if message body is correct:
'{
"role": "user",
"content": "Say hi!"
}'
But the error is about the headers, so I don't think the message body is the reason for invalid header -error.