This post shows that some very simplistic algorithms can’t unambiguously determine a key. But I don’t think it establishes that a more sophisticated algorithm could not. Key center is not just based on chords and notes in a scale. It’s based on the note/chord that seems like the place where the music is at rest, or at home. Many songs have non-diatonic chords, but it’s still fairly obvious what key they are in.
That said, there are examples where they key is ambiguous even to humans (e.g. Hey Joe [C G D A E], or Sweet Home Alabama [D C G] but disputed whether it’s in G or in D).