Turn the Instant Pot to the lowest SAUTE setting and add the whole spices (cardamom pods, cloves, cumin seeds, black peppercorns, and cinnamon sticks, if using). Toast until fragrant or for about 5 minutes.
Add the onion, garlic, and ginger and saute for about 3 minutes.
Add the rest of the spices and the butter to the Instant Pot. Stir on the lowest SAUTE setting until the butter melts.
Once the butter has melted, set a timer for 10 minutes. Stir every minute or two during this time. The butter should come to a low simmer.
A foam will start to form on top of the butter, but eventually this foam will settle and will sink to the bottom.
When the foam has mostly settled at the bottom (this should take until your timer goes off), turn the Instant Pot off but leave the liner in the pot. Allow the butter to continue cooking with the residual heat for another 10 minutes, stirring occasionally. The proteins (the foam) that sank to the bottom should turn a golden brown color and everything should be almost completely settled. See photos above for visual cues.
Once the butter is finished cooking, line a mesh strainer with a cheesecloth and place on top of a glass bowl. Ladle the ghee into the mesh strainer so that only the clear ghee is left over and all of the spices are removed.
Serve with anything you’d like. Enjoy!