Per Nicolas, use org-export-get-relative-level.