Key rule: you must exit to a different country
Your onward flight must go to a different country or territory from where you started. Example: US → Shanghai → Japan ✓. US → Shanghai → US ✗. US → Shanghai → Hong Kong ✓ (Hong Kong is a separate customs territory). US → Shanghai → Beijing (domestic) ✗ — domestic flights don't count as international transit. Immigration will check your onward ticket; if you don't have one or it returns to your origin, you will be denied the transit permit and may be held for the next available outbound flight.