To be eligible for education credits the institution must be an "eligible institution." Some foreign universities are, most aren't, which precludes education credits for costs paid there.
An eligible educational institution is a college eligible to participate in a student aid program administered by the U.S. Department of Education. It includes virtually all accredited public, nonprofit, and proprietary (privately owned profit-making) post-secondary institutions in the US. The educational institution should be able to tell you if it is an eligible educational institution.
You can do an on-line search for eligible institutions. (Note when searching that the drop down menu for "state" includes areas such as Canada and "Foreign Countries." Only the Government would list Canada and other foreign countries as states!)