Repository navigation
posthog-v7.84.0
Minor changes
-
063f1ce
posthog.emails.send()can now send email content your code rendered, such as HTML from Jinja or React Email. Give the email atemplate_keyand asubject, and passhtml,textor both.posthog = Posthog("phc_...", secret_key="phs_...") result = posthog.emails.send( to="user@example.com", distinct_id="user_123", template_key="password-reset", subject="Reset your password", html=rendered_html, ) # "delivered", "bounced", ... status = posthog.emails.get(result.id).status
You need a project secret API key, the kind that starts with
phs_. Create one under Project secret API keys in your project settings. Set its Transactional email scope to Write to send emails, or to Read for a key that only reads statuses. Pass it to the client assecret_key. Setapp_hostto your PostHog app URL when you self-host PostHog or send through a reverse proxy.PostHog records each email's delivery, opens and clicks on the person with that
distinct_id. It groups every email with the sametemplate_key, so you see their metrics and logs in one place. The SDK retries a request that hits a network error, a rate limit or an outage twice by default. Every send carries an idempotency key, so a retry never sends the email twice. Pass your ownidempotency_key, such aswelcome:user_123, and your job runner's retries are safe too.A send with your own content also takes
from_,reply_toandcapture_engagement=False. Setmigrated_fromon the client to tell PostHog which email provider you moved from. A failed call raises anEmailErrorwith PostHog'scodeand the HTTPstatus_code.Docs: Send transactional emails with Python and the transactional email overview. — Thanks @Silthus!
Patch changes
- b741c65 The LangChain callback handler no longer reports too few input tokens for a non-streamed
ChatAnthropiccall that reads or writes the prompt cache. It took the raw Anthropic usage fromresponse_metadata, whose input tokens already exclude the cache, and subtracted the cache tokens again, so a cached call usually reported 0 input tokens. It now reads LangChain's standardusage_metadatafirst, as it already did for streamed calls. — Thanks @jaeminbird for your first contribution 🎉!