Python SDK bulk user creation from CSV: Handling API rate limits and validation errors

Is it possible to efficiently bulk-create users from a CSV file using the Genesys Cloud Platform SDK for Python without hitting rate limits or encountering silent failures?

I am building a script to onboard a large batch of agents. The current implementation reads a CSV, constructs User objects, and calls post_users() in a tight loop. While this works for small batches, it becomes unreliable with larger datasets. I need a robust pattern for handling the asynchronous nature of the API and managing errors gracefully.

Here is the current YAML configuration for the script’s settings:

script_config:
 csv_path: 'agents_batch_01.csv'
 default_division_id: 'default'
 retry_attempts: 3
 rate_limit_pause_ms: 100
 batch_size: 50

The core logic looks like this:

from geniecloud.platform.client import ApiClient, Configuration
from geniecloud.platform.models import User
import csv

def create_users_from_csv(client, csv_file):
 with open(csv_file, 'r') as f:
 reader = csv.DictReader(f)
 for row in reader:
 user = User(
 name=row['name'],
 email=row['email'],
 username=row['username'],
 division_id='default'
 )
 try:
 api_response = client.users_api.post_users(body=user)
 print(f"Created user: {api_response.id}")
 except Exception as e:
 print(f"Error creating user {row['username']}: {e}")

The issue is that post_users() returns a 202 Accepted, but the actual creation happens asynchronously. I am seeing a mix of 400 Bad Request errors (likely due to duplicate emails or invalid data) and 429 Too Many Requests.

How should I structure the retry logic and error handling to ensure no users are lost or duplicated? Should I be checking the location header from the 202 response for status polling, or is there a better batch endpoint I am missing?