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.

fix(data-imports): shrink Anthropic usage report page size to avoid 400 (#70812)

Tom Owersa6242c5fb89c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/settings.py
index 0d1a20482a99..e8f445efea50 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/anthropic/settings.py
@@ -127,7 +127,10 @@ ANTHROPIC_ENDPOINTS: dict[str, AnthropicEndpointConfig] = {
incremental_fields=[_datetime_incremental_field("starting_at")],
bucket_width="1d",
group_by=_USAGE_GROUP_BY,
- limit=31, # API max for the 1d bucket width
+ # Grouping by every dimension multiplies the result rows per bucket, so requesting the
+ # 31-bucket max overflows the report's per-response result cap and the API 400s. The API
+ # default keeps each page small; pagination still walks all history via `next_page`.
+ limit=7,
default_incremental_lookback_seconds=_REPORT_LOOKBACK_SECONDS,
),
"cost_report": AnthropicEndpointConfig(
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.py
index 5a1c6c0374f8..b159e9249c9f 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
@@ -103,9 +103,18 @@ class TestReportParams:
)
assert params["starting_at"] == "2026-03-04T00:00:00Z"
assert params["bucket_width"] == "1d"
- assert params["limit"] == 31
+ assert params["limit"] == 7
assert multi == {"group_by[]": config.group_by}
+ def test_usage_report_page_size_stays_below_bucket_max(self) -> None:
+ # Grouping by every dimension multiplies the results per bucket, so requesting the 31-bucket
+ # max overflows the per-response result cap and the API 400s. Keep the page small while still
+ # grouping by the full set; pagination walks the rest.
+ config = anthropic.ANTHROPIC_ENDPOINTS["usage_report"]
+ params, _ = _report_params(config, should_use_incremental_field=False, db_incremental_field_last_value=None)
+ assert len(config.group_by) == 8
+ assert params["limit"] <= 7
+
def test_full_refresh_falls_back_to_launch_date(self) -> None:
# Without a watermark we must still send the required starting_at; the Anthropic launch date
# pulls all available history without requesting decades of empty pre-launch buckets.