Genesys Cloud Platform SDK Token Refresh Race Condition During Batch Processing

We are experiencing a race condition with the Genesys Cloud JavaScript Platform SDK while processing large batches of analytics data for our New Relic custom events pipeline. The access token expires mid-execution, causing subsequent API calls to fail with a 401 Unauthorized error before the internal refresh mechanism can complete.

Our script iterates over conversation IDs to fetch detailed metrics. It works fine for small sets, but when pushing through 500+ IDs, the token lifetime (usually 1 hour) gets hit during the loop. The SDK seems to attempt a refresh, but the pending requests don’t automatically retry or wait for the new token. They just throw 401s.

Here is the simplified logic we are using:

const platformClient = require('genesys-cloud-platform-client');

async function processBatch(conversationIds) {
 const analyticsClient = platformClient.AnalyticsApi();
 
 for (const id of conversationIds) {
 try {
 // This call fails intermittently with 401 as token expires
 const data = await analyticsClient.postAnalyticsConversationsDetailsQuery({
 body: { query: { filter: { id: id } } }
 });
 
 // Push to New Relic
 sendToNewRelic(data);
 } catch (error) {
 console.error(`Failed for ${id}:`, error.message);
 }
 }
}

The error log shows:
Error: Request failed with status code 401. Token has expired.

We expected the SDK to handle the refresh transparently, as per the documentation for other endpoints. Is there a specific configuration flag or method to enforce synchronous token refresh before proceeding? Or do we need to implement our own interceptor to catch 401s and retry? We are running this in a Node.js environment, version 18.

We’ve tried setting the refreshToken manually, but that doesn’t solve the mid-batch expiry issue. Any pointers on handling this gracefully without rewriting the entire client logic?