Genesys Cloud API batch job fails with 401 due to token expiration

Running a Terraform module to provision 500 users via the /api/v2/users endpoint. The script fetches an OAuth token at the start. Halfway through the loop, requests start failing with 401 Unauthorized. The token’s lifespan seems shorter than expected for this volume. Is there a standard pattern for refreshing the token mid-execution without tearing down the Terraform state? Current setup uses the pure-rest provider wrapper.