Using multiple API keys concurrently

When using google.generative ai library, how do I have multiple genai requests run concurrently using different api keys?
The API seems to only allow a global configuration with genai.configure, and it’s a global variable defined in a module, which doesn’t seem to be thread safe.

Welcome to the forum. Depending on your setup, you can run concurrent requests (that is an inherent advantage of a stateless API). Using Python, you can have multiple venv and they will not interfere with each other. But I also have a follow up question: What is the point of having different API keys in separate instances? If you explain what you are trying to accomplish with that, we might have alternative solutions to address the requirements.