# Resend Audiences — Manage Email Lists from AI Agents > Resend Audiences API lets agents add, remove, segment, unsubscribe email recipients. Tag-based segments. Compliant unsubscribe built in. ## Install Save as a script file and run: ## Quick Use 1. `client.audiences.create({name})` to make a list 2. `client.contacts.create({audience_id, email, ...})` per signup 3. `client.broadcasts.create + send` to ship a campaign with auto-unsubscribe --- ## Intro Resend Audiences is the list-management API — your agent adds recipients on signup, removes them on unsubscribe, segments by tag, and ships compliant unsubscribe links automatically. No separate ESP, no list-import CSV nightmare. Best for: AI agents that nurture leads, newsletter signup flows, onboarding sequences with per-stage list membership, anywhere your agent needs to send to a managed group. Works with: Resend Node + Python SDKs, REST. Setup time: 5 minutes. --- ### Create an audience ```python from resend import Resend client = Resend(api_key=os.environ["RESEND_API_KEY"]) audience = client.audiences.create({"name": "TokRepo Weekly Digest"}) print(audience["id"]) # save this — used for all member ops ``` ### Add a contact ```python client.contacts.create({ "audience_id": audience_id, "email": "jane@example.com", "first_name": "Jane", "last_name": "Smith", "unsubscribed": False, }) ``` ### Bulk import on signup ```python async def on_user_signup(user): client.contacts.create({ "audience_id": WEEKLY_DIGEST_ID, "email": user.email, "first_name": user.first_name, "unsubscribed": False, }) # If user opted into multiple lists, repeat per audience_id ``` ### Send a broadcast to an audience ```python broadcast = client.broadcasts.create({ "audience_id": WEEKLY_DIGEST_ID, "from": "TokRepo Weekly ", "subject": "5 new AI assets shipped this week", "html": render_weekly_digest_html(this_week_assets), "scheduled_at": "in 1 hour", # or "2026-05-12 09:00:00 -0700" }) client.broadcasts.send(broadcast["id"]) ``` ### Compliance: unsubscribe + RFC 8058 Resend automatically: - Adds a one-click unsubscribe link to every broadcast email - Includes `List-Unsubscribe` and `List-Unsubscribe-Post` headers (Gmail/Yahoo 2024 sender requirements) - Records unsubscribes against the contact — future sends skip them ```python # Manually unsubscribe (e.g., from a user-facing preference center) client.contacts.update({ "audience_id": WEEKLY_DIGEST_ID, "email": "jane@example.com", "unsubscribed": True, }) ``` ### List members ```python contacts = client.contacts.list({"audience_id": WEEKLY_DIGEST_ID}) for c in contacts["data"]: print(c["email"], c["unsubscribed"]) ``` --- ### FAQ **Q: Can I do tag-based segmentation?** A: Yes — contacts support arbitrary tag fields. Filter at send time by tag value to create dynamic segments. Use a separate audience per major list type, then tags for sub-segmentation. **Q: How does Audiences compare to Klaviyo / Mailchimp?** A: Audiences is a primitive — list + send + unsubscribe + compliance. Klaviyo/Mailchimp layer on visual campaign builders, automations, predictive segments. For AI-agent-driven lists where the agent IS the segmentation engine, Audiences is the right size. **Q: What about double opt-in?** A: Not built in — Resend assumes you've collected consent before adding. Implement double opt-in by sending a confirm-email through `emails.send` with a token URL, and only call `contacts.create` after the recipient clicks confirm. --- ## Source & Thanks > Built by [Resend](https://github.com/resend). Audiences API docs at [resend.com/docs/api-reference/audiences](https://resend.com/docs). > > [resend/resend-node](https://github.com/resend/resend-node) — official SDK --- ## 快速使用 1. `client.audiences.create({name})` 建列表 2. 每注册一个 `client.contacts.create({audience_id, email, ...})` 3. `client.broadcasts.create + send` 发带自动退订的 campaign --- ## 简介 Resend Audiences 是列表管理 API —— agent 在注册时加收件人、退订时移除、按 tag 分群、自动带合规退订链接。不用单独 ESP、没 CSV 导入噩梦。适合培养 leads 的 AI agent、newsletter 注册流、按阶段成员管理的 onboarding 序列、任何 agent 需要发给托管群体的场景。兼容 Resend Node + Python SDK、REST。装机时间 5 分钟。 --- ### 创建 audience ```python from resend import Resend client = Resend(api_key=os.environ["RESEND_API_KEY"]) audience = client.audiences.create({"name": "TokRepo 周报"}) print(audience["id"]) # 存下来 —— 所有成员操作要用 ``` ### 加联系人 ```python client.contacts.create({ "audience_id": audience_id, "email": "jane@example.com", "first_name": "Jane", "last_name": "Smith", "unsubscribed": False, }) ``` ### 注册时批量导入 ```python async def on_user_signup(user): client.contacts.create({ "audience_id": WEEKLY_DIGEST_ID, "email": user.email, "first_name": user.first_name, "unsubscribed": False, }) # 用户订了多个列表就按 audience_id 重复 ``` ### 给 audience 群发 ```python broadcast = client.broadcasts.create({ "audience_id": WEEKLY_DIGEST_ID, "from": "TokRepo Weekly ", "subject": "本周上线 5 个 AI 新资产", "html": render_weekly_digest_html(this_week_assets), "scheduled_at": "in 1 hour", # 或 "2026-05-12 09:00:00 -0700" }) client.broadcasts.send(broadcast["id"]) ``` ### 合规:退订 + RFC 8058 Resend 自动: - 每封群发邮件加一键退订链接 - 含 `List-Unsubscribe` 和 `List-Unsubscribe-Post` header(Gmail/Yahoo 2024 发件人要求) - 把退订记到联系人身上 —— 后续发送跳过 ```python # 手动退订(例如用户首选项中心) client.contacts.update({ "audience_id": WEEKLY_DIGEST_ID, "email": "jane@example.com", "unsubscribed": True, }) ``` ### 列成员 ```python contacts = client.contacts.list({"audience_id": WEEKLY_DIGEST_ID}) for c in contacts["data"]: print(c["email"], c["unsubscribed"]) ``` --- ### FAQ **Q: 能按 tag 分群吗?** A: 能 —— 联系人支持任意 tag 字段。发送时按 tag 值过滤做动态分群。每个主要列表类型用独立 audience,再用 tag 做子分群。 **Q: Audiences 跟 Klaviyo / Mailchimp 比?** A: Audiences 是 primitive —— list + 发送 + 退订 + 合规。Klaviyo/Mailchimp 加可视化营销建造器、自动化、预测分群。AI agent 驱动列表(agent 本身就是分群引擎)用 Audiences 大小合适。 **Q: 双重确认(double opt-in)呢?** A: 没内置 —— Resend 假设你加之前已收到同意。通过 `emails.send` 发带 token URL 的确认邮件,收件人点确认后再调 `contacts.create` 实现双重确认。 --- ## 来源与感谢 > Built by [Resend](https://github.com/resend). Audiences API docs at [resend.com/docs/api-reference/audiences](https://resend.com/docs). > > [resend/resend-node](https://github.com/resend/resend-node) — official SDK --- Source: https://tokrepo.com/en/workflows/resend-audiences-manage-email-lists-from-ai-agents Author: Resend