Sorry, I'm not getting a much clearer picture.
You can obviously model your code after the URL remapping code from viewtopic.php. Basically the code set off by "//
www.phpBB-SEO.com SEO TOOLKIT BEGIN/END" caches the topic title to ID mapping, forum title to ID mapping, etc. in the $phpbb_seo class instance and then the code in append_sid calls format_url (or similar method). You could call $phpbb_seo methods directly; all the "setup" code you see in viewtopic.php etc. is to enable append_sid to do the URL remapping; this approach was chosen because phpBB has the convention that
every single forum URL passes by append_sid, thereby enabling a single location for the remapping invocations.
Without more details (code snippets), I cannot advise you further. Reviewing the code noted above should answer your questions.