: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 OpenRouter no-organization 404 as non-retryable (#71430)
Tom Owersde824e2ebb66
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/source.pyindex 2c6c795b9586..7859a5b6fd73 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/source.py@@ -38,6 +38,15 @@ _MANAGEMENT_KEY_REQUIRED = ("read the models and providers catalogs.")+# The organization members and workspaces endpoints resolve only when the management key's account+# belongs to an OpenRouter organization; an account without one gets a 404. Retrying can't create an+# organization, so we stop and tell the customer.+_NO_ORGANIZATION = (+ "Your OpenRouter account isn't part of an organization, so the organization members and workspaces "+ "tables can't be synced. Disable these tables, or reconnect with a management key that belongs to an "+ "organization."+)+@SourceRegistry.registerclass OpenRouterSource(ResumableSource[OpenRouterSourceConfig, OpenRouterResumeConfig]):@@ -88,6 +97,11 @@ Use a **management API key** (create one under [Settings -> Management Keys](htt# status text and base host, not the per-request path/query."401 Client Error: Unauthorized for url: https://openrouter.ai": "Your OpenRouter API key is invalid or has been revoked. Create a new key in your OpenRouter dashboard, then reconnect.","403 Client Error: Forbidden for url: https://openrouter.ai": "Your OpenRouter API key is missing the management scope needed to sync this data. Use a management API key (Settings -> Management Keys), then reconnect.",+ # Match the org-scoped paths specifically, not a bare host 404, so a genuine bad path on+ # another endpoint still surfaces instead of being silently disabled. The query string is+ # dropped as the volatile part.+ "404 Client Error: Not Found for url: https://openrouter.ai/api/v1/organization/members": _NO_ORGANIZATION,+ "404 Client Error: Not Found for url: https://openrouter.ai/api/v1/workspaces": _NO_ORGANIZATION,}def get_schemas(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter_source.pyindex b089b4bfae9b..f066d343194f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter_source.py@@ -64,10 +64,35 @@ class TestOpenRouterSource:schemas = self.source.get_schemas(self.config, self.team_id, names=["models", "activity"])assert {s.name for s in schemas} == {"models", "activity"}- @pytest.mark.parametrize("expected_key", ["401 Client Error", "403 Client Error"])+ @pytest.mark.parametrize("expected_key", ["401 Client Error", "403 Client Error", "404 Client Error"])def test_non_retryable_errors(self, expected_key):assert any(expected_key in key for key in self.source.get_non_retryable_errors())+ @pytest.mark.parametrize(+ "raw_error,is_non_retryable",+ [+ # Real raise_for_status() strings carry the offset/limit query the org endpoints page with;+ # the keys must still match them as a substring the way external_data_job.py classifies.+ (+ "404 Client Error: Not Found for url: https://openrouter.ai/api/v1/organization/members?offset=0&limit=100",+ True,+ ),+ (+ "404 Client Error: Not Found for url: https://openrouter.ai/api/v1/workspaces?offset=0&limit=100",+ True,+ ),+ # A 404 on a catalog endpoint would be a real path bug, not a missing organization — it must+ # stay retryable rather than be silently disabled.+ ("404 Client Error: Not Found for url: https://openrouter.ai/api/v1/models", False),+ ],+ )+ def test_404_classification(self, raw_error, is_non_retryable):+ errors = self.source.get_non_retryable_errors()+ matches = [msg for key, msg in errors.items() if key in raw_error]+ assert bool(matches) is is_non_retryable+ if is_non_retryable:+ assert "organization" in (matches[0] or "").lower()+def test_validate_credentials_invalid_key(self):with _patch_key_info(None):ok, error = self.source.validate_credentials(self.config, self.team_id)