Skip to content

feat(events): accept an idempotency key when sending an event - #328

Open
NicolasLopes7 wants to merge 1 commit into
mainfrom
feat/events-idempotency-key
Open

NicolasLopes7 wants to merge 1 commit into
mainfrom
feat/events-idempotency-key

Conversation

@NicolasLopes7

@NicolasLopes7 NicolasLopes7 commented Dec 4, 2026 •

Copy link
Copy Markdown

What

Events.send and Events.send_async take an optional options argument with idempotency_key, sent as the Idempotency-Key header on POST /events/send. This uses the same SendOptions shape and request plumbing as Emails.send and Batch.send. Existing calls don't change.

Why

The API accepts Idempotency-Key on POST /events/send. It stops a retried job or a redelivered message from starting duplicate Automation runs. Contract: resend/resend-docs#2039. Node SDK equivalent: resend/resend-node#1205.

Usage

options: resend.Events.SendOptions = {"idempotency_key": "order/123"}
resend.Events.send(
    {"event": "order.created", "email": "user@example.com", "payload": {"orderId": "123"}},
    options,
)

How tested

  • New sync and async tests check that the header is sent when a key is given (the sync one also checks that it's left out when no key is given). Both fail without the change.
  • tox -e lint,mypy,py on Python 3.14: lint OK, mypy clean, 907 passed.
  • examples/events.py and examples/async/events_async.py now show the option.

🤖 Generated with Claude Code


Summary by cubic

Events.send and Events.send_async now accept an optional options argument with an idempotency_key, sent as the Idempotency-Key header on POST /events/send. This lets retried jobs or redelivered messages avoid starting duplicate Automation runs. Existing calls are unaffected.

  • Uses the same SendOptions shape and request plumbing as Emails.send and Batch.send.
  • Adds sync and async tests verifying the header is sent when a key is provided and omitted otherwise.
  • Updates examples/events.py and examples/async/events_async.py to show the new option.

Written for commit 9ed3a8b. Summary will update on new commits.

View guided diff

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread tests/events_test.py Resolved
Comment thread examples/events.py Resolved
@NicolasLopes7
NicolasLopes7 marked this pull request as ready for review December 4, 2026 21:10
@NicolasLopes7

Copy link
Copy Markdown
Author

Reply to the cubic review summary ("2 issues found"): neither issue needs a code change.

  1. tests/events_test.py:254, global resend.api_key not restored: every test class sets the key in its own setUp, and no test reads it without setting it first, so the value left behind cannot affect other tests. Details: feat(events): accept an idempotency key when sending an event #328 (comment)
  2. examples/events.py:76, fixed idempotency key: intentional. The example sends the same event for the same email, so a stable key is the correct usage, and a rerun returns the deduplicated response. Details: feat(events): accept an idempotency key when sending an event #328 (comment)

@klotty klotty left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved.

@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants