SalpXXAPI News
Beginner Q&A 3 min read

Beginner Q&A: Why does my client fail to parse JSON after HTTP 204?

A 204 is a success without a response body. Check what the endpoint promises and distinguish valid empty success from a broken response.

If an endpoint documents 204 No Content for success, do not call response.json() on that response. A 204 is not a receipt telling you to check on a job later. It is a successful response with no body. A JSON parsing error means the client tried to decode empty input, not necessarily that the remote action failed. Conversely, an unexpected 204 from a generation endpoint that promises text is a contract violation, not a successful blank generation. 1

Q: How is a 204 different from empty JSON?

No body and a body of {} are different. The latter is a valid JSON object: it parses, and then you can check its keys. With a 204 there is nothing to decode. Some update or delete operations return only a success status. You can still read headers such as ETag separately if provided; there is no need to invent a JSON object. A 204 cannot contain a body or carry a Content-Length header. 1

Suppose a management endpoint documents 204 after deleting a test configuration. The application can remove the row from the list and show “Deleted.” A different endpoint that creates a job and promises a JSON job ID cannot share an “empty is fine” rule. Both use HTTP, but the two operations promise different results.

Q: How should a client handle this without hiding errors?

  1. Start with the method and endpoint. Specify the success status, body expectation, and expected media type in the relevant handler. Do not send every 2xx response through one JSON parser.
  1. Accept 204 only where documented. Return an explicit bodyless success, such as the success state in a delete UI. An unexpected 204 on a generation endpoint should be flagged; do not return an empty string or invent a job ID.
  1. Validate when JSON is expected. Check the media type, parse the body, and validate business fields. Distinguish an empty body, HTML, and a missing job ID instead of catching everything and returning {}.
  1. Do not replay an operation just because parsing failed. Before resending something that changes state or incurs a charge, confirm its outcome. Check the object with a read-only request or provide support with the timestamp and a sanitized request ID. Do not send credentials or the entire user input to support.

Q: When using a gateway, how do I find the failing layer?

Find the HTTP status before SDK wrapping. Make sure it belongs to the actual operation, not a browser OPTIONS preflight or a success line printed by your client. Record the method, path, status, Content-Type, and sanitized request ID. Compare them with the gateway's documented contract. If a management endpoint permits 204, exercise that branch on a test configuration. If you expected model output, capture a minimal non-sensitive reproduction and confirm you reached the intended endpoint.

Do not guess the outcome from whether Content-Length is zero. Some clients hide or adjust headers, and a UI alert cannot distinguish the remote status from a local exception. Capture the status and time from the same request, then check the endpoint documentation.

Add four regression tests: valid 204, unexpected 204, valid JSON, and a successful status with a non-JSON body. The first two must take different branches despite having the same status. Let the endpoint contract determine success before deciding whether to parse.

Sources & attribution

This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.

  1. 204 No Content — MDN Web Docs (Mozilla) · accessed 2026-11-30Note:Explains the successful, bodyless 204 response with delete and update examples.

One key for Claude, GPT and 50+ models

The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.