Repository navigation
feat: add per-email idempotency keys to batch send - #37
Merged
Merged
Conversation
- New BatchEmailMessage type: an EmailMessage with an optional
idempotency_key. emails.send_batch() accepts it next to EmailMessage
and builders; the key is sent as the email's idempotency_key field.
- The idempotency_key= argument stays the Idempotency-Key header of the
whole request. The API validates the per-email keys.
- A builder gets a key through its wire format:
{**builder.build(), "idempotency_key": key}.
- Document per-email keys and details["accepted"] on a partial batch
failure in the README and the send_batch docstring.
Co-Authored-By: Claude <noreply@anthropic.com>
bjarn
force-pushed
the
feat/batch-idempotency-keys
branch
from
October 18, 2026 16:07
6c07531 to
b0dcc7d
Compare
bjarn
added this pull request to stack #38
October 18, 2026 17:20
bjornftw
approved these changes
Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #36 — merge that first.
What changed
Non-breaking. Suggested bump: minor (3.1.0 → 3.2.0, released with #36).
lettermint.BatchEmailMessagetype. It is anEmailMessagewith an optional per-emailidempotency_key, and it mirrors the generatedSendBatchMailItem.emails.send_batch()now acceptsSequence[EmailMessage | BatchEmailMessage | EmailBuilder], so lists typed asEmailMessagestill type-check. A per-email key goes out as the item'sidempotency_keyfield.idempotency_key=argument ofsend_batch()is still theIdempotency-Keyheader of the whole request.emails.send()andbuilder.send()never putidempotency_keyin the body.{**builder.build(), "idempotency_key": key}.BatchEmailMessage.attachmentsalso accepts the base64 attachment list thatbuild()returns, so this type-checks.ConflictErrorwith codeIDEMPOTENCY_CONFLICT.send_batchdocstring cover per-email keys. They also explain that on a partial failure, the error'sdetails["accepted"]lists the emails already accepted (index,message_id). The existingAPIError.detailsalready holds that list, so there is no new accessor.Usage
Checks
python -m ruff check src tests scripts: all checks passedpython -m ruff format --check src tests scripts: all files formattedpython -m mypy: no issues in 33 source filespython scripts/unasync.py --check: up to datepython scripts/generate.py --checkwith and without the generator: okpython -m pytest tests/: 250 passed on Python 3.10, 3.11, 3.12, 3.13 and 3.14python -m build,twine check --strict dist/*and the wheel smoke test: passedmypy --strictruns: existing calls type-check unchanged (list[EmailMessage],list[EmailMessage | EmailBuilder], tuples, async builders), and so does the README snippetNot run locally
Suggested release tag
v3.2.0(together with #36)🤖 Generated with Claude Code