You can add a setComputeUnitLimit()
instruction to the transaction:
import {
Transaction,
ComputeBudgetProgram,
} from "@solana/web3.js";
let tx = new Transaction();
// needs to be the first instruction
// experiment with this number to find one where the transaction succeeds.
tx.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }));
// add other instructions
tx.add(...);