Skip to content
RelationsAI
Error codes

invalid_json

HTTP status
400
Retry
No
Execution
Nothing was done
Admin needed
No

Invalid JSON body. The body could not be parsed as a JSON document, so the request was not processed.

What it means

The API returns HTTP 400 with error.code set to invalid_json. The default message is: "The request body is not valid JSON."

Common causes

  • A trailing comma, an unquoted key or a truncated body.
  • A form-encoded body sent with a JSON content type.

How to identify it

Check the response status (400) and error.code (invalid_json). Branch on error.code, not on the message text: messages can be reworded, codes do not change within v1. Log error.request_id (also sent as the X-Request-Id header) so support can find the request.

How to fix it

  • Serialize the body with a JSON library rather than by string concatenation.
  • Send Content-Type: application/json.

Retry guidance

Sending the request unchanged fails the same way. Fix the cause first (see How to fix it), then send it again.

Did anything happen?

This request was refused before any call was placed and before anything was charged.

Idempotency

Nothing was done. Fix the request and send it again; if you sent an Idempotency-Key you may reuse it, because a refused request is not stored.

Who can fix it

The developer who sends the request can fix it; no administrator action is normally needed.

When to contact support

If the error persists after the steps above, contact support@relationsai.com. See Support for what to include (the request_id, the time in UTC, the operation, and whether you used a test or live key) and what never to send (API keys, Authorization headers, webhook signing secrets, recording links, transcripts or customer data).

Example error response

JSONJSON
{ "error": { "code": "invalid_json", "message": "The request body is not valid JSON.", "details": {}, "request_id": "req_hfrm5ytbbxqqrscd33wexrdr", "retry": "no", "doc_url": "https://docs.relationsai.com/errors/invalid_json" } }

Incorrect and corrected request

Incorrect: The body was built by string concatenation and ends with a trailing comma, which JSON does not allow.

Text
POST /v1/calls Authorization: Bearer rai_test_YOUR_TEST_KEY Content-Type: application/json {"agent_id": "agent_4Nf8Gt2Hx6Jq9Lm3Pv7Rs1", "to": "+12025550100",}

Corrected: The same request serialized with a JSON library.

Text
POST /v1/calls Authorization: Bearer rai_test_YOUR_TEST_KEY Content-Type: application/json { "agent_id": "agent_4Nf8Gt2Hx6Jq9Lm3Pv7Rs1", "to": "+12025550100" }

Operations that can return this error

See all codes in the error-code reference.