Fixing 400 "Request body is not valid JSON"
These 400s mean the API could not read the request body, or the body was missing something it needs before it can do anything else.
The messages you can get
Request body is not valid JSON.The body did not parse, or was the literalnull.Field "model" is required.The JSON parsed but had nomodelstring.- On
/v1/messages:messages: Field required, and must be an array.whenmessagesis missing or not a list. - On
/v1/responses:input: Field required, and must be a string or an array of items.
HTTP 400
{
"error": {
"message": "Request body is not valid JSON.",
"type": "invalid_request_error",
"code": null,
"param": null
}
}Common causes
- Shell quoting. In Windows cmd, single quotes do not quote, so a curl
-d '{...}'arrives broken. Use a file with-d @body.json. - Sending form data. Posting a dict as form fields instead of JSON (for example
requests.post(url, data=payload)in Python) sends no JSON. Usejson=payload. - String building. A message containing a quote or newline breaks hand-built JSON. Serialize with a JSON library.
- Empty body. A request sent before the payload was attached.
How it shows up
SillyTavern builds valid JSON itself, so you will rarely see these there unless a proxy or extension rewrites the body. In SDKs the body is always serialized for you; seeing these errors usually means hand-written HTTP code. The OpenAI SDKs raise BadRequestError and do not retry.
Step by step fix
- Print the exact body your code sends.
- Run it through a JSON validator, or parse it back with your language's JSON library.
- Check it has
modelas a string andmessagesas an array of objects withroleandcontent. - Set
Content-Type: application/json. - Test the minimal body:
{"model":"outlaw-1","messages":[{"role":"user","content":"hi"}]}The docs have working examples for curl, Python and Node.
Telling it apart from similar errors
Key problems are checked first, so a request with both a bad key and bad JSON shows the 401. A model id that is present but wrong is model_not_found. Note that on /v1/chat/completions the API does not validate the rest of the body itself; a malformed field the model rejects (other than size or images) comes back as a 503 Model overloaded, so if a 503 never clears, check your body.
FAQ
Is a 400 charged?
No. These are refused before any model call.
Why did I get a 401 instead of the JSON error?
The key is checked before the body is read. Fix the key first, then the body.