: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 anthropic API version 2026-10-21 (#126952)
Tom Owersc98d42974c1c
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex 173e7e2e6b99..002131c178fb 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -117,6 +117,7 @@ The opposite gap also occurs: a reference rendered from one version-blind OpenAP- A partial move that changes the resource's id scheme (internal integer → public UUID) breaks joins between the moved tables and the tables left on the legacy wire, which still carry the old foreign key. Say so in the PR and treat the repin as lossy.- A version that changes the pagination _mechanism_ (e.g. offset→cursor, or one opaque cursor param for another, since a token one generation issued means nothing to the other) also changes the resumable checkpoint's persisted shape. Add a new defaulted field to the resume-config dataclass rather than repurposing the existing one — so state persisted under the old version still decodes — and make the seed and save-checkpoint logic dispatch on the resolved version. Reusing one field across incompatible mechanisms corrupts in-flight resumes of the other version. When a table stays on its old wire under the new pin, key the check on the wire that issued the cursor, not on the pin. When both mechanisms are positional with a fixed page size (offset↔page number), keep the existing field instead: let the new version's paginator derive its page from the stored offset, so one checkpoint means the same row under either pin.- Other products can read a synced table's columns by name, e.g. a signal emitter registered on `(source_type, table)` in `products/signals/backend/emission/registry.py`. Grep for the source type outside its directory before a new version renames or nests a column such a reader uses, and keep that column under its old name on the new version's rows.+- A version that only renames response fields a table already exposes (no new data) maps the new names back onto the existing columns in the row mapper, rather than letting the new pin's rows carry new column names. A renamed field can be a merge key or a fan-out stamp, and a table that changes shape by pin also invalidates its canonical column descriptions. Where a rename also changes the meaning of a value (a null that now means something else), keep the column and update its description to cover both pins.- When the vendor renames a collection between versions, keep the schema/table name set identical across versions and put the rename in a per-version path on the endpoint config — otherwise discovery diffs orphan the table on repin.- A table gated to an explicit list of versions (an endpoint added by an earlier bump) drops off a new default unless the new label joins that list. Before flipping the default, extend every such list for each endpoint the new version still serves.- When the new version has no equivalent for an old endpoint (a dropped collection, not a rename), keep that table only on the versions that serve it and let the table set differ by version — never map it to a guessed path just to keep the sets equal, since docs are the sole source of truth and an unverified path makes a new source surface a table that 404s at sync time.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/anthropic.py b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/anthropic.pyindex 7b60c40c1cc3..0c1b03c37aa5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/anthropic.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/anthropic.py@@ -22,6 +22,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.anthropic.FanOutConfig,PaginationType,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSIONfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_sessionfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (RESTAPIConfig,@@ -40,7 +41,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.soufrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponseANTHROPIC_BASE_URL = "https://api.anthropic.com"-ANTHROPIC_VERSION = "2023-06-01"+ANTHROPIC_VERSION_2023_06_01 = "2023-06-01"+# Renames Admin API and Claude Enterprise Analytics response fields and drops the old names. The rows+# are mapped back onto the 2023-06-01 column names, so a table keeps one shape under either pin.+ANTHROPIC_VERSION_2026_10_21 = "2026-10-21"# Entity list endpoints allow up to 1000 per page.ENTITY_PAGE_SIZE = 1000# Attempts per request for the entity list endpoints (users, workspaces, api_keys, ...). They are@@ -233,10 +237,53 @@ class ClaudeCodeDayPaginator(BasePaginator):return f"ClaudeCodeDayPaginator(current_day={self._current_day}, today={self._today})"-def _version_headers() -> dict[str, str]:+def _wire_version(api_version: str) -> str:+ # Sources created before this source declared versions were backfilled with the unversioned+ # label. They always sent 2023-06-01, so they keep sending it.+ return ANTHROPIC_VERSION_2023_06_01 if api_version == UNVERSIONED_API_VERSION else api_version+++def _version_headers(api_version: str) -> dict[str, str]:# Auth (x-api-key) is supplied via the framework auth config so its value is redacted from# logs; only the non-secret version/accept headers are set here.- return {"anthropic-version": ANTHROPIC_VERSION, "accept": "application/json"}+ return {"anthropic-version": _wire_version(api_version), "accept": "application/json"}+++def _is_legacy_version(api_version: str) -> bool:+ return _wire_version(api_version) == ANTHROPIC_VERSION_2023_06_01+++# Response fields 2026-10-21 renamed, per endpoint, mapped from the new name back to the column name.+_RENAMED_FIELDS: dict[str, dict[str, str]] = {+ "rbac_groups": {"role_ids": "roles"},+ "rbac_group_members": {"rbac_group_id": "group_id"},+ "rbac_roles": {"display_name": "name"},+}+++def _restore_renamed_fields(renames: dict[str, str], item: dict[str, Any]) -> dict[str, Any]:+ item = {**item}+ for new_name, column in renames.items():+ if new_name in item:+ item[column] = item.pop(new_name)+ return item+++def _flatten_api_key_scope(item: dict[str, Any]) -> dict[str, Any]:+ """2026-10-21 replaces an API key's `workspace_id` with a `scope` object; surface it as the column.++ Unlike 2023-06-01, a key bound to the Default Workspace carries that workspace's real id, and only+ an organization-scoped key leaves the column null.+ """+ item = {**item}+ scope = item.pop("scope", None)+ item["workspace_id"] = scope.get("workspace_id") if isinstance(scope, dict) else None+ return item+++def _data_selector(config: AnthropicEndpointConfig, api_version: str) -> str:+ # 2026-10-21 serves the summaries rows under `data` too, like every other endpoint.+ return config.data_selector if _is_legacy_version(api_version) else "data"def _auth_config(api_key: str) -> ApiKeyAuthConfig:@@ -267,14 +314,14 @@ VALIDATION_UNREACHABLE_MESSAGE = ()-def validate_credentials(api_key: str) -> tuple[bool, Optional[str]]:+def validate_credentials(api_key: str, api_version: str) -> tuple[bool, Optional[str]]:# A single cheap probe against the smallest list endpoint confirms the admin key is genuine.# 200 => valid. 403 => valid key without a scope we probed here; still a real key, so accept it# at create time (sync-time 403s are caught by get_non_retryable_errors). 401 => bad key.ok, status = validate_via_probe(lambda: make_tracked_session(redact_values=(api_key,)),f"{ANTHROPIC_BASE_URL}/v1/organizations/users?limit=1",- headers={"x-api-key": api_key, **_version_headers()},+ headers={"x-api-key": api_key, **_version_headers(api_version)},ok_statuses=(200, 403),)if ok:@@ -286,7 +333,7 @@ def validate_credentials(api_key: str) -> tuple[bool, Optional[str]]:return False, INVALID_ADMIN_KEY_MESSAGE-def _check_path_access(api_key: str, path: str, missing_reason: str) -> Optional[str]:+def _check_path_access(api_key: str, api_version: str, path: str, missing_reason: str) -> Optional[str]:"""Report whether the configured key can read a path that needs access beyond the Admin API key.Returns None when it can, or the reason to show against the tables that need it. Only a real@@ -297,7 +344,7 @@ def _check_path_access(api_key: str, path: str, missing_reason: str) -> Optional_ok, status = validate_via_probe(lambda: make_tracked_session(redact_values=(api_key,)),f"{ANTHROPIC_BASE_URL}{path}",- headers={"x-api-key": api_key, **_version_headers()},+ headers={"x-api-key": api_key, **_version_headers(api_version)},)# 404 as well as 403: an organization that is not on a Claude Enterprise plan does not serve# these routes at all.@@ -306,18 +353,18 @@ def _check_path_access(api_key: str, path: str, missing_reason: str) -> Optionalreturn None-def check_analytics_access(api_key: str) -> Optional[str]:- return _check_path_access(api_key, f"{ANALYTICS_PATH_PREFIX}users?limit=1", ANALYTICS_ACCESS_MISSING)+def check_analytics_access(api_key: str, api_version: str) -> Optional[str]:+ return _check_path_access(api_key, api_version, f"{ANALYTICS_PATH_PREFIX}users?limit=1", ANALYTICS_ACCESS_MISSING)-def check_rbac_group_access(api_key: str) -> Optional[str]:- return _check_path_access(api_key, f"{RBAC_GROUPS_PATH}?limit=1", RBAC_GROUP_ACCESS_MISSING)+def check_rbac_group_access(api_key: str, api_version: str) -> Optional[str]:+ return _check_path_access(api_key, api_version, f"{RBAC_GROUPS_PATH}?limit=1", RBAC_GROUP_ACCESS_MISSING)-def check_rbac_role_access(api_key: str) -> Optional[str]:+def check_rbac_role_access(api_key: str, api_version: str) -> Optional[str]:# The custom role reads take their own scope, so a key that reaches the group tables can still# be denied here.- return _check_path_access(api_key, f"{RBAC_ROLES_PATH}?limit=1", RBAC_ROLE_ACCESS_MISSING)+ return _check_path_access(api_key, api_version, f"{RBAC_ROLES_PATH}?limit=1", RBAC_ROLE_ACCESS_MISSING)def _flatten_created_by(item: dict[str, Any]) -> dict[str, Any]:@@ -722,12 +769,12 @@ _FAN_OUT_ROW_MAPS: dict[str, Callable[[dict[str, Any]], dict[str, Any]]] = {}-def _analytics_actor_columns(item: dict[str, Any]) -> dict[str, Any]:+def _analytics_actor_columns(item: dict[str, Any], api_version: str) -> dict[str, Any]:"""Surface the seat user a per-user report row is attributed to as flat columns."""actor = item.get("actor") or {}return {"user_id": actor.get("user_id"),- "user_email": actor.get("email"),+ "user_email": actor.get("email") if _is_legacy_version(api_version) else actor.get("email_address"),"user_name": actor.get("name"),"user_deleted": actor.get("deleted"),}@@ -736,10 +783,10 @@ def _analytics_actor_columns(item: dict[str, Any]) -> dict[str, Any]:# The per-user report requests carry no `group_by`, so the dimension fields Anthropic populates only# for a grouped query (model, product, cost_type, token_type, context_window, inference_geo, speed,# rbac_group_id, and the Claude Tag and Slack fields) are null on every row and are left out below.-def _flatten_analytics_user_cost(item: dict[str, Any]) -> dict[str, Any]:+def _flatten_analytics_user_cost(api_version: str, item: dict[str, Any]) -> dict[str, Any]:"""One row per (day, user): cost attributed to that seat user for that day."""starting_at = item.get("starting_at")- actor = _analytics_actor_columns(item)+ actor = _analytics_actor_columns(item, api_version)return {"id": _row_id(starting_at, actor["user_id"]),"starting_at": starting_at,@@ -754,10 +801,10 @@ def _flatten_analytics_user_cost(item: dict[str, Any]) -> dict[str, Any]:}-def _flatten_analytics_user_usage(item: dict[str, Any]) -> dict[str, Any]:+def _flatten_analytics_user_usage(api_version: str, item: dict[str, Any]) -> dict[str, Any]:"""One row per (day, user): token usage attributed to that seat user for that day."""starting_at = item.get("starting_at")- actor = _analytics_actor_columns(item)+ actor = _analytics_actor_columns(item, api_version)cache_creation = item.get("cache_creation") or {}server_tool_use = item.get("server_tool_use") or {}return {@@ -830,6 +877,7 @@ def anthropic_source(team_id: int,job_id: str,resumable_source_manager: ResumableSourceManager[AnthropicResumeConfig],+ api_version: str,db_incremental_field_last_value: Optional[Any] = None,) -> SourceResponse:config = ANTHROPIC_ENDPOINTS.get(endpoint)@@ -846,7 +894,7 @@ def anthropic_source(is_report_endpoint = config.pagination == PaginationType.PAGEclient_config: ClientConfig = {"base_url": ANTHROPIC_BASE_URL,- "headers": _version_headers(),+ "headers": _version_headers(api_version),"auth": _auth_config(api_key),"max_retries": REPORT_MAX_RETRY_ATTEMPTS if is_report_endpoint else MAX_RETRY_ATTEMPTS,}@@ -855,6 +903,7 @@ def anthropic_source(client_config["retry_budget_seconds"] = REPORT_RETRY_BUDGET_SECONDSresume = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None+ renames = {} if _is_legacy_version(api_version) else _RENAMED_FIELDS.get(endpoint, {})if config.analytics_window is not None:# Claude Enterprise Analytics: one request per UTC day, each day its own resource so the@@ -880,7 +929,10 @@ def anthropic_source(if config.analytics_window == AnalyticsWindowKind.DATE_RANGE:# A summary row is already flat and carries its own `starting_at`.return None- return _flatten_analytics_user_cost if endpoint == "analytics_user_cost" else _flatten_analytics_user_usage+ flatten = (+ _flatten_analytics_user_cost if endpoint == "analytics_user_cost" else _flatten_analytics_user_usage+ )+ return partial(flatten, api_version)def save_analytics_checkpoint(next_start: date) -> None:resumable_source_manager.save_state(@@ -893,7 +945,7 @@ def anthropic_source("endpoint": {"path": config.path,"params": _analytics_params(config, window),- "data_selector": config.data_selector,+ "data_selector": _data_selector(config, api_version),"paginator": AnthropicCursorPaginator(cursor_path="next_page", cursor_param="page"),},"data_map": analytics_row_map(window),@@ -966,7 +1018,7 @@ def anthropic_source(child_row_map = _FAN_OUT_ROW_MAPS.get(endpoint)def fan_out_data_map(row: dict[str, Any]) -> dict[str, Any]:- stamped = _stamp_parent_id(fan_out, row)+ stamped = _stamp_parent_id(fan_out, _restore_renamed_fields(renames, row))return child_row_map(stamped) if child_row_map else stampedrest_config: RESTAPIConfig = {@@ -1031,8 +1083,14 @@ def anthropic_source(data_map: Optional[Callable[[dict[str, Any]], dict[str, Any] | list[dict[str, Any]]]]if is_report:data_map = _explode_usage_bucket if endpoint == "usage_report" else _explode_cost_bucket+ elif endpoint == "api_keys":+ data_map = (+ _flatten_created_by+ if _is_legacy_version(api_version)+ else lambda item: _flatten_api_key_scope(_flatten_created_by(item))+ )else:- data_map = _flatten_created_by if endpoint == "api_keys" else None+ data_map = partial(_restore_renamed_fields, renames) if renames else Noneinitial_paginator_state: Optional[dict[str, Any]] = Noneif resume is not None and resume.cursor:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/canonical_descriptions.pyindex 4545c8d24b83..864a43df52d4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/canonical_descriptions.py@@ -51,7 +51,11 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"id": "Unique identifier for the API key.","type": 'Object type, always "api_key".',"name": "Display name of the API key.",- "workspace_id": "ID of the workspace the key belongs to, or null for the default workspace.",+ "workspace_id": (+ "ID of the workspace the key belongs to. On API version 2023-06-01 it is null for the default "+ "workspace. From 2026-10-21 it holds the default workspace's real ID, and is null only for a key "+ "scoped to the whole organization."+ ),"created_at": "RFC 3339 timestamp of when the API key was created.","created_by_id": "ID of the actor that created the API key.","created_by_type": "Type of the actor that created the API key.",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.pyindex be25e20af959..0f5469638fc2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/source.py@@ -10,6 +10,8 @@ from products.warehouse_sources.backend.facade.source_config import (SourceFieldInputConfigType,)from products.warehouse_sources.backend.temporal.data_imports.sources.anthropic.anthropic import (+ ANTHROPIC_VERSION_2023_06_01,+ ANTHROPIC_VERSION_2026_10_21,AnthropicResumeConfig,anthropic_source,check_analytics_access,@@ -107,8 +109,8 @@ class AnthropicSource(ResumableSource[AnthropicSourceConfig, AnthropicResumeConf)lists_tables_without_credentials = True # static endpoint catalog — safe for public docs- supported_versions = ("2023-06-01",)- default_version = "2023-06-01"+ supported_versions = (ANTHROPIC_VERSION_2023_06_01, ANTHROPIC_VERSION_2026_10_21)+ default_version = ANTHROPIC_VERSION_2026_10_21api_docs_url = "https://platform.claude.com/docs/en/api/versioning"@property@@ -223,6 +225,7 @@ The group, group membership and custom role tables come from the Claude EnterpriAccessFamily.RBAC_GROUPS: check_rbac_group_access,AccessFamily.RBAC_ROLES: check_rbac_role_access,}+ resolved_version = self.resolve_api_version(api_version)permissions: dict[str, str | None] = dict.fromkeys(endpoints)by_family: dict[AccessFamily, list[str]] = defaultdict(list)for name in endpoints:@@ -231,7 +234,7 @@ The group, group membership and custom role tables come from the Claude Enterpriby_family[endpoint_config.access_family].append(name)for family, names in by_family.items():# Every endpoint in a family needs the same access, so one probe answers for all of them.- reason = probes[family](config.api_key)+ reason = probes[family](config.api_key, resolved_version)for name in names:permissions[name] = reasonreturn permissions@@ -243,7 +246,7 @@ The group, group membership and custom role tables come from the Claude Enterprischema_name: Optional[str] = None,api_version: str | None = None,) -> tuple[bool, str | None]:- return validate_anthropic_credentials(config.api_key)+ return validate_anthropic_credentials(config.api_key, self.resolve_api_version(api_version))def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[AnthropicResumeConfig]:return ResumableSourceManager[AnthropicResumeConfig](inputs, AnthropicResumeConfig)@@ -260,6 +263,7 @@ The group, group membership and custom role tables come from the Claude Enterpriteam_id=inputs.team_id,job_id=inputs.job_id,resumable_source_manager=resumable_source_manager,+ api_version=self.resolve_api_version(inputs.api_version),db_incremental_field_last_value=inputs.db_incremental_field_last_valueif inputs.should_use_incremental_fieldelse None,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.py b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.pyindex bc4b372fa6e7..1089c486416a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/tests/test_anthropic.py@@ -9,6 +9,8 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.common.s)from products.warehouse_sources.backend.temporal.data_imports.sources.anthropic.anthropic import (ANALYTICS_ACCESS_MISSING,+ ANTHROPIC_VERSION_2023_06_01,+ ANTHROPIC_VERSION_2026_10_21,INVALID_ADMIN_KEY_MESSAGE,STANDARD_KEY_MESSAGE,VALIDATION_UNREACHABLE_MESSAGE,@@ -249,7 +251,7 @@ class TestValidateCredentials:def test_status_mapping(self, _name: str, api_key: str, status: int, expected: tuple[bool, str | None]) -> None:# 403 is accepted at create time (real key, unprobed scope); 401 means a bad key.with scripted_network([ScriptedResponse(status=status)]) as network:- assert validate_credentials(api_key) == expected+ assert validate_credentials(api_key, ANTHROPIC_VERSION_2026_10_21) == expectedassert network.requests_log[0].path == "/v1/organizations/users"assert network.requests_log[0].param("limit") == "1"@@ -511,7 +513,7 @@ class TestAnalyticsAccessProbe:)def test_status_mapping(self, _name: str, status: int, expected: str | None) -> None:with scripted_network([ScriptedResponse(status=status, json={})]) as network:- assert check_analytics_access("sk-ant-admin-test") == expected+ assert check_analytics_access("sk-ant-admin-test", ANTHROPIC_VERSION_2026_10_21) == expectedassert network.requests_log[0].path == f"{ANALYTICS_PATH_PREFIX}users"@@ -677,3 +679,177 @@ class TestRbacNonRetryableErrors:matched = [message for pattern, message in errors.items() if error_message_matches(observed, [pattern])]assert matched, "a group or role denial must be non-retryable"assert expected_scope in (matched[0] or "")+++_V1 = ANTHROPIC_VERSION_2023_06_01+_V2 = ANTHROPIC_VERSION_2026_10_21+++class TestApiVersionDispatch:+ @parameterized.expand(+ [+ (+ "api_keys_legacy",+ "api_keys",+ _V1,+ [_entity_page([{"id": "k1", "workspace_id": "w1"}], has_more=False, last_id="k1")],+ {"workspace_id": "w1"},+ [],+ ),+ (+ "api_keys_workspace_scope",+ "api_keys",+ _V2,+ [+ _entity_page(+ [{"id": "k1", "scope": {"type": "workspace", "workspace_id": "w1"}}],+ has_more=False,+ last_id="k1",+ )+ ],+ {"workspace_id": "w1"},+ ["scope"],+ ),+ (+ "api_keys_organization_scope",+ "api_keys",+ _V2,+ [_entity_page([{"id": "k1", "scope": {"type": "organization"}}], has_more=False, last_id="k1")],+ {"workspace_id": None},+ ["scope"],+ ),+ (+ "rbac_groups_legacy",+ "rbac_groups",+ _V1,+ [_token_page([{"id": "g1", "roles": ["r1"]}], has_more=False, next_page=None)],+ {"roles": ["r1"]},+ [],+ ),+ (+ "rbac_groups_renamed",+ "rbac_groups",+ _V2,+ [_token_page([{"id": "g1", "role_ids": ["r1"]}], has_more=False, next_page=None)],+ {"roles": ["r1"]},+ ["role_ids"],+ ),+ (+ "rbac_group_members_legacy",+ "rbac_group_members",+ _V1,+ [+ _token_page([{"id": "g1"}], has_more=False, next_page=None),+ _token_page([{"group_id": "g1", "user_id": "u1"}], has_more=False, next_page=None),+ ],+ {"group_id": "g1", "user_id": "u1"},+ [],+ ),+ (+ "rbac_group_members_renamed",+ "rbac_group_members",+ _V2,+ [+ _token_page([{"id": "g1"}], has_more=False, next_page=None),+ _token_page([{"rbac_group_id": "g1", "user_id": "u1"}], has_more=False, next_page=None),+ ],+ {"group_id": "g1", "user_id": "u1"},+ ["rbac_group_id"],+ ),+ (+ "rbac_roles_legacy",+ "rbac_roles",+ _V1,+ [_token_page([{"id": "r1", "name": "Admins"}], has_more=False, next_page=None)],+ {"name": "Admins"},+ [],+ ),+ (+ "rbac_roles_renamed",+ "rbac_roles",+ _V2,+ [_token_page([{"id": "r1", "display_name": "Admins"}], has_more=False, next_page=None)],+ {"name": "Admins"},+ ["display_name"],+ ),+ (+ "analytics_user_cost_legacy",+ "analytics_user_cost",+ _V1,+ [_report_page([_user_report_row()], has_more=False, next_page=None)],+ {"user_email": "[email protected]"},+ [],+ ),+ (+ "analytics_user_cost_renamed",+ "analytics_user_cost",+ _V2,+ [+ _report_page(+ [{**_user_report_row(), "actor": {"user_id": "user_1", "email_address": "[email protected]"}}],+ has_more=False,+ next_page=None,+ )+ ],+ {"user_email": "[email protected]"},+ [],+ ),+ (+ "analytics_summaries_legacy",+ "analytics_summaries",+ _V1,+ [ScriptedResponse(json={"summaries": [{"starting_at": "2026-03-04T00:00:00Z"}]})],+ {"starting_at": "2026-03-04T00:00:00Z"},+ [],+ ),+ (+ "analytics_summaries_renamed",+ "analytics_summaries",+ _V2,+ [ScriptedResponse(json={"data": [{"starting_at": "2026-03-04T00:00:00Z"}]})],+ {"starting_at": "2026-03-04T00:00:00Z"},+ [],+ ),+ (+ "backfilled_unversioned_pin_stays_legacy",+ "rbac_roles",+ "v1",+ [_token_page([{"id": "r1", "name": "Admins"}], has_more=False, next_page=None)],+ {"name": "Admins"},+ [],+ ),+ (+ "unpinned_follows_default",+ "rbac_roles",+ None,+ [_token_page([{"id": "r1", "display_name": "Admins"}], has_more=False, next_page=None)],+ {"name": "Admins"},+ ["display_name"],+ ),+ ]+ )+ def test_rows_keep_their_columns_under_each_version(+ self,+ _name: str,+ endpoint: str,+ api_version: str | None,+ script: list[ScriptedResponse],+ expected: dict[str, Any],+ absent: list[str],+ ) -> None:+ incremental: dict[str, Any] = {}+ incremental_fields = ANTHROPIC_ENDPOINTS[endpoint].incremental_fields+ if incremental_fields:+ incremental = {+ "incremental_field": incremental_fields[0]["field"],+ "db_incremental_field_last_value": _midnight(datetime.now(UTC).date()),+ }+ result = _driver().run(endpoint, script, api_version=api_version, **incremental)++ assert result.raised is None+ sent_version = {None: _V2, "v1": _V1}.get(api_version, api_version)+ assert {request.headers["anthropic-version"] for request in result.requests} == {sent_version}+ assert len(result.rows) == 1+ row = result.rows[0]+ assert {key: row.get(key) for key in expected} == expected+ assert [key for key in absent if key in row] == []