1- from typing import Any , Dict , List , cast
1+ from typing import Any , Dict , List , NotRequired , Optional , cast
22
33from typing_extensions import TypedDict
44
88from ._emails import Emails
99
1010
11+ class _SendOptions (TypedDict ):
12+ idempotency_key : NotRequired [str ]
13+ """
14+ Unique key that ensures the same operation is not processed multiple times.
15+ Allows for safe retries without duplicating operations.
16+ If provided, will be sent as the `Idempotency-Key` header.
17+ """
18+
19+
1120class _SendResponse (TypedDict ):
1221 data : List [Email ]
1322 """
@@ -17,6 +26,16 @@ class _SendResponse(TypedDict):
1726
1827class Batch :
1928
29+ class SendOptions (_SendOptions ):
30+ """
31+ SendOptions is the class that wraps the options for the batch send method.
32+
33+ Attributes:
34+ idempotency_key (NotRequired[str]): Unique key that ensures the same operation is not processed multiple times.
35+ Allows for safe retries without duplicating operations.
36+ If provided, will be sent as the `Idempotency-Key` header.
37+ """
38+
2039 class SendResponse (_SendResponse ):
2140 """
2241 SendResponse type that wraps a list of email objects
@@ -26,20 +45,26 @@ class SendResponse(_SendResponse):
2645 """
2746
2847 @classmethod
29- def send (cls , params : List [Emails .SendParams ]) -> SendResponse :
48+ def send (
49+ cls , params : List [Emails .SendParams ], options : Optional [SendOptions ] = None
50+ ) -> SendResponse :
3051 """
3152 Trigger up to 100 batch emails at once.
3253 see more: https://resend.com/docs/api-reference/emails/send-batch-emails
3354
3455 Args:
3556 params (List[Emails.SendParams]): The list of emails to send
57+ options (Optional[SendOptions]): Batch options, ie: idempotency_key
3658
3759 Returns:
3860 SendResponse: A list of email objects
3961 """
4062 path = "/emails/batch"
4163
4264 resp = request .Request [_SendResponse ](
43- path = path , params = cast (List [Dict [Any , Any ]], params ), verb = "post"
65+ path = path ,
66+ params = cast (List [Dict [Any , Any ]], params ),
67+ verb = "post" ,
68+ options = cast (Dict [Any , Any ], options ),
4469 ).perform_with_content ()
4570 return resp
0 commit comments