When using the Paint Bucket tool you set both the material property and the UV mapping. The API material setter only sets the material property.
Iām thinking either the face you painted with the API has leftover UV mapping from having been painted previously, or the face you painted using the tool got a non-standard UV-mapping from the face you picked the material from using the material eye dropper.