There is no conventional way to in a trigger which can tell what actually might have caused an insert or update to happen. But, to achieve this, you can create a custom checkbox field on the object, something like IsAPI_c. After which you need to pass in true for that field with any API call and then check the field in your trigger for each record in the batch.
trigger Update_Last_Modified_By_API
on My_Object__c (before update)
{
for ( My_Object__c o : Trigger.New )
{ if ( o.IsAPI__c )
{ o.Last_Modified_By_API__c = datetime.now(); } o.IsAPI__c = false; }
}