campaigns_generate_messages
Per-step, per-lead equivalent of the auto-generation that runs during campaigns_activate. Use this to cover leads that are still PENDING on a specific step — typically because:
new leads were enrolled after the campaign first activated,
a previous activation ran out of connects mid-way, or
the user wants to regenerate selectively after tweaking the sequence template.
Input is Lead sqids, not CampaignLog sqids. The natural source is campaigns_step_logs with ?status=0. The endpoint resolves each Lead to its CampaignLog row for this (campaign, step) pair, filters to status=PENDING, and queues the generation as a background Celery task.
Returns task_sqid — poll jobs_get(task_sqid) until status == 'COMPLETED' (or 'FAILED'). Per-lead generation errors (unresolved ${vars}, AI snippet failures) appear in the task's result payload; the affected rows stay PENDING so a follow-up call can retry them.
Cost. One COMPOSE_EMAIL charge per generated message; see billing_pricelist for the current rate. The task does a batch-level balance pre-check before charging anything; if the account is short on connects the whole task fails cleanly with no partial charges. Call billing_balance before batches of 1000+.
Idempotent. If the task crashes halfway, re-calling with the same lead sqids picks up the still-PENDING rows; already-generated rows are skipped silently inside the per-row SELECT … FOR UPDATE SKIP LOCKED transaction.
Race-safe with the background process_campaign_steps_pending_status scheduler — both paths use the same row lock.
Method: POST /api/v1/workspaces/{workspace_sqid}/campaigns/{sqid}/steps/{step_sqid}/generate-messages/
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sqid": "<sqid>",
"step_sqid": "<step_sqid>",
"lead_sqids": "<lead_sqids>"
},
"name": "campaigns_generate_messages"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sqid | Yes | ||
| step_sqid | Yes | ||
| lead_sqids | Yes | Lead sqids whose pending messages for this step should be generated. Source these from `campaigns_step_logs` filtered by status=0 (PENDING). Cap 1000 per call. |