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.

feat(warehouse_sources): support Vapi API version v2 (#74170)

Tom Owers649b5e3d70d0
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/settings.py
index 80e53d499b7d..a44c3cf4a1dc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/settings.py
@@ -1,10 +1,21 @@
-from dataclasses import dataclass, field
+from dataclasses import dataclass, field, replace
from typing import Literal, Optional
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSION
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
VAPI_BASE_URL = "https://api.vapi.ai"
+# Vapi's "v2" is a selective, per-resource scheme, not an account-wide or header-selected
+# version: only some resources gained a distinct `/v2/<resource>` route, and the rest keep
+# serving the same path and shape under both labels. Of the resources this source reads, only
+# phone numbers diverge (see `version_overrides` below). `v1` is the legacy unversioned API
+# existing rows are pinned to. See https://docs.vapi.ai/changelog/2025-09-17.
+VAPI_VERSION_V1 = UNVERSIONED_API_VERSION
+VAPI_VERSION_V2 = "v2"
+SUPPORTED_VERSIONS = (VAPI_VERSION_V1, VAPI_VERSION_V2)
+DEFAULT_VERSION = VAPI_VERSION_V2
+
# Vapi caps `limit` at 1000 (default 100). Call/chat objects can be large (full transcripts,
# message arrays, cost breakdowns), so keep pages at 100 rows to bound per-request memory.
DEFAULT_PAGE_LIMIT = 100
@@ -26,6 +37,15 @@ def _datetime_incremental_field(name: str) -> IncrementalField:
}
+@dataclass(frozen=True)
+class VapiEndpointVersion:
+ """Per-version override of an endpoint's request path and pagination style, for a resource
+ the vendor serves at a different route/shape under a newer API version."""
+
+ path: str
+ pagination: VapiPaginationStyle
+
+
@dataclass
class VapiEndpointConfig:
name: str
@@ -36,6 +56,10 @@ class VapiEndpointConfig:
partition_key: Optional[str] = "createdAt"
primary_keys: list[str] = field(default_factory=lambda: ["id"])
should_sync_default: bool = True
+ # Versions that serve this resource at a different path/pagination than the version-
+ # independent fields above, keyed by version label. Everything else (incremental fields,
+ # partitioning, primary keys) is identical across versions for the resources we read.
+ version_overrides: dict[str, VapiEndpointVersion] = field(default_factory=dict)
VAPI_ENDPOINTS: dict[str, VapiEndpointConfig] = {
@@ -62,6 +86,11 @@ VAPI_ENDPOINTS: dict[str, VapiEndpointConfig] = {
name="phone_numbers",
path="/phone-number",
pagination="created_at_cursor",
+ version_overrides={
+ # v2 replaces the bare createdAt-descending array at /phone-number with a
+ # page-numbered {results, metadata} envelope served at /v2/phone-number.
+ VAPI_VERSION_V2: VapiEndpointVersion(path="/v2/phone-number", pagination="page"),
+ },
),
"squads": VapiEndpointConfig(
name="squads",
@@ -107,6 +136,16 @@ VAPI_ENDPOINTS: dict[str, VapiEndpointConfig] = {
ENDPOINTS = tuple(VAPI_ENDPOINTS.keys())
+
+def resolve_endpoint(endpoint: str, api_version: str) -> VapiEndpointConfig:
+ """Endpoint config for a resolved version pin, swapping in any per-version path/pagination."""
+ config = VAPI_ENDPOINTS[endpoint]
+ override = config.version_overrides.get(api_version)
+ if override is None:
+ return config
+ return replace(config, path=override.path, pagination=override.pagination)
+
+
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
name: config.incremental_fields for name, config in VAPI_ENDPOINTS.items()
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/source.py
index e81cdd61dec5..f66faa1ebb22 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/source.py
@@ -22,8 +22,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import SourceSchema
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.vapi import VapiSourceConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.settings import (
+ DEFAULT_VERSION,
ENDPOINTS,
INCREMENTAL_FIELDS,
+ SUPPORTED_VERSIONS,
VAPI_ENDPOINTS,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.vapi import (
@@ -36,6 +38,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class VapiSource(ResumableSource[VapiSourceConfig, VapiResumeConfig]):
+ supported_versions = SUPPORTED_VERSIONS
+ default_version = DEFAULT_VERSION
api_docs_url = "https://docs.vapi.ai/api-reference"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@@ -98,6 +102,8 @@ You can find your private API key in the [Vapi dashboard](https://dashboard.vapi
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
+ # Version-blind: the table set, incremental fields, and primary keys are identical across
+ # versions; only phone_numbers' request path/pagination differ, which discovery doesn't expose.
def _build_schema(endpoint: str) -> SourceSchema:
endpoint_config = VAPI_ENDPOINTS[endpoint]
has_incremental = len(endpoint_config.incremental_fields) > 0
@@ -118,6 +124,7 @@ You can find your private API key in the [Vapi dashboard](https://dashboard.vapi
def validate_credentials(
self, config: VapiSourceConfig, team_id: int, schema_name: Optional[str] = None, api_version: str | None = None
) -> tuple[bool, str | None]:
+ # Version-blind: the probe hits /assistant, which has no v2 variant, so it validates both pins.
if validate_vapi_credentials(config.api_key):
return True, None
@@ -135,6 +142,7 @@ You can find your private API key in the [Vapi dashboard](https://dashboard.vapi
return vapi_source(
api_key=config.api_key,
endpoint=inputs.schema_name,
+ api_version=self.resolve_api_version(inputs.api_version),
logger=inputs.logger,
resumable_source_manager=resumable_source_manager,
should_use_incremental_field=inputs.should_use_incremental_field,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi.py
index ce7625bcf14a..4f59a9ef2186 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi.py
@@ -9,6 +9,10 @@ from parameterized import parameterized
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.utils import table_from_py_list
from products.warehouse_sources.backend.temporal.data_imports.sources.vapi import vapi
+from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.settings import (
+ VAPI_VERSION_V1,
+ VAPI_VERSION_V2,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.vapi import (
VapiResumeConfig,
_format_datetime_param,
@@ -77,12 +81,15 @@ def _patch_fetch(monkeypatch: Any, pages: dict[str, Any]) -> list[str]:
return fetched
-def _collect(monkeypatch: Any, manager: _FakeResumableManager, **kwargs: Any) -> list[dict]:
+def _collect(
+ monkeypatch: Any, manager: _FakeResumableManager, api_version: str = VAPI_VERSION_V1, **kwargs: Any
+) -> list[dict]:
monkeypatch.setattr(vapi, "Batcher", _FakeBatcher)
monkeypatch.setattr(vapi, "DEFAULT_PAGE_LIMIT", 2)
rows: list[dict] = []
for table in get_rows(
api_key="key",
+ api_version=api_version,
logger=MagicMock(),
resumable_source_manager=manager, # type: ignore[arg-type]
**kwargs,
@@ -286,20 +293,65 @@ class TestUnpaginatedEndpoints:
assert manager.saved == []
+class TestPhoneNumbersVersionDispatch:
+ """phone_numbers is the only resource whose wire contract differs between versions: v1 serves a
+ bare createdAt-descending array at /phone-number, v2 a page-numbered envelope at /v2/phone-number."""
+
+ def test_v1_walks_created_at_descending_array(self, monkeypatch: Any) -> None:
+ pages = {
+ "https://api.vapi.ai/phone-number?limit=2": [
+ {"id": "2", "createdAt": "2026-01-02T00:00:00.000Z"},
+ {"id": "1", "createdAt": "2026-01-01T00:00:00.000Z"},
+ ],
+ "https://api.vapi.ai/phone-number?limit=2&createdAtLt=2026-01-01T00%3A00%3A00.000Z": [],
+ }
+ fetched = _patch_fetch(monkeypatch, pages)
+ rows = _collect(monkeypatch, _FakeResumableManager(), api_version=VAPI_VERSION_V1, endpoint="phone_numbers")
+
+ assert [r["id"] for r in rows] == ["2", "1"]
+ assert fetched == list(pages)
+
+ def test_v2_walks_ascending_pages_at_v2_path(self, monkeypatch: Any) -> None:
+ pages = {
+ "https://api.vapi.ai/v2/phone-number?limit=2&page=1&sortOrder=ASC&sortBy=createdAt": {
+ "results": [
+ {"id": "1", "createdAt": "2026-01-01T00:00:00.000Z"},
+ {"id": "2", "createdAt": "2026-01-02T00:00:00.000Z"},
+ ],
+ "metadata": {"hasNextPage": False},
+ },
+ }
+ fetched = _patch_fetch(monkeypatch, pages)
+ rows = _collect(monkeypatch, _FakeResumableManager(), api_version=VAPI_VERSION_V2, endpoint="phone_numbers")
+
+ assert [r["id"] for r in rows] == ["1", "2"]
+ assert fetched == list(pages)
+
+
class TestVapiSourceResponse:
@parameterized.expand(
[
- ("calls_descending", "calls", "desc", ["createdAt"]),
- ("chats_ascending", "chats", "asc", ["createdAt"]),
- ("files_unpartitioned", "files", "asc", None),
+ ("calls_descending", "calls", VAPI_VERSION_V1, "desc", ["createdAt"]),
+ ("chats_ascending", "chats", VAPI_VERSION_V1, "asc", ["createdAt"]),
+ ("files_unpartitioned", "files", VAPI_VERSION_V1, "asc", None),
+ # phone_numbers flips from a descending cursor (v1) to ascending pages (v2), so the
+ # pipeline's watermark direction must follow the pinned version.
+ ("phone_numbers_v1_descending", "phone_numbers", VAPI_VERSION_V1, "desc", ["createdAt"]),
+ ("phone_numbers_v2_ascending", "phone_numbers", VAPI_VERSION_V2, "asc", ["createdAt"]),
]
)
def test_sort_mode_and_partitioning(
- self, _name: str, endpoint: str, expected_sort_mode: str, expected_partition_keys: list[str] | None
+ self,
+ _name: str,
+ endpoint: str,
+ api_version: str,
+ expected_sort_mode: str,
+ expected_partition_keys: list[str] | None,
) -> None:
response = vapi_source(
api_key="key",
endpoint=endpoint,
+ api_version=api_version,
logger=MagicMock(),
resumable_source_manager=MagicMock(),
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi_source.py
index 03c9184f6d31..b312df66881b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/tests/test_vapi_source.py
@@ -5,7 +5,12 @@ from parameterized import parameterized
from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInputConfigType
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.vapi import VapiSourceConfig
-from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.settings import ENDPOINTS, VAPI_ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.settings import (
+ ENDPOINTS,
+ VAPI_ENDPOINTS,
+ VAPI_VERSION_V1,
+ VAPI_VERSION_V2,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.source import VapiSource
from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.vapi import VapiResumeConfig
from products.warehouse_sources.backend.types import ExternalDataSourceType
@@ -25,6 +30,11 @@ class TestVapiSource:
def test_source_type(self):
assert self.source.source_type == ExternalDataSourceType.VAPI
+ def test_declares_v1_and_v2_with_v2_default(self):
+ # New sources are stamped v2; v1 stays declared so existing pinned rows keep their path.
+ assert self.source.supported_versions == (VAPI_VERSION_V1, VAPI_VERSION_V2)
+ assert self.source.default_version == VAPI_VERSION_V2
+
def test_get_source_config(self):
config = self.source.get_source_config
@@ -119,6 +129,7 @@ class TestVapiSource:
def test_source_for_pipeline_plumbs_arguments(self, mock_vapi_source):
inputs = mock.MagicMock()
inputs.schema_name = "calls"
+ inputs.api_version = VAPI_VERSION_V1
inputs.should_use_incremental_field = True
inputs.db_incremental_field_last_value = "2026-01-01T00:00:00.000Z"
inputs.db_incremental_field_earliest_value = "2025-01-01T00:00:00.000Z"
@@ -134,6 +145,24 @@ class TestVapiSource:
assert kwargs["db_incremental_field_last_value"] == "2026-01-01T00:00:00.000Z"
assert kwargs["db_incremental_field_earliest_value"] == "2025-01-01T00:00:00.000Z"
+ @parameterized.expand(
+ [
+ ("no_pin_defaults_to_v2", None, VAPI_VERSION_V2),
+ ("v1_pin_preserved", VAPI_VERSION_V1, VAPI_VERSION_V1),
+ ("v2_pin_preserved", VAPI_VERSION_V2, VAPI_VERSION_V2),
+ ]
+ )
+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.vapi.source.vapi_source")
+ def test_source_for_pipeline_resolves_api_version(self, _name, pin, expected, mock_vapi_source):
+ inputs = mock.MagicMock()
+ inputs.schema_name = "phone_numbers"
+ inputs.api_version = pin
+ inputs.should_use_incremental_field = False
+
+ self.source.source_for_pipeline(self.config, mock.MagicMock(), inputs)
+
+ assert mock_vapi_source.call_args.kwargs["api_version"] == expected
+
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.vapi.source.vapi_source")
def test_source_for_pipeline_omits_cursors_when_not_incremental(self, mock_vapi_source):
inputs = mock.MagicMock()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/vapi.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/vapi.py
index d206cc06baa5..8cd97a20db66 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/vapi.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vapi/vapi.py
@@ -16,8 +16,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.vapi.settings import (
DEFAULT_PAGE_LIMIT,
VAPI_BASE_URL,
- VAPI_ENDPOINTS,
VapiEndpointConfig,
+ resolve_endpoint,
)
REQUEST_TIMEOUT_SECONDS = 60
@@ -214,6 +214,7 @@ def _drain(
def get_rows(
api_key: str,
endpoint: str,
+ api_version: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[VapiResumeConfig],
should_use_incremental_field: bool = False,
@@ -221,7 +222,7 @@ def get_rows(
db_incremental_field_earliest_value: Optional[Any] = None,
incremental_field: str | None = None,
) -> Iterator[pa.Table]:
- config = VAPI_ENDPOINTS[endpoint]
+ config = resolve_endpoint(endpoint, api_version)
session = _make_session(api_key)
batcher = Batcher(logger=logger, chunk_size=2000, chunk_size_bytes=100 * 1024 * 1024)
@@ -293,6 +294,7 @@ def get_rows(
def vapi_source(
api_key: str,
endpoint: str,
+ api_version: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[VapiResumeConfig],
should_use_incremental_field: bool = False,
@@ -300,13 +302,14 @@ def vapi_source(
db_incremental_field_earliest_value: Optional[Any] = None,
incremental_field: str | None = None,
) -> SourceResponse:
- config = VAPI_ENDPOINTS[endpoint]
+ config = resolve_endpoint(endpoint, api_version)
return SourceResponse(
name=endpoint,
items=lambda: get_rows(
api_key=api_key,
endpoint=endpoint,
+ api_version=api_version,
logger=logger,
resumable_source_manager=resumable_source_manager,
should_use_incremental_field=should_use_incremental_field,