Clearance and creepage for AC Optocoupler for 230V line detection
I also posted the question on reddit and got the answer there:


  So a few things before the actual answer:
  
  What's the mains voltage? 2.5mm sounds like 240V if I'm not mistaken.
  (correct)
  
  In situations like this, you can increase creepage distance by adding
  a board cutout (slot) between the pins. You can also reduce creepage
  requirements by adding a conformal coating.
  
  It would be weird if the datasheet of a component intended for AC
  mains use violated clearance/creepage requirements, and made no
  mention of the above, right? That usually means something else is
  going on.
  
  In this case (real answer now) you are looking in the wrong place.
  Because you have two LEDs that are anti-parallel, one of them will
  always be on. That means the voltage between the pins is not
  120/240/whatever but just the forward voltage drop of the LED. You
  don't have mains voltage between the pins, you have 1.4V (per the
  datasheet). So that spacing is perfectly fine.
  
  What you do need to consider is that nearly all of that voltage is
  actually dropped across R2. That is where you need to worry about
  creepage, and in this case the two SMT pads of that resistor do look
  way too close together. I also do not see any current limiting,
  meaning that if that resistor fails short or a short otherwise
  develops, you're in for a bad time.
  
  In this case just choose a larger resistor package to maintain the
  requisite spacing requirements. You can also add a slot between the
  resistor pads to improve the situation slightly, but you'll need to
  upsize either way as the resistor body itself still provides a bridge.
  
  220k is also quite a large value, make sure it's enough to actually
  turn the output on sufficiently. That's 1mA at 240 which is probably
  enough but double check. And of course power rating and all that which
  you're already aware of.


Credit: u/happyhappypeelpeel