API returning user ID of -1 when uploading avatar

The parameter api_username specifies the user you are executing the API action as…
… in this case you are likely using system where the default ID for this user is -1.

Negative value user ID’s I believe are used to identify bots.