How can I set the image to use the UV Map using the python api
Every UV face needs to be set to the image datablock:

image = bpy.data.images.new(name="test", width=512, height=512)

for uv_face in cube.data.uv_textures.active.data:
    uv_face.image = image

bpy.ops.object.bake_image()


Note that a uv_texture can't be accessed in edit-mode.

In addition to the UV face assignment, every mesh face should get a material with an image texture assigned (same image as for UV faces) and the texture coordinates be set to UV. Otherwise the texture may not show correct in viewport, although it might be baked correctly (better test!).

Have a look at the Material Utils addons, it let's you transfer UV face image assignments to material texture assignments and vice versa.