Hi Massimo,
You can add and remove A/B test variants programmatically, please see API examples here. But there is no public API to add widgets unfortunately, which makes A/B test variants API pretty useless I agree.
If you really need to deal with it, to hack around this, when creating pages and variants you may work directly with JSON stored in DocumentPageBuilderWidgets column of CMS_Document table: it contains all widgets and variants data. But there is no documentation or guidance to do so.