invalid_request
The request was authenticated and understood, but a field in it does not satisfy the schema or a hand-written check the route applies before doing any work.
How to fix it
- Read details.fields on the response. It is a deduplicated list of the failing paths and it is populated for every schema failure, so it names the key rather than describing it.
- Strip CR and LF from the subject and from every recipient address before sending. An address assembled from a display name and a user-supplied string is the usual source.
- Deduplicate recipients yourself before counting against the 25-unique-recipient cap, because the server counts the deduplicated union of to, cc and bcc.
- Do not retry unchanged. This code is not retryable, and the same body will fail the same way.
Which rule fired
Two different layers produce this code. The outer one is the error handler: a body that fails the route's schema, or is not valid JSON, is caught centrally and converted. A schema failure also carries a details.fields array naming each path that failed, so you do not have to guess which key was wrong. The inner one is a set of explicit checks that a schema cannot express, and those are the ones worth knowing about, because they are where a syntactically valid request still gets refused.
| In error.message | Means |
|---|---|
The request does not match the required format. Check the fields and JSON syntax. | The body does not parse against the route's schema, or it is not valid JSON. A schema failure also lists the failing paths in details.fields; a JSON syntax error does not. |
Request body could not be read. | The request body could not be read off the wire at all, for a reason other than exceeding the size cap. |
Idempotency-Key is required for send operations. | A send arrives without an Idempotency-Key header. |
A valid Idempotency-Key is required. | Approving a draft without an Idempotency-Key header, or with one longer than 128 characters. |
CR/LF is not allowed in headers. | A carriage return or line feed appears in the subject or in any recipient address on a send. This is a header-injection guard and it runs before anything is written. |
Too many recipients. | The union of to, cc and bcc, deduplicated, exceeds 25 unique recipients. The cap counts unique addresses, not entries, so the same address in to and cc costs one. |
Choose up to 10 distinct attachments. | A send names more than 10 attachment ids, or the same id twice. |
limit must be 1–100 and q at most 200 printable characters. | A thread or message listing has a limit outside 1 to 100, or a q longer than 200 characters or containing control characters. |
limit must be 1–100. | An event listing has a limit outside 1 to 100, or one that is not an integer. |
Use a valid address name. | Creating a live inbox on the platform domain with a local_part that, lower-cased, is not 1 to 64 letters, digits, dots, underscores or hyphens beginning with a letter or digit. |
Use a valid address name (letters, digits, dots, underscores, or hyphens). | The same check, for an inbox on your own domain. |
Enter a domain such as agents.example.com, not a URL or mailbox. | Previewing or attaching a domain whose name is not a plain hostname: a URL or a mailbox, an IP address or localhost, a single label, or longer than 253 characters. |
webhook URL is not allowed. HTTPS public endpoints only. | Creating a webhook whose URL is not https on the default port, carries a username, a password or a #fragment, or names localhost, a .local or .internal host, or a private address. Sending a test event to an endpoint whose stored URL no longer passes the same check. |
Unknown event type in subscription. | Creating a webhook that subscribes to an event type the API does not define. |
Upload cannot accept bytes. | Bytes are written to an upload that is not in the staging state, or whose reservation has already expired. |
Upload is not awaiting completion. | Completing an upload that is no longer waiting to be completed (it was completed or purged), or whose reservation has expired. |
Upload content is missing. | Completing an upload before any bytes were stored for it. |
Declared checksum does not match streamed bytes. | Completing an upload with a sha256 that does not match the stored bytes. |
Declared media type does not match detected type. | Completing an upload whose bytes do not match the media type declared when it was reserved. |
The export is not ready or has expired. Create a new export. | Downloading an export that is not prepared yet, or whose download window has closed. |
Review and accept the current published commercial terms before checkout. | Starting checkout without accepting the current published version of the paid subscription terms. |
Why it works this way: The header-injection check rejects the whole request rather than stripping the offending characters. Silently rewriting a subject would mean the message that went out is not the message you asked for, and the caller would have no way to notice.
Example
{
"error": {
"code": "invalid_request",
"message": "The request does not match the required format. Check the fields and JSON syntax.",
"request_id": "req_8Kd2x91",
"retryable": false,
"details": { "fields": ["subject"] }
}
} Over MCP, list_threads, list_messages, send_message and create_draft return it as text in a result marked isError: true, not as this body.
Where it appears
- Every /v1 route that takes a JSON body
-
POST /projects/{project_id}/ inboxes/ {inbox_id}/ messages -
POST /projects/{project_id}/ approvals/ {approval_id}/ approve -
GET /projects/{project_id}/ inboxes/ {inbox_id}/ threads -
GET /projects/{project_id}/ events -
POST /projects/{project_id}/ inboxes -
POST /projects/{project_id}/ domains -
POST /projects/{project_id}/ webhooks -
PUT /projects/{project_id}/ uploads/ {upload_id}/ content -
POST /projects/{project_id}/ uploads/ {upload_id}/ complete -
GET /projects/{project_id}/ exports/ {export_id}/ download
Paths are relative to https://api.emailforagents.ai/v1.