How to Debug a 400 Bad Request from an LLM API
Use the actual error body to isolate malformed JSON, unsupported fields, context limits and invalid parameter values.

A 400 Bad Request means the server could not accept the submitted request as it stands. Start with the error body. If it names a field, inspect the JSON your client actually sent. If it gives no field, compare the failing request with the smallest documented request for the same model and endpoint. Retrying the same payload leaves you with the same mystery.
The OpenAI error guide describes bad requests caused by malformed or missing parameters. Other providers and compatible gateways can use different error objects and HTTP mappings. A 422 often indicates a semantic processing problem despite syntactically acceptable input, but inspect the actual service contract rather than relying on that status distinction alone.
Start with the smallest valid request
For our Chat Completions route, send POST https://api.tokenhot.ai/v1/chat/completions with Content-Type: application/json and your bearer token in the Authorization header. Start with this body for a model your account can use:
{
"model": "CONFIRMED_MODEL_ID",
"messages": [{"role": "user", "content": "Reply with OK."}]
}
Replace the placeholder with a currently supported model for the operation. Build the JSON using a serializer rather than concatenating strings. Use a previously successful request as the baseline if you have one. If you send a fresh request, disable automatic retries and allow for the normal generation charge. Keep a redacted copy of the failing payload, without API keys or customer content.
If the baseline succeeds, reintroduce fields in logical groups: output settings, reasoning options, tools, structured output and media. Add one group, compare the response, and narrow a rejected group to a single field or interaction. If the minimal request still fails, do not blindly add fields to compensate: check the endpoint and exact model ID. If the response points to credentials or permissions, follow the 401/403 guide.
Use the error detail as an index into the request
| Error detail points to | Inspect |
|---|---|
| Invalid JSON or content type | Actual serialized body and HTTP header |
| Missing field or wrong type | Required fields, nesting, null versus omitted, number versus string |
| Unsupported parameter | Model and exact endpoint's parameter list |
| Invalid value | Allowed enum/range and mutually exclusive fields |
| Context limit | Input history, tool schemas, reference assets and reserved output |
| Invalid conversation state | Message order, tool IDs and retained response blocks |
Here is an illustrative error body for a route that accepts a numeric temperature:
{
"error": {
"param": "temperature",
"message": "Expected a number, received a string."
}
}
Start with error.param: it points to temperature. Now inspect the JSON your client sent. The quotation marks around 0.7 make it a string. Change the value in the client and compare the serialized field:
- "temperature": "0.7"
+ "temperature": 0.7
If the model omits temperature from its supported parameters, leave the field out of the baseline. Changing its type cannot add model support.
Do not assume every model supports temperature, top_p, max_tokens and max_completion_tokens interchangeably. Compare the exact model and API surface. If a client silently discards unsupported fields, a 200 response may not mean your intended setting was applied.
Context failures need their own comparison
Count or estimate the full request according to the selected model's accounting, not only the latest user message. Tool definitions, repeated history, system instructions and media can contribute. Check whether the route limits input separately from total context or reserves an output allowance. Reduce the input while preserving necessary instructions and tool-message relationships; do not strip signed thinking blocks or tool results indiscriminately.
Save the difference, then correct the request
Record the last working body, first failing body, exact status, error type/code/parameter and redacted request ID. A small diff makes the next step clear. Keep an explicit retry budget and count each deliberately resubmitted request. Never assume a timeout means the original operation was not accepted.
For a failed remote image fetch, use the image URL diagnostic guide. For a model-not-found response, isolate the model and endpoint first. A 400 request fix is successful when the minimal intended operation is accepted and the returned content actually meets the task—not merely when a parameter is removed.


