Patient responses to immune checkpoint inhibitors can be influenced by the gastrointestinal microbiome. Mouse models can be used to study microbiome–host crosstalk, yet their utility is constrained by substantial anatomical, functional, immunological and microbial differences between mice and humans. Here we show that a gut-on-a-chip system mimicking the architecture and functionality of the human intestine by including faecal microbiome and peristaltic-like movements recapitulates microbiome–host interactions and predicts responses to immune checkpoint inhibitors in patients with melanoma. The system is composed of a vascular channel seeded with human microvascular endothelial cells and an intestinal channel with intestinal organoids derived from human induced pluripotent stem cells, with the two channels separated by a collagen matrix. By incorporating faecal samples from patients with melanoma into the intestinal channel and by performing multiomic analyses, we uncovered epithelium-specific biomarkers and microbial factors that correlate with clinical outcomes in patients with melanoma and that the microbiome of non-responders has a reduced ability to buffer cellular stress and self-renew. The gut-on-a-chip model may help identify prognostic biomarkers and therapeutic targets. A gut-on-a-chip incorporating peristaltic-like movements and faecal samples from patients with melanoma recapitulates microbiome–host interactions and predicts the responses of the patients to immune checkpoint inhibitors.