Generate (single lead)

Api ReferenceUpdated February 18, 2025

Generate (single lead)

Generate a personalized cold email sequence for one lead. This is a synchronous request: the response is returned when generation is done, which can take 3–10 minutes. Use a long client timeout (at least 300 seconds, preferably 600).

POST /api/v1/campaigns/:id/generate


Path parameters

ParameterTypeDescription
idstring (UUID)Campaign ID (from GET /api/v1/campaigns).

Headers

HeaderRequiredDescription
Authorization or X-API-KeyYesAPI key.
Content-TypeYesapplication/json

Request body

FieldTypeRequiredDescription
leadobjectYesLead data for personalization.
lead.namestringNoFull name.
lead.titlestringNoJob title.
lead.companystringNoCompany name.
lead.emailstringYesEmail (required; used for mapping and exports).
lead.linkedin_urlstringNoLinkedIn profile URL.
lead.company_websitestringNoCompany website.
optionsobjectNoList/generation options (see below).

Options (optional)

OptionTypeDescription
list_namestringDisplay name for the list in the UI (default: derived from lead).
email_countnumberNumber of emails in sequence (1–5; default from campaign or 3).
email_signaturestringSignature appended to generated emails.
campaign_anglestringContext/angle for personalization.
approved_ctasstring or string[]CTAs to use (e.g. "Direct Meeting CTA, Lead Magnet CTA" or array).

Example request

curl -X POST "https://app.machfive.io/api/v1/campaigns/CAMPAIGN_ID/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "lead": {
      "name": "Jane Doe",
      "title": "VP Marketing",
      "company": "Acme Inc",
      "email": "jane@acme.com",
      "company_website": "https://acme.com"
    },
    "options": {
      "list_name": "API: jane@acme.com",
      "email_count": 3
    }
  }'

Response (200 OK)

{
  "lead_id": "lead_xyz789",
  "list_id": "uuid-of-email_sequences-row",
  "sequence": [
    { "step": 1, "subject": "...", "body": "..." },
    { "step": 2, "subject": "...", "body": "..." },
    { "step": 3, "subject": "...", "body": "..." }
  ],
  "credits_remaining": 94
}
FieldTypeDescription
lead_idstringInternal lead identifier.
list_idstring (UUID)List/sequence row ID (for status or export if needed).
sequencearrayGenerated emails: step, subject, body per step.
credits_remainingnumberCredits left in the workspace after this request.

The response may also include sequence_id (deprecated); use list_id only.


Error responses

StatusErrorDescription
400BAD_REQUESTInvalid JSON, missing lead, missing/invalid lead.email, or campaign has no vector store.
401UNAUTHORIZEDMissing or invalid API key.
402INSUFFICIENT_CREDITSNot enough credits; message includes upgrade guidance.
403FORBIDDENCampaign not in this workspace.
404NOT_FOUNDCampaign not found.
500INTERNAL_ERRORGeneration failed.

Error body shape: { "error": "CODE", "message": "Human-readable message" }.