The purpose of this phase 2 trial is to study the activity of pembrolizumab in combination with bevacizumab in patients with untreated brain metastases from melanoma or NSCLC to determine activity and safety of the drug combination. Furthermore, in patients who undergo resection of biopsy of a brain metastasis, we will evaluate biomarkers predictive of treatment benefit, and will also conduct correlative biomarker studies on extra-cerebral specimens in all patients in whom a systemic biopsy is feasible or in archival tumor tissue when available.