: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
feat(warehouse_sources): support LlamaCloud API version v2 (#80097)
Tom Owers0394f9ce2fae
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex 0e9cdc017b68..d73950fa8a61 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -51,7 +51,7 @@ Add it when any of these hold:- Keep it minimal. If the version is just a header/URL segment and response shapes are compatible, thread the version string down to where the client/URL is built (see Stripe: `StripeSource.source_for_pipeline` passes `self.resolve_api_version(inputs.api_version)` → `stripe_source(...)` → `StripeClient(stripe_version=...)`). Resolve through `resolve_api_version` at the source class — never hardcode a fallback version in the request layer.- Only introduce per-version modules/branches where behavior genuinely diverges (different pagination, different field mapping). Keep all version branching inside the source's own directory — never in shared layers.- When the new version renames endpoints, changes primary keys, or reshapes responses, the divergence must actually be branched — never leave the old single-version request path serving the new default. All the relevant surfaces can vary by version: `get_rows` receives the resolved pin in `inputs.api_version`; credential fields can key off `default_version`.- - Conversely, don't add inert scaffolding: an `api_version` param no caller varies, or a version→URL map with identical values, is a review finding, not forward-compat. Declaration-only (`supported_versions`/`default_version` and nothing else) is the correct shape just when the gate above passed on a non-wire reason — the old label is being retired, or the vendor switches behavior account-side rather than per request. If the gate passed on nothing at all, there is no PR.+ - Conversely, don't add inert scaffolding: an `api_version` param no caller varies, or a version→URL map with identical values, is a review finding, not forward-compat. Declaration-only (`supported_versions`/`default_version` and nothing else) is the correct shape just when the gate above passed on a non-wire reason — the old label is being retired, the vendor switches behavior account-side rather than per request, or the source already reads the vendor's newest generation under the framework's legacy unversioned label (verify the request paths the source actually builds, not the label — a legacy label can already ride the new wire, so the new label just formalizes it for new rows and both resolve identically). If the gate passed on nothing at all, there is no PR.- **Discovery and probe paths receive the pin — consume it.** The framework passes the resolved pin as the `api_version` parameter of `get_schemas`, `validate_credentials`, `get_endpoint_permissions`, and the webhook management methods. A multi-version source MUST build its discovery/probe/webhook clients from that parameter, not from `default_version` or a hardcoded header — otherwise a pinned source discovers/reconciles under the wrong version and its tables can disappear, duplicate, or fail reconciliation. Resolve it with `self.resolve_api_version(api_version)` — callers with a row pass an already-resolved value (mirroring `SourceInputs.api_version`), so the source-side resolve only covers pre-creation calls that pass `None`. Ignoring the parameter is only correct when you can state why the version makes no difference to that path.- Watch for version-dependent column hints/schemas: e.g. Stripe's `external_table_definitions` were built for specific versions. When adding a version whose response shapes differ, gate the canonical column hints to the versions they were built for and let newer versions auto-infer the schema from the data (a set of hint-compatible versions checked where hints are applied). For `has_managed_hogql_schema=True` sources this includes the read path: `hogql_definition`'s canonical column mapping is version-blind, so renamed columns need the canonical schema/descriptions updated too.4. **Keep old versions working**: do not delete or alter the request path for previously supported versions. Removing a version is an explicit future decision, not part of a version-add PR.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/llama_cloud.py b/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/llama_cloud.pyindex cd25e9202c57..b02c6b0718ad 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/llama_cloud.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/llama_cloud/llama_cloud.py@@ -22,6 +22,13 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.llama_clouREQUEST_TIMEOUT_SECONDS = 60+# LlamaCloud's current stable API generation (its v2 SDKs shipped January 2026). LlamaCloud versions+# its API in the endpoint path (`/api/v1/...` vs `/api/v2/...`), not via a request header, and this+# source already reads the v2-generation job endpoints (parse, extract, classify, batches under+# `/api/v2`). So the framework's legacy unversioned label and this explicit label resolve to the+# same requests — new sources are stamped "v2" while existing pins keep syncing byte-for-byte.+LLAMA_CLOUD_API_VERSION_V2 = "v2"+class LlamaCloudRetryableError(Exception):passdiff --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 23d351965df6..418bf6fe39fb 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@@ -11,7 +11,11 @@ from posthog.schema import (SourceFieldSelectConfigOption,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (+ UNVERSIONED_API_VERSION,+ FieldType,+ ResumableSource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (CanonicalDescriptions,)@@ -23,6 +27,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_LlamaCloudSourceConfig,)from products.warehouse_sources.backend.temporal.data_imports.sources.llama_cloud.llama_cloud import (+ LLAMA_CLOUD_API_VERSION_V2,LlamaCloudResumeConfig,llama_cloud_source,validate_credentials as validate_llama_cloud_credentials,@@ -38,7 +43,13 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass LlamaCloudSource(ResumableSource[LlamaCloudSourceConfig, LlamaCloudResumeConfig]):lists_tables_without_credentials = True # static endpoint catalog — safe for public docs- api_docs_url = "https://docs.cloud.llamaindex.ai"+ api_docs_url = "https://developers.llamaindex.ai/python/cloud/"++ # LlamaCloud versions its API in the endpoint path (see LLAMA_CLOUD_API_VERSION_V2): this source+ # already reads the v2-generation endpoints, so the legacy unversioned label and "v2" drive+ # identical requests. New sources default to "v2"; existing pins keep syncing byte-for-byte.+ supported_versions = (UNVERSIONED_API_VERSION, LLAMA_CLOUD_API_VERSION_V2)+ default_version = LLAMA_CLOUD_API_VERSION_V2@propertydef source_type(self) -> ExternalDataSourceType: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 5efabaa5e10e..8f6f2bc3d95b 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@@ -217,3 +217,26 @@ class TestLlamaCloudSource:self.source.source_for_pipeline(self.config, MagicMock(), inputs)assert mock_source.call_args.kwargs["db_incremental_field_last_value"] is None+++class TestLlamaCloudSourceVersions:+ def setup_method(self) -> None:+ self.source = LlamaCloudSource()++ def test_new_sources_default_to_v2(self) -> None:+ # New sources (no pin) must be created on LlamaCloud's current API generation.+ assert self.source.default_version == "v2"+ assert self.source.resolve_api_version(None) == "v2"++ @parameterized.expand([("v1",), ("v2",)])+ def test_existing_pin_is_honored(self, version: str) -> None:+ # Pinned rows — including the legacy "v1" default existing sources carry — keep their+ # version after the default bump, so their syncs stay byte-for-byte unaffected.+ assert version in self.source.supported_versions+ assert self.source.resolve_api_version(version) == version++ @parameterized.expand([("v1",), ("v2",)])+ def test_no_version_is_deprecated(self, version: str) -> None:+ # This is a plain update, not a sunset: neither label is deprecated, so the in-product+ # deprecation banner must stay dark for existing v1 pins.+ assert self.source.get_version_deprecation(version) is None