What are the predictors and neural correlates of antidepressant response to ketamine? Patients, ages 18 to 65 years with treatment-resistant MDD and BD will, in a double-blind crossover study, receive either intravenous ketamine or saline solution and multimodal MRI, MEG and polysomnography.