I'm Canadian, but not a tax lawyer. When I've done consulting work in the past for an American company, it has been done B2B; invoices were sent from my (personal) company to their company. They then paid the invoices. There wasn't anything more complicated than that; I wasn't hired as an American employee or anything like that, software development was a service that they paid my company to do and I invoiced them for it.
At the end of the year, it was simply recorded as a sale and was taxed appropriately.