Two main differential diagnoses for your doctor to consider are a kidney stone, and gall bladder pain in that area. Kidney toward your back, gall bladder toward the front.
I had similar pain during keto. The tests to consider are blood tests to try and identify any organ damage, like when fatty liver elevates liver enzymes. If those numbers go up in the presence of right side pain a liver work up is indicated. The other test is abdominal imaging. Usually ultrasound is a first step.
My right side pain, like a runner’s “stitch”, was post-operative for the destruction and removal of a kidney stone from my right side ureter. The kidney stone pain was different to the right side abdominal ache that was from smooth muscle spasm of the irritated ureter. The stone was calcium oxalate (the spikiest one). The kidney stone pain was crippling and put in an ambulance after putting me on the floor in the foetal position wondering what had ruptured inside. So, that’s not the right side pain under the ribs that you are describing.
Another family member had similar pain but a different diagnosis. They had gall stones and gall bladder pain from a low fat diet.
Look up the symptoms of oxalate dumping that can occur early in keto depending upon your previous diet. Oxalate dumping can lead to the formation of calcium oxalate kidney stones.
These are things to check in about with your doctor, or a new doctor that listens to you.
my answer is the same, close enough as the one I gave in Feb 2020.