Agent tasks
Your own agent or script polls for an issue to write, then hands it back as a draft. Lease token, 30 minutes per task.
- GET /agent-tasks/next — Take the next task
- POST /agent-tasks/{id}/complete — Hand in the issue
- POST /agent-tasks/{id}/fail — Give up a task
get/agent-tasks/next— Take the next task
Takes the oldest issue due and locks it for 30 minutes (3 attempts at most). The lease_token proves the task: send it back with complete or fail. The task carries the brief, the sources, the last issues, the brand kit, the output_format and the rules. {"object": "agent_task", "data": null} when nothing is due: stop until the next run. Call it at least once a day: a silent agent triggers an alert.
Keys: full_access
Query parameters
| newsletter_id | uuid | Only this newsletter's tasks (default: every newsletter of the workspace). |
curl -X GET https://api.smartletter.ai/agent-tasks/next \
-H "Authorization: Bearer $SMARTLETTER_API_KEY"Response 200
{
"object": "agent_task",
"id": "9a1f0c2e-0000-4000-8000-000000000009",
"lease_token": "q3Zp0w6Kc1m9Yx2VtR8nHb5LdA7sEfJ4uGo-NiBkXcM",
"lease_expires_at": "2026-10-22T09:30:00.000Z",
"deadline_at": "2026-10-22T14:00:00.000Z",
"send_at": "2026-10-22T17:00:00.000Z",
"newsletter": {
"id": "7c3e1a52-0000-4000-8000-000000000001",
"name": "Acme Weekly",
"language": "en",
"themes": [
"saas"
],
"brand_kit": {
"themeColor": "#4f46e5"
}
},
"brief": "Three short sections, one practical tip each.",
"context": {
"sources": "<<<BEGIN UNTRUSTED_FEED_DATA 3f9c…>>>\n- Churn benchmarks 2026 (2026-10-20) https://example.com/churn\n<<<END UNTRUSTED_FEED_DATA 3f9c…>>>",
"recent_issues": [
{
"subject": "Onboarding emails that work",
"sent_at": "2026-10-15T17:00:00.000Z",
"excerpt": "This week: three onboarding emails…"
}
],
"top_links": [
{
"url": "https://example.com/onboarding",
"clicks": 84
}
],
"audience_size": 1520
},
"output_format": {
"subject": "string, 1 to 200 characters",
"preheader": "string up to 200 characters, or null",
"blocks": "array of 1 to 60 blocks…"
},
"rules": [
"Write the issue in this language: en.",
"Follow the brief; the brand kit sets the voice."
]
}post/agent-tasks/{id}/complete— Hand in the issue
Creates the issue as a draft, from subject, preheader and blocks (1 to 60 blocks, no raw HTML). It is reviewed; in auto_schedule mode it is scheduled when the review passes, otherwise the owner validates it. Sending the same lease_token again returns the same draft. 409 when the lease is gone (ask for the next task). 422 lists the problems in details.issues.
Keys: full_access
Body
| lease_tokenrequired | string | The lease_token returned with the task. |
| subjectrequired | string | |
| preheader | string | |
| blocksrequired | any[] | 1 to 60 blocks (no raw HTML), see the task's output_format. |
curl -X POST https://api.smartletter.ai/agent-tasks/<id>/complete \
-H "Authorization: Bearer $SMARTLETTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"lease_token":"q3Zp0w6Kc1m9Yx2VtR8nHb5LdA7sEfJ4uGo-NiBkXcM","subject":"3 ways to cut churn this week","preheader":"One tip you can use today.","blocks":[{"type":"paragraph","text":"Hi! Here is this week's tip."}]}'Response 200
{
"newsletter_id": "7c3e1a52-0000-4000-8000-000000000001",
"scheduled_for": null,
"review": {
"blocking": false
}
}post/agent-tasks/{id}/fail— Give up a task
Releases the lease and records why. status is open (the task is offered again) until the 3rd attempt, then failed and the owner is told.
Keys: full_access
Body
| lease_tokenrequired | string | The lease_token returned with the task. |
| reasonrequired | string | Why the issue could not be written. |
curl -X POST https://api.smartletter.ai/agent-tasks/<id>/fail \
-H "Authorization: Bearer $SMARTLETTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"lease_token":"q3Zp0w6Kc1m9Yx2VtR8nHb5LdA7sEfJ4uGo-NiBkXcM","reason":"No source this week."}'Response 200
{
"status": "open"
}