# Flask/FastAPI: request-scoped send, mapped errors
```python
import os
import resend
from resend.exceptions import ResendError
resend.api_key = os.environ["RESEND_API_KEY"]
@app.post("/send")
def send_email():
params = {
"from": "[SENDER]",
"to": ["[RECIPIENT]"],
"subject": "hello world",
"html": "<strong>it works!</strong>",
}
try:
email = resend.Emails.send(params)
return {"id": str(email)}
except ResendError as error:
print(error)
return {"error": "could not send email"}, 502
```
## Checklist
- Call `resend.Emails.send` inside the view function, not at module import.
Import-time sends fire once at startup and never again.
- Map ResendError to a 5xx response. Returning the raw exception object leaks
internals and usually serializes badly.
- Keep `resend.api_key` assignment at module scope (once), the send call at
request scope (every time). One is configuration, the other is work.
- The key comes from the environment in every framework. No framework changes
that.