1. Mounting an immune response is likely to be costly in terms of energy and nutrients, and so it is predicted that dietary intake should change in response to infection to offset these costs. The present study focuses on the interactions between a specialist grass-feeding caterpillar species, the African armyworm Spodoptera exempta, and an opportunist bacterium, Bacillus subtilis. 2. The main aims of the study were (i) to establish the macronutrient costs to the insect host of surviving a systemic bacterial infection, (ii) to determine the relative importance of dietary protein and carbohydrate to immune system functions, and (iii) to determine whether there is an adaptive change in the host's normal feeding behaviour in response to bacterial challenge, such that the nutritional costs of resisting infection are offset. 3. We show that the survival of bacterially infected larvae increased with increasing dietary protein-to-carbohydrate (P:C) ratio, suggesting a protein cost associated with bacterial resistance. As dietary protein levels increased, there was an increase in antibacterial activity, phenoloxidase (PO) activity and protein levels in the haemolymph, providing a potential source for this protein cost. However, there was also evidence for a physiological trade-off between antibacterial activity and phenoloxidase activity, as larvae whose antibacterial activity levels were elevated in response to immune activation had reduced PO activity. 4. When given a choice between two diets varying in their P:C ratios, larvae injected with a sub-lethal dose of bacteria increased their protein intake relative to control larvae whilst maintaining similar carbohydrate intake levels. These results are consistent with the notion that S. exempta larvae alter their feeding behaviour in response to bacterial infection in a manner that is likely to enhance the levels of protein available for producing the immune system components and other factors required to resist bacterial infections ('self-medication').