Escherichia coli is an important model organism in microbiology and a prominent member of the human microbiota1. Environmental isolates readily colonize the gastrointestinal tract of humans and other animals, and they can serve diverse probiotic, commensal and pathogenic roles in the host2,3,4. Although certain strains have been associated with the severity of inflammatory bowel disease (IBD)2,5, the diverse immunomodulatory phenotypes remain largely unknown at the molecular level. Here, we decode a previously unknown E. coli metabolic pathway that produces a family of hybrid pterin–phenylpyruvate conjugates, which we named the colipterins. The metabolites are upregulated by subinhibitory levels of the antifolate sulfamethoxazole, which is used to treat infections including in patients with IBD6,7. The genes folX/M and aspC/tyrB involved in monapterin biosynthesis8,9,10 and aromatic amino acid transamination,11 respectively, were required to initiate the colipterin pathway. We show that the colipterins are antioxidants, harbour diverse immunological activities in primary human tissues, activate anti-inflammatory interleukin-10 and improve colitis symptoms in a colitis mouse model. Our study defines an antifolate stress response in E. coli and links its associated metabolites to a major immunological marker of IBD.