With python align text to camera
I got the idea while writing my question. I'm not very good at 3D math with matrices etc but it worked.

Maybe someone will be helped by this.

cam_rot = scene.camera.rotation_euler
bpy.ops.object.text_add(location=(x,y,z))
textobject=bpy.context.object
textobject.rotation_euler = cam_rot