Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(anthropic): tell customers to sync less often when the rate limit runs out (#116060)

Tom Owers89d7b1431b7b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.py
index ecc866ead68d..3cf963141595 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.py
@@ -92,6 +92,17 @@ The group, group membership and custom role tables come from the Claude Enterpri
return CANONICAL_DESCRIPTIONS
+ def get_retry_exhausted_errors(self) -> dict[str, str]:
+ # The report endpoints share one organization rate limit, and Anthropic can ask for a wait of
+ # up to an hour once it is spent. A schedule shorter than that keeps hitting the same limit,
+ # so the generic "short problem on the source's side" copy sends the customer nowhere.
+ return {
+ "HTTP 429 for https://api.anthropic.com": (
+ "Anthropic's API rate limit for your organization ran out before this sync finished. "
+ "Set this table to sync less often, such as every 6 hours, so each run stays within the limit."
+ ),
+ }
+
def get_non_retryable_errors(self) -> dict[str, str | None]:
rbac_group_denied = "This table comes from the Claude Enterprise user management API, which your key can't reach. Reconnect the source with an Admin API key created in claude.ai for all your linked organizations, carrying the read:rbac_groups scope, or turn this table's sync off."
rbac_role_denied = "This table comes from the Claude Enterprise user management API, which your key can't reach. Reconnect the source with an Admin API key created in claude.ai carrying the read:members scope, or turn this table's sync off."
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.py b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.py
index 7361d17dee24..ea7fd6b86bf8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.py
@@ -270,6 +270,31 @@ class TestNonRetryableErrors:
non_retryable = AnthropicSource().get_non_retryable_errors()
assert not any(key in other_error for key in non_retryable)
+ @parameterized.expand(
+ [
+ (
+ "long_retry_after",
+ "RESTClientRetryableError: HTTP 429 for https://api.anthropic.com/v1/organizations/usage_report/claude_code"
+ " (the server asked for a wait of 3600 seconds)",
+ ),
+ (
+ "retry_budget_spent",
+ "RESTClientRetryableError: HTTP 429 for https://api.anthropic.com/v1/organizations/usage_report/messages",
+ ),
+ ]
+ )
+ def test_exhausted_rate_limit_stays_retryable_with_sync_frequency_guidance(
+ self, _name: str, observed_error: str
+ ) -> None:
+ source = AnthropicSource()
+ assert not error_message_matches(observed_error, source.get_non_retryable_errors().keys())
+ messages = [
+ message
+ for pattern, message in source.get_retry_exhausted_errors().items()
+ if error_message_matches(observed_error, [pattern])
+ ]
+ assert messages and "sync less often" in messages[0]
+
def _cc_record(actor_email: str = "[email protected]") -> dict[str, Any]:
return {