The toggle button itself could appear while editing or placing the blueprint dynamically, other mods do that so I could read their code to get a running start on how Factorio's GUI api works. And they are doing pretty much the same thing. BP alignment mod might actually save some data in the blueprint somehow so I could use that mod to inform me on that too.
In my experience adding a button to the blueprint GUI is rather fragile. The initial setup and editing a blueprint are treated differently I think, and if you want to save anything in the blueprint you also save all the changes the user has made. With the new Blueprint Library there also were some problems (in some cases - probably when opening a blueprint from the library or maybe from nested books - the alignment GUI didn't open) but I didn't really look into that because the alignment mod is mostly obsolete now anyway.
See e.g. https://github.com/steffen-kiess/factorio-BlueprintAlignment/blob/41149648214978d9d4ec36ee58b35aa6a1dcb2be/gui.lua#L196, there is some fun stuff like reopening the blueprint UI (and when this was called during the initial setup then it will switch to the edit mode here).
Also if there are multiple mods doing this kind of stuff they can break each other.
Kinda wish the existing GUI and blueprints themselves were more moddable so we don't have to do all these weird workarounds to implement features that would otherwise be a line of code and now is probably hours of work...
Yes, proper support from the game would make this much easier. You also can always use a hack like a string in the blueprint title, then you don't need any UI at all. (But I don't know whether that will work with Recursive Blueprints).
Edit: And I need some way to store information in the ghosts as well, and some way to recognise which blueprint was used to place the ghosts, even when placed by script like from Recursive Blueprints. Does Lua have WeakMaps, and if so can they be stored in the global table? Those wouldn't work for blueprints when the blueprints are stringified or transfered between games though. But for other things that could be a solution. Mods usually seem to use special invisible items and entities which always seem to break at the slightest mod interaction/instant blueprint etc. And for blueprinting entities a WeakMap wouldn't work, but I don't need to store anything that needs to be copied from the surface to blueprints anyways.
I think the new way to store it are the entity tags https://lua-api.factorio.com/latest/LuaItemStack.html#LuaItemStack.get_blueprint_entity_tags which will then show up as ghost tags: https://lua-api.factorio.com/latest/LuaEntity.html#LuaEntity.tags