We consider multi-environment prediction problems in which environments change the distribution of a latent variable while the mechanisms generating covariates and targets remain stable conditional on that variable. We formulate a Bayesian model that models the environment explicitly, derive a variational objective with an empirical-Bayes prior, and use amortized variational inference to learn representations for prediction in new environments.