Draft an email with AI
POST
/api/v1/mailbox/ai/composeWrites or rewrites a draft from an instruction. Only when capabilities.ai is true and the holder has accepted the AI terms (POST /ai/consent).
Errors
| Status | When |
|---|---|
401 |
No token, or the session expired or was signed out. Sign in again with POST /mailbox-auth/login. |
403 |
The account has a temporary password: until POST /security/password succeeds, every other call answers this with error_code: password_change_required. |
502 |
The AI service did not answer usefully. |
503 |
No AI is set up on this server. |
Request body
instructionstringrequiredWhat to write, in plain words, up to 2,000 characters.
existing_draftstring or nullA draft to rewrite instead of starting fresh.
Request
POST
/api/v1/mailbox/ai/composecurl -X POST 'https://courier.mailyte.com/api/v1/mailbox/ai/compose' \
-H 'Authorization: Bearer MAILBOX_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"instruction": "Thank Tunde for the figures and ask for the Q4 forecast by Friday.",
"existing_draft": null
}'const response = await fetch('https://courier.mailyte.com/api/v1/mailbox/ai/compose', {
method: 'POST',
headers: {
Authorization: 'Bearer MAILBOX_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"instruction": "Thank Tunde for the figures and ask for the Q4 forecast by Friday.",
"existing_draft": null
}),
});
const { data } = await response.json();import requests
response = requests.post(
"https://courier.mailyte.com/api/v1/mailbox/ai/compose",
headers={"Authorization": "Bearer MAILBOX_TOKEN"},
json={
"instruction": "Thank Tunde for the figures and ask for the Q4 forecast by Friday.",
"existing_draft": null
},
)
data = response.json()["data"]<?php
$response = Http::withToken('MAILBOX_TOKEN')
->post('https://courier.mailyte.com/api/v1/mailbox/ai/compose', [
'instruction' => 'Thank Tunde for the figures and ask for the Q4 forecast by Friday.',
'existing_draft' => null,
]);
$data = $response->json('data');require "net/http"
require "json"
uri = URI("https://courier.mailyte.com/api/v1/mailbox/ai/compose")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer MAILBOX_TOKEN"
request["Content-Type"] = "application/json"
request.body = {
"instruction": "Thank Tunde for the figures and ask for the Q4 forecast by Friday.",
"existing_draft": null
}.to_json
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }Response
Successful Response
dataobjectdraftstringai_calls_remaininginteger
200
application/json{
"type": "success",
"msg": "Draft generated",
"data": {
"draft": "Hi Tunde,\n\nThank you for the Q3 figures...",
"ai_calls_remaining": 47
}
}Returned inside the standard envelope.
Errors
| Status | When |
|---|---|
401 | No token, or the session expired or was signed out. Sign in again with `POST /mailbox-auth/login`. |
403 | The account has a temporary password: until `POST /security/password` succeeds, every other call answers this with `error_code: password_change_required`. |
422 | Validation Error |
502 | The AI service did not answer usefully. |
503 | No AI is set up on this server. |
Every status, with what causes it and what to do, is on the error reference.