API ReferenceAIGenerate preview
POST/v2/ai/generate-preview

Generate preview

Personalizes an existing HTML template against lead details and/or an AI prompt — the core AI Playground action. Pick a model from List models, or omit model to use the default.

Stablescope: write API KeyLearn about API scopes →

Credits are refunded on failure

The chosen model's emailCredits are deducted up front and refunded automatically if generation fails, so a failed call never leaves your balance short.

Request

AuthorizationBearer YOUR_API_KEY
Content-Typeapplication/json

Parameters

FieldTypeRequiredDescription
htmlstringRequiredThe template body to personalize, 1–800,000 characters.
subjectstringOptionalSubject line, up to 998 characters.
leadDetailsobjectOptionalFlat string map used for merge fields, up to 100 keys.
aiPromptobjectOptional{ prompt (1–10,000 chars, required), tone?, length?, leadDetails? } — instructions for how to personalize.
modelstringOptionalA model id from List models, must be email-eligible (has emailCredits). Omitted, unset, or an id with no emailCredits falls back to gpt-6-sol — note this is NOT the same model as List models' top-level defaultModel field, which is the AI Agent/chat default (gpt-6-luna).
curl -X POST "https://api.stynar.com/v2/ai/generate-preview" \
  -H "Authorization: Bearer esk_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"html":"<p>Hi {{firstName}},</p><p>Saw {{company}} is hiring — thought you'"'"'d like this.</p>","leadDetails":{"firstName":"Jane","company":"Acme"},"aiPrompt":{"prompt":"Make the opening line reference their recent funding round.","tone":"casual"},"model":"gpt-6-luna"}'

Response

✓ 200 OK
200 response
{
  "html": "<p>Hi Jane,</p><p>Congrats on the Series A — thought you'd like this.</p>",
  "subject": "Quick question about Acme",
  "model": "gpt-6-luna",
  "creditsCharged": 0.4
}

Response fields

Errors

StatusCodeMeaning
✕ 402 QUOTA_EXCEEDEDNot enough credits for this model.
✕ 403 ForbiddenQUOTA_EXCEEDEDThe chosen model's tier is locked during your trial.
✕ 401 UnauthorizedUNAUTHORIZEDMissing, malformed, unknown, revoked, or expired key.
✕ 403 ForbiddenAPI_ACCESS_DISABLEDAPI access is turned off for your account.
✕ 403 ForbiddenINSUFFICIENT_SCOPEThe key doesn't have the scope this endpoint requires.
✕ 404 Not FoundNOT_FOUNDUnknown route, or a resource that doesn't exist / isn't yours.
✕ 409 ConflictCONFLICTThe action can't be applied to the resource's current state.
✕ 429 Too Many RequestsRATE_LIMIT_EXCEEDEDPer-minute or per-second limit hit.
✕ 429 Too Many RequestsQUOTA_EXCEEDEDMonthly quota exhausted.
✕ 500 Internal Server ErrorINTERNAL_ERRORSomething broke on Stynar's end.
Full error reference →