Genace

INVALID_JSON: Request body is not valid JSON

HTTP 400 INVALID_JSON
{
  "error": {
    "type": "invalid_param",
    "code": "INVALID_JSON",
    "message": "Request body is not valid JSON"
  }
}

The body could not be parsed at all. Nothing about your parameters has been looked at yet, so this error never names a field — there was no object to find one in.

The four usual causes

1. Shell quoting. By far the most common. Single quotes inside a single-quoted shell string terminate it early:

# broken — the shell closes the string at "it's"
curl -d '{"prompt":"a cat, it's raining"}' ...

# fine
curl -d '{"prompt":"a cat, it is raining"}' ...

Use a heredoc or a file when prompts contain apostrophes:

curl -X POST https://genace.ai/api/v1/video/generations \
  -H "Authorization: Bearer $GENACE_API_KEY" \
  -H "Content-Type: application/json" \
  -d @payload.json

2. An empty body. A POST with no -d at all, or a client that dropped the body on a redirect. Worth checking if the same code worked yesterday.

3. Unescaped newlines in a prompt. Multi-line prompts need \n inside the JSON string, not literal line breaks. Most JSON libraries handle this; string concatenation does not.

4. Trailing commas. Valid in JavaScript object literals, invalid in JSON. This one survives code review surprisingly often.

Check the Content-Type too

Content-Type: application/json

Some HTTP clients default to application/x-www-form-urlencoded and will serialise your object as a form body, which is then not JSON.

Isolating it

Validate the payload independently before blaming the API:

printf '%s' "$PAYLOAD" | python -m json.tool

If that fails, the problem is entirely on your side and the API is reporting it accurately.

Not the same as INVALID_PARAM

INVALID_JSONINVALID_PARAM
Body parsednoyes
Names a fieldnoyes, in param
What to checkquoting, encoding, Content-Typethe value you sent

If you are getting INVALID_PARAM, your JSON is fine and a specific value is not.

Where these facts come from

  • codebase: src/app/api/v1/{video,images}/generations/route.ts — body parsing