Rotating OAuth client secrets without dropping active tokens in Python SDK

Problem
We need to rotate the client secret for our backend service without dropping active sessions. The platform docs mention a short grace period for secret swaps, but the timing feels off. We’re running the cron job at 2 AM EST and the SDK doesn’t respect the overlap window. Thread safety is another headache since multiple workers share the same client instance. Environment variables get overwritten before the old token finishes its lifecycle.

Code
Here is the rotation logic we wrote. It pulls the new secret, updates the env var, and tries to refresh the auth context.

from genesyscloud import PlatformClient
import os

client = PlatformClient.create_from_default_config()
resp = client.auth.post_auth_tokens_client_credentials(
 client_id=os.getenv('CLIENT_ID'),
 client_secret=os.getenv('OLD_SECRET')
)
os.environ['CLIENT_SECRET'] = resp.body.client_secret
client.init_platform_client()

Error
The second call to init_platform_client() throws a 401 Unauthorized on /api/v2/auth/token. It’s throwing the error instantly instead of waiting for the grace window. We also tried hitting PATCH /api/v2//clients/{id} directly with raw requests, but the SDK wrapper overrides the auth headers before the request goes out. The response body just says invalid_client. Sometimes it works on the first retry, then fails on the third.

Question
How do we properly queue the secret swap so the SDK keeps using the old token until it actually expires? We’ve been patching the header dict directly, but the analytics endpoints still reject the stale token after about ninety seconds. We’re not sure if the Python SDK caches the client ID somewhere that blocks the rotation. Any working example for the secret swap window