A oxygen and potassium co-doped polymeric carbon nitride (O/K-PCNs) was simply constructed by an acid gas cutting strategy for photocatalytic H2O2 generation. The effect of each accompanied configurations on photosynthesis of H2O2 was systematically analyzed. The C–O–C structure formed by O doping is capable of decreasing K ions incorporated energy barrier, thus remarkably improving the content of crucial K active sites. Dual heteroatom sites synergistically enhance O2 adsorption and surface ORR by a bridge K–O–O–C model. Moreover, the accompanied cyano defect and poly(heptazine imide) is responsible for improving in-plane and interlayer carriers separation, respectively. The optimal O/K-PCNs exhibits 60-fold higher photocatalytic H2O2 production rate than pure PCN. A positive correlation between the H2O2 production rate and the K heteratoms content was established. This work clarifies role of multiple configurations in PCN, especially O-containing groups, providing a new insight for design heteroatoms-doped materials for solar energy conversion.