: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-imports): treat llama_cloud usage-metrics 400 as non-retryable (#72162)
Tom Owers15d597e6750f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/source.pyindex 1f045a4c756c..d7c48fb728ff 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/source.py@@ -87,9 +87,22 @@ You can create an API key in [LlamaCloud](https://cloud.llamaindex.ai) under **Sdef get_non_retryable_errors(self) -> dict[str, str | None]:# Both regional hosts share the https://api.cloud. prefix, so one key per status# covers NA and EU without matching unrelated hosts.+ usage_metrics_400 = (+ "LlamaCloud rejected the request for the usage metrics table with a 400 error. This beta "+ "endpoint isn't available for every LlamaCloud organization, so we've stopped syncing "+ "usage_metrics; your other LlamaCloud tables keep syncing. If you need usage metrics, check "+ "with LlamaCloud that your organization has access to the beta usage-metrics API."+ )return {"401 Client Error: Unauthorized for url: https://api.cloud.": "Your LlamaCloud API key is invalid, revoked, or from a different region. Create a new API key in LlamaCloud, check the region, and reconnect.","403 Client Error: Forbidden for url: https://api.cloud.": "Your LlamaCloud API key does not have access to this data. Check the key's project in LlamaCloud and reconnect.",+ # The beta usage-metrics endpoint deterministically returns 400 for organizations it isn't+ # available to; our request is otherwise valid (organization_id resolved, page_size in range),+ # so retrying can't help. Scope the key to this endpoint's path — status and path, not the+ # variable query string — so genuine 400s on other endpoints still surface. The host differs+ # per region, so one key each keeps the match off unrelated 401/403 responses.+ "400 Client Error: Bad Request for url: https://api.cloud.llamaindex.ai/api/v1/beta/usage-metrics": usage_metrics_400,+ "400 Client Error: Bad Request for url: https://api.cloud.eu.llamaindex.ai/api/v1/beta/usage-metrics": usage_metrics_400,}def get_canonical_descriptions(self) -> CanonicalDescriptions:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/tests/test_llama_cloud_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/tests/test_llama_cloud_source.pyindex ef8da47694f3..675f50a3d6d1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/tests/test_llama_cloud_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/tests/test_llama_cloud_source.py@@ -139,6 +139,14 @@ class TestLlamaCloudSource:("401 Client Error: Unauthorized for url: https://api.cloud.llamaindex.ai/api/v2/parse?page_size=100",),("401 Client Error: Unauthorized for url: https://api.cloud.eu.llamaindex.ai/api/v2/projects",),("403 Client Error: Forbidden for url: https://api.cloud.llamaindex.ai/api/v1/beta/files",),+ # The beta usage-metrics endpoint 400s for organizations it isn't available to; the+ # request is otherwise valid, so retrying can't help. Both regional hosts must match.+ (+ "400 Client Error: Bad Request for url: https://api.cloud.llamaindex.ai/api/v1/beta/usage-metrics?page_size=100&organization_id=00000000-0000-0000-0000-000000000000",+ ),+ (+ "400 Client Error: Bad Request for url: https://api.cloud.eu.llamaindex.ai/api/v1/beta/usage-metrics?page_size=100&organization_id=00000000-0000-0000-0000-000000000000",+ ),])def test_non_retryable_errors_match_auth_failures(self, observed_error: str) -> None:@@ -149,6 +157,9 @@ class TestLlamaCloudSource:[("500 Server Error: Internal Server Error for url: https://api.cloud.llamaindex.ai/api/v2/parse",),("401 Client Error: Unauthorized for url: https://api.example.com/api/v2/parse",),+ # A 400 on a different endpoint may be a fixable bug in our request, so it must stay+ # retryable and keep surfacing rather than being swallowed by the usage-metrics key.+ ("400 Client Error: Bad Request for url: https://api.cloud.llamaindex.ai/api/v2/parse?page_size=100",),])def test_non_retryable_errors_ignore_unrelated(self, unrelated_error: str) -> None: