How to use multiple Stripe secret keys with stripe-node?

I'm using stripe-node library. I need to interact with several stripe accounts, each one with their own secret key. What's the best way to do that?

Is there a way to specify the secret key for each request, like:

stripe.charges.create({
  auth: secret_key_1,
  ...
});
stripe.charges.create({
  auth: secret_key_2,
  ...
});

One workaround I thought of is simply instantiating a separate stripe instance for each account.


Solution 1:

As it states in the documentation you can set the api_key on a per-request basis like this:

stripe.charges.retrieve("ch_1AqjPcJWCk4FIh3mWQ3Hvmvi", {
  api_key: "sk_test_nra5nLtBVqMvXCoYROwWQFRG"
});

The only other alternative is to have multiple instances as already mentioned in other answers.