: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(data-warehouse): add 3 missing tables to the ElevenLabs source (#117225)
Tom Owers6dc6b2fe1287
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 47fa0cee3b99..e9cb07612e64 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -4206,9 +4206,9 @@ Diffed against: <https://api.elevenlabs.io/openapi.json>- [x] `/v1/models` — lookup table resolving the model_id carried on history items and conversations (high)- [x] `/v1/workspace/members (and /v1/workspace/groups)` — lookup resolving the workspace user ids attached to history, conversations and usage rows (high)- [x] `/v1/convai/tools and /v1/convai/tools/{tool_id}/executions` — agent tool catalog plus per-execution records — the analytical detail behind agent conversations (medium)-- [ ] `/v1/convai/phone-numbers` — lookup resolving the phone number a Conversational AI call came in on (medium)-- [ ] `/v1/convai/batch-calling/workspace` — batch calling jobs, the campaign-level grouping over outbound conversations (medium)-- [ ] `/v1/user/subscription` — plan quota and current-period usage, needed to turn character stats into utilization (medium)+- [x] `/v1/convai/phone-numbers` — lookup resolving the phone number a Conversational AI call came in on (medium)+- [x] `/v1/convai/batch-calling/workspace` — batch calling jobs, the campaign-level grouping over outbound conversations (medium)+- [x] `/v1/user/subscription` — plan quota and current-period usage, needed to turn character stats into utilization (medium)- [ ] `/v1/convai/knowledge-base (+ /summaries)` — knowledge base documents referenced by agents, resolves document ids seen in agent configs (medium)- [ ] `/v1/convai/tags` — tag lookup for grouping agents and conversations in reporting (medium)- [ ] `/v1/workspace/audit-logs` — state/transition history across workspace resources (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/canonical_descriptions.pyindex bb07899337d5..490710377651 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/canonical_descriptions.py@@ -159,4 +159,56 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"error_type": "Error category, if the execution failed.",},},+ "phone_numbers": {+ "description": "Phone numbers that Conversational AI agents use for inbound and outbound calls. One row per phone number.",+ "docs_url": "https://elevenlabs.io/docs/api-reference/phone-numbers/list",+ "columns": {+ "phone_number_id": "Unique identifier for the phone number.",+ "phone_number": "The phone number.",+ "label": "Label given to the phone number.",+ "provider": "Telephony provider of the phone number (twilio, exotel, or sip_trunk).",+ "assigned_agent": "The agent assigned to the phone number, with its ID and name.",+ "outbound_trunk": "Outbound SIP trunk configuration, for SIP trunk numbers. Header values are redacted.",+ "inbound_trunk": "Inbound SIP trunk configuration, for SIP trunk numbers.",+ },+ },+ "batch_calls": {+ "description": "Outbound batch calling jobs in your workspace. One row per batch call job.",+ "docs_url": "https://elevenlabs.io/docs/api-reference/batch-calling/list",+ "columns": {+ "id": "Unique identifier for the batch call job.",+ "name": "Name of the batch call job.",+ "agent_id": "Identifier of the agent that places the calls.",+ "agent_name": "Display name of the agent that places the calls.",+ "phone_number_id": "Identifier of the phone number the calls are placed from.",+ "phone_provider": "Telephony provider used to place the calls.",+ "status": "Status of the job (pending, in_progress, completed, failed, or cancelled).",+ "created_at_unix": "Creation time of the job, in Unix seconds.",+ "scheduled_time_unix": "Time the job is scheduled to start, in Unix seconds.",+ "last_updated_at_unix": "Last update time of the job, in Unix seconds.",+ "total_calls_scheduled": "Number of calls scheduled in the job.",+ "total_calls_dispatched": "Number of calls dispatched so far.",+ "total_calls_finished": "Number of calls finished so far.",+ "retry_count": "Number of times the job was retried.",+ },+ },+ "subscription": {+ "description": "Subscription plan, quota, and current billing period usage. A single row that each sync replaces.",+ "docs_url": "https://elevenlabs.io/docs/api-reference/user/subscription/get",+ "columns": {+ "tier": "Tier of the subscription.",+ "status": "Status of the subscription.",+ "character_count": "Number of characters (credits) used in the current billing period.",+ "character_limit": "Maximum number of characters (credits) allowed in the current billing period.",+ "next_character_count_reset_unix": "Time of the next character count reset, in Unix seconds.",+ "voice_slots_used": "Number of voice slots in use.",+ "voice_limit": "Maximum number of voice slots allowed.",+ "professional_voice_limit": "Maximum number of professional voices allowed.",+ "billing_period": "Billing period of the subscription.",+ "currency": "Currency of the subscription.",+ "current_overage": "Current usage-based overage cost.",+ "next_invoice": "The next invoice.",+ "open_invoices": "Open invoices.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.pyindex d80bb71548dd..7f39f3501c1b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.py@@ -1,5 +1,5 @@import dataclasses-from collections.abc import Mapping+from collections.abc import Callable, Mappingfrom datetime import UTC, date, datetimefrom typing import Any, Optional, cast@@ -30,9 +30,6 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.elevenlabsELEVENLABS_BASE_URL = "https://api.elevenlabs.io"REDACTED = "[REDACTED]"-# Webhook tools can carry literal credentials in their configured request headers, and executions echo-# the headers that were sent. Warehouse readers must not be able to read them back.-SECRET_BEARING_ENDPOINTS = frozenset({"tools", "tool_executions"})@dataclasses.dataclass@@ -84,6 +81,25 @@ def _redact_tool_secrets(row: dict[str, Any]) -> dict[str, Any]:return row+def _redact_phone_number_secrets(row: dict[str, Any]) -> dict[str, Any]:+ # `provider_config` is the deprecated alias of `outbound_trunk`, so both carry the same SIP headers.+ for key in ("outbound_trunk", "provider_config"):+ trunk = row.get(key)+ if isinstance(trunk, dict) and "headers" in trunk:+ trunk["headers"] = _redact_header_values(trunk["headers"])+ return row+++# Webhook tools can carry literal credentials in their configured request headers, executions echo the+# headers that were sent, and SIP trunks can send custom auth headers on each call. Warehouse readers+# must not be able to read them back.+SECRET_REDACTORS: dict[str, Callable[[dict[str, Any]], dict[str, Any]]] = {+ "tools": _redact_tool_secrets,+ "tool_executions": _redact_tool_secrets,+ "phone_numbers": _redact_phone_number_secrets,+}++def _build_params(config: ElevenLabsEndpointConfig,should_use_incremental_field: bool,@@ -96,7 +112,7 @@ def _build_params(API keeps the time-window filter alongside the cursor), so pagination terminates at `has_more`rather than re-walking full history each incremental run."""- params: dict[str, Any] = {} if config.page_size is None else {"page_size": config.page_size}+ params: dict[str, Any] = {} if config.page_size is None else {config.page_size_param: config.page_size}params.update(config.extra_params)if (@@ -199,7 +215,7 @@ def validate_credentials(api_key: str, schema_name: Optional[str] = None) -> tupconfig = ELEVENLABS_ENDPOINTS[config.fanout.parent_name]probe_path = config.path if config else "/v1/user"# Bake the probe's page_size into the URL: validate_via_probe issues a bare GET with no params.- url = f"{ELEVENLABS_BASE_URL}{probe_path}{'?page_size=1' if config and config.page_size else ''}"+ url = f"{ELEVENLABS_BASE_URL}{probe_path}{f'?{config.page_size_param}=1' if config and config.page_size else ''}"# Don't follow redirects: requests preserves the custom `xi-api-key` header across a cross-origin# 3xx, so a redirect off the fixed API host could replay the key to another origin.@@ -281,11 +297,11 @@ def elevenlabs_source(},child_endpoint_extra={"paginator": _paginator(config), "data_selector": config.items_key},child_params_extra=params,- page_size_param="page_size",+ page_size_param=config.page_size_param,),)- if endpoint in SECRET_BEARING_ENDPOINTS:- resource.add_map(_redact_tool_secrets)+ if endpoint in SECRET_REDACTORS:+ resource.add_map(SECRET_REDACTORS[endpoint])return SourceResponse(name=endpoint,items=lambda: resource,@@ -330,8 +346,8 @@ def elevenlabs_source(resume_hook=save_checkpoint,initial_paginator_state=initial_paginator_state,)- if endpoint in SECRET_BEARING_ENDPOINTS:- resource.add_map(_redact_tool_secrets)+ if endpoint in SECRET_REDACTORS:+ resource.add_map(SECRET_REDACTORS[endpoint])return SourceResponse(name=endpoint,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/settings.pyindex 92d4215074e9..5ab790724198 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/settings.py@@ -15,13 +15,15 @@ class ElevenLabsEndpointConfig:# Top-level array key in the JSON response body (differs per endpoint: history/conversations/...).# A JSONPath such as "$.*" selects the values of a body keyed by id; None takes a bare-array body.items_key: Optional[str]- primary_keys: list[str]+ # None for single-row snapshot tables that are replaced wholesale, so there is nothing to merge on.+ primary_keys: Optional[list[str]]# Query param used to request the next page, and the response field that carries the next cursor.# ElevenLabs uses three different cursor styles across endpoint families. Both None for# unpaginated endpoints that return the whole collection in one body.cursor_param: Optional[str] = Nonecursor_response_key: Optional[str] = Nonepage_size: Optional[int] = None+ page_size_param: str = "page_size"# None for tables without a stable creation timestamp; those small tables stay unpartitioned.partition_key: Optional[str] = None# Stable, monotonic incremental column and the server-side filter param that bounds it. Both None@@ -196,6 +198,33 @@ ELEVENLABS_ENDPOINTS: dict[str, ElevenLabsEndpointConfig] = {parent_params={"sort_by": "created_at", "sort_direction": "asc"},),),+ # Phone numbers that Conversational AI agents take and place calls on. Returned as one bare array.+ "phone_numbers": ElevenLabsEndpointConfig(+ name="phone_numbers",+ path="/v1/convai/phone-numbers",+ items_key=None,+ primary_keys=["phone_number_id"],+ ),+ # Outbound batch calling jobs. Mutable (status and call counters change while the job runs) with no+ # updated-since filter, so full refresh only.+ "batch_calls": ElevenLabsEndpointConfig(+ name="batch_calls",+ path="/v1/convai/batch-calling/workspace",+ items_key="batch_calls",+ cursor_param="last_doc",+ cursor_response_key="next_doc",+ primary_keys=["id"],+ page_size=100,+ page_size_param="limit",+ partition_key="created_at_unix",+ ),+ # Plan quota and current-period usage, returned as one object that becomes a single row.+ "subscription": ElevenLabsEndpointConfig(+ name="subscription",+ path="/v1/user/subscription",+ items_key=None,+ primary_keys=None,+ ),}ENDPOINTS = tuple(ELEVENLABS_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/source.pyindex b2bf88c87fd4..ac02c6a27189 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/source.py@@ -67,10 +67,11 @@ You can create an API key in your [ElevenLabs account settings](https://elevenlaGrant the following read permissions when creating the key:- **History** (text-to-speech generation history)-- **Conversational AI** (conversations, agents, triage tickets, tools, and tool executions)+- **Conversational AI** (conversations, agents, triage tickets, tools, tool executions, phone numbers, and batch calls)- **Voices**- **Models**- **Workspace** (members and groups)+- **User** (subscription)""",iconPath="/static/services/elevenlabs.svg",docsUrl="https://posthog.com/docs/cdp/sources/elevenlabs",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.pyindex bad11ace6ee9..7c1937597ddb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.py@@ -73,24 +73,43 @@ class TestBuildParams:class TestPagination:- def test_walks_cursor_pages_and_saves_state_after_each_yield(self) -> None:+ @parameterized.expand(+ [+ (+ "history",+ "history",+ "history_item_id",+ "start_after_history_item_id",+ "last_history_item_id",+ "page_size",+ "1000",+ ),+ ("batch_calls", "batch_calls", "id", "last_doc", "next_doc", "limit", "100"),+ ]+ )+ def test_walks_cursor_pages_and_saves_state_after_each_yield(+ self,+ endpoint: str,+ items_key: str,+ id_key: str,+ cursor_param: str,+ cursor_response_key: str,+ page_size_param: str,+ page_size: str,+ ) -> None:result = _driver().run(- "history",+ endpoint,[- ScriptedResponse(- json={"history": [{"history_item_id": "a"}], "has_more": True, "last_history_item_id": "a"}- ),- ScriptedResponse(- json={"history": [{"history_item_id": "b"}], "has_more": False, "last_history_item_id": "b"}- ),+ ScriptedResponse(json={items_key: [{id_key: "a"}], "has_more": True, cursor_response_key: "a"}),+ ScriptedResponse(json={items_key: [{id_key: "b"}], "has_more": False, cursor_response_key: "b"}),],)assert result.raised is None- assert result.rows == [{"history_item_id": "a"}, {"history_item_id": "b"}]+ assert result.rows == [{id_key: "a"}, {id_key: "b"}]# Page 1 sends no cursor; page 2 sends the cursor from page 1 under the endpoint's cursor param.- assert result.params("start_after_history_item_id") == [None, "a"]- assert result.params("page_size") == ["1000", "1000"]+ assert result.params(cursor_param) == [None, "a"]+ assert result.params(page_size_param) == [page_size, page_size]# Saved only once (after page 1, since page 2 is terminal) so a crash re-yields the last page.assert result.saved_states == [ElevenLabsResumeConfig(cursor="a")]@@ -200,10 +219,30 @@ class TestSecretRedaction:],lambda row: row["tool_call_details"]["headers"],),+ *[+ (+ f"sip_trunk_{trunk_key}_headers",+ "phone_numbers",+ [+ [+ {+ "phone_number_id": "p1",+ "provider": "sip_trunk",+ trunk_key: {+ "address": "sip.example.com",+ "headers": {"Authorization": "Bearer sk_fake", "X-Ref": {"secret_id": "s1"}},+ },+ }+ ]+ ],+ lambda row, key=trunk_key: row[key]["headers"],+ )+ for trunk_key in ("outbound_trunk", "provider_config")+ ],])def test_literal_header_values_never_reach_the_warehouse(- self, _name: str, endpoint: str, bodies: list[dict[str, Any]], headers_of: Callable[[Any], Any]+ self, _name: str, endpoint: str, bodies: list[Any], headers_of: Callable[[Any], Any]) -> None:result = _driver().run(endpoint, [ScriptedResponse(json=body) for body in bodies])@@ -226,6 +265,21 @@ class TestUnpaginatedEndpoints:# jsonpath unwraps a single match, so a one-group body must still come back as one row.("single_group", "workspace_groups", {"g1": {"id": "g1", "name": "a"}}, ["g1"], "id"),("no_groups", "workspace_groups", {}, [], "id"),+ (+ "phone_numbers_bare_array",+ "phone_numbers",+ [{"phone_number_id": "p1", "provider": "twilio"}, {"phone_number_id": "p2", "provider": "exotel"}],+ ["p1", "p2"],+ "phone_number_id",+ ),+ # The subscription is one object, not a list, and must land as a single snapshot row.+ (+ "subscription_single_object",+ "subscription",+ {"tier": "creator", "character_count": 1200, "character_limit": 100000},+ ["creator"],+ "tier",+ ),])def test_whole_collection_becomes_rows(@@ -264,6 +318,11 @@ class TestValidateCredentials:[("fan_out_child_probes_parent", "tool_executions", "https://api.elevenlabs.io/v1/convai/tools?page_size=1"),("unpaginated_sends_no_page_size", "workspace_members", "https://api.elevenlabs.io/v1/workspace/members"),+ (+ "custom_page_size_param",+ "batch_calls",+ "https://api.elevenlabs.io/v1/convai/batch-calling/workspace?limit=1",+ ),])def test_schema_probe_url(self, _name: str, schema_name: str, expected_url: str) -> None:@@ -309,10 +368,14 @@ class TestSourceResponse:("tools", ["id"], "asc", None),# Executions from different tools interleave in time, so the watermark must wait for job end.("tool_executions", ["tool_id", "id"], "desc", None),+ ("phone_numbers", ["phone_number_id"], "asc", None),+ ("batch_calls", ["id"], "asc", "created_at_unix"),+ # A single snapshot row has no unique column to merge on; full refresh replaces it.+ ("subscription", None, "asc", None),])def test_response_shape_per_endpoint(- self, endpoint: str, primary_keys: list[str], sort_mode: str, partition_key: str | None+ self, endpoint: str, primary_keys: list[str] | None, sort_mode: str, partition_key: str | None) -> None:# sort_mode="asc" on a newest-first endpoint corrupts the watermark; the pk must be table-unique.result = _driver().run(endpoint, [ScriptedResponse(json={})])diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs_source.pyindex d9f4274290e0..4da708f580e1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs_source.py@@ -27,6 +27,9 @@ class TestElevenLabsSchemas:("tools", False, False),# Executions take a server-side `start_time` filter, so they merge incrementally.("tool_executions", True, False),+ ("phone_numbers", False, False),+ ("batch_calls", False, False),+ ("subscription", False, False),])def test_schema_sync_capabilities(self, endpoint: str, incremental: bool, append: bool) -> None: