Why am I getting 400 errors from nginx?

When I make an API call from my code using the gpt-4 model like so:

	"frequency_penalty": 0,
	"messages": [{
		"content": "...",
		"role": "user"
	"model": "gpt-4",
	"presence_penalty": 0,
	"temperature": 0.1

I get the following response:

<head><title>400 Bad Request</title></head>
<center><h1>400 Bad Request</h1></center>

If I make the same (so far as I can tell) call from the command line, I get an actual response. If I make the call with gpt-3.5-turbo I get an actual response. I’m nowhere near the token limit on these calls.

The interesting thing is the error is coming from nginx, and I’m getting the error response in HTML (not the JSON error response body I’d get if I had exceeded the token limit, for example.)

Does anyone know what’s going on?

1 Like

Today it’s not happening. So the answer was, “a server-side bug”.

Uh. Well, not exactly it turns out. In fact, not at all. What was happening was that we were getting a 429 (hitting the rate limit) and then backing off before retrying. But we were retrying using the same Go http.Request object, which is apparently not allowed and due to that an empty body ended up being sent and OpenAI was quite rightly responding with a 400.

I hope this helps someone.

1 Like

(post deleted by author)

Did you just copy-paste my post into ChatGPT and post the output? Because it doesn’t look like you read it.

1 Like