In the standard theory of cavity quantum electrodynamics (QED), coupling between photons inside and outside a cavity (cavity system and environment) is given conserving the total number of photons. However, when the cavity photons (ultrastrongly) interact with atoms or excitations in matters, the system-environment coupling must be determined from a more fundamental viewpoint. Based on the Maxwell's boundary conditions in the QED theory for dielectric media, we derive the quantum Langevin equation and input-output relation, in which the total number of polaritons (not photons) inside the cavity and photons outside is conserved.