Python SDK Analytics API pagination loop failing with 403 Forbidden

Got a 403 Forbidden error on the second page of the analytics query. The script runs fine locally against the sandbox environment, but it chokes in production. I’m trying to build a daily export job that pulls queue interaction counts and dumps them into an S3 bucket using Python and boto3. The first page of results comes back clean with a 200 OK. The issue hits when the code tries to fetch the next page using the nextPageId from the previous response. It seems like the token expires or the session drops between requests, but I’m using the same auth object.

Here’s the snippet where it breaks:

import gen_ccloud_client
import boto3

auth = gen_ccloud_client.auth
client = gen_ccloud_client
analytics = client.analytics

# Initial query
response = analytics.post_analytics_interactions_details_query(
 body={
 "dateFrom": "2023-10-01T00:00:00.000Z",
 "dateTo": "2023-10-02T00:00:00.000Z",
 "groupBy": ["queueId"],
 "metrics": ["count"]
 }
)

data = response.body
current_page = data.get("nextPageId")

while current_page:
 try:
 response = analytics.post_analytics_interactions_details_query(
 body={
 "dateFrom": "2023-10-01T00:00:00.000Z",
 "dateTo": "2023-10-02T00:00:00.000Z",
 "groupBy": ["queueId"],
 "metrics": ["count"],
 "nextPageId": current_page
 }
 )
 data = response.body
 current_page = data.get("nextPageId")
 # Process data...
 except Exception as e:
 print(f"Error fetching page: {e}")
 break

# Upload to S3
s3 = boto3.client('s3')
s3.put_object(Bucket='my-analytics-bucket', Key='export.json', Body=json.dumps(all_data))

The error trace points to the post_analytics_interactions_details_query call inside the loop. It throws a 403. The docs say the token is valid for 60 minutes, and this job runs in under 5 minutes. I’ve checked the IAM roles for the Lambda function running this code, and they have full S3 access. The Genesys OAuth client has the right scopes for analytics. What am I missing? Is there a rate limit I’m hitting that returns 403 instead of 429?