← All tutorialsContent

Newsletter generator

Pull the week's top stories in a niche, write a 400-word digest, send to your list. One cron, one agent.

Cost~$0.10 per issue + $0.0005 per recipient
Operations
web_search.querytext_generation.generateemail.send

Prerequisites

  • Cron runner (your own infra) that triggers a Friday 8am job.
  • Recipient list in your DB. The agent receives the list; Upivia just sends.

Walkthrough

1. Gather

Run web_search.query for 5–10 niche keywords. Dedupe URLs.

2. Write

Single GPT-4o call: 'Write a 400-word newsletter from these links.' Cache the result.

3. Fan out

Loop over recipients calling email.send. Use a per-recipient idempotency_key so retries never double-send.

bash# One send per recipient; the idempotency_key dedupes any retry.
curl -X POST https://www.upivia.com/v1/service-requests \
  -H "Authorization: Bearer $AGENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "service":"email",
    "operation":"send",
    "payload":{"to":"sub@x.com","subject":"Weekly Digest","body":"<html>"},
    "idempotency_key":"newsletter_2026_05_w3_sub_x.com"
  }'

Next steps

Audit every call at /audit-logs, watch spend at /usage, and tune budgets per service on the agent's page.

Create an account →