fix(ai): preserve Anthropic cache-write TTL breakdowns - #746
Conversation
|
@greptile review |
|
Reviews (1): Last reviewed commit: "fix(ai): preserve Anthropic cache-write ..." | Re-trigger Greptile |
richardsolomou
left a comment
There was a problem hiding this comment.
This looks good, thank you! Could you also open a targeted posthog-js follow-up for the equivalent gaps there? Vercel already preserves the raw usage, but Anthropic streaming and the LangChain integration appear to drop the TTL breakdown.
|
@richardsolomou I opened the targeted JS follow-up in PostHog/posthog-js#4236. Thanks for pointing me in that direction! |
@gouveags can you fix your commits and force push? |
a489857 to
7135dd1
Compare
|
@marandaneto Sorry about the unsigned commit. I’ve rebuilt the branch with a verified signature. Could you check it again? Thanks for the heads-up. Does this guideline apply across all PostHog repositories, or is it specific to this one? (asking because in other repos nobody noticed this). |
|
@carlos-marchal-ph all fixed, let me know if you notice something else that needs polishing! Thanks for the feedback! |
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| pypi/posthog: minor | |||
There was a problem hiding this comment.
is that a fix or new feat? title is fix, but the changeset is minor
Note
This PR depends on PostHog/posthog#71323 for server-side pricing. It can merge independently, but TTL-specific cost calculation takes effect only after the server-side change ships.
💡 Motivation and Context
PostHog/posthog#71323 adds separate costing for Anthropic's 5-minute and 1-hour cache writes. The Python SDK already preserves that breakdown in its native Anthropic wrappers, but two integrations drop it before ingestion.
Fixes #745. Related to PostHog/posthog#71306. Depends on PostHog/posthog#71323.
This change:
The PostHog Bedrock and Vertex clients reuse the native Anthropic message adapters. Aggregate-only events remain unchanged; invalid or empty TTL details fall back to the aggregate, and a valid breakdown replaces rather than adds to it.
Direct
boto3calls are outside this PR becauseposthog-pythonhas no boto3 Bedrock wrapper. The OTel integration forwards spans through a separate endpoint and is not changed.💚 How did you test it?
1826 passed, 67 skipped; one unrelated, order-dependent logging assertion failed inposthog/test/test_consumer.py::TestConsumer::test_message_only_error_logs_include_posthog_prefix, and it passes in isolation.143 passed, 9 skipped.📝 Checklist
If releasing new changes
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
I used Codex to inspect the server contract, audit the Python SDK integration paths, implement the focused changes, and run independent test, code, and writing reviews. No public session link is available.
The first pass focused on the LangChain callback. The broader audit showed that native Anthropic wrappers already preserve raw usage, while Claude Agent needed the same raw-usage path. The final diff reuses those existing mechanisms instead of adding provider pricing or a new integration layer.