@mro You do a WebFinger request on the AP host domain, and its response will give you a subject with the correct handle domain. See for example this account: https://toot.kif.rocks/@team and its WebFinger response: https://toot.kif.rocks/.well-known/webfinger?resource=acct:team@toot.kif.rocks This is a Mastodon split-domain setup.
The process is described here: https://www.w3.org/community/reports/socialcg/CG-FINAL-apwf-20240608/#reverse-discovery (step 4 is important for this)