What's the best way to assign a case role via the API?
Looking through the api code for relationships it doesn't appear to be case-aware. You can duplicate what happens in the UI by checking out CRM_Contact_Page_Ajax::relationship(), and note near the bottom where it calls CRM_Case_BAO_Case::createCaseRoleActivity().

Depending on what you mean by "api", that might not be exactly what you're looking for, but you should just be able to add a call to CRM_Case_BAO_Case::createCaseRoleActivity() to the code you've written that already creates the relationship.