The Smart Compose endpoint expects a JSON object with the prompt nested inside, not just a string. Your request body should be structured like this:
json
{
"prompt": "Your prompt text here"
}
Keep in mind error 400 comes when the formatting of a request doesn’t have the expected content to go through. Common issues that cause 400 errors with Smart Compose include:
grant ID is required - Make sure you’re including a valid grant ID in the URL path
prompt is required - The prompt field must be present in the request body
invalid request - The request format is malformed
The endpoint URL should be:
POST /v3/grants/{grant_id}/messages/smart-compose
Make sure you’re including the required headers
Content-Type: application/json
Authorization: Bearer <NYLAS_API_KEY>
Also verify that your grant has the proper scopes - Smart Compose requires gmail.readonly for Google or Mail.Read for Microsoft .
If you’re still getting errors, check that your prompt is under 1,000 tokens as longer queries receive error messages.
Thank you for the information. I am sending json body but will check again . Can you also fix API playground? it is getting CORS error. I want to try there also.