As many as a dozen drug-sniffing NYPD pooches could be forced into early retirement when New York legalizes weed, the city’s top cop said Friday.

“We’re probably gonna have to end up getting new dogs,” Commissioner James O’Neill told reporters. “It is a concern of ours.”

That’s because the department’s 12 narcotics dogs are trained to alert their handlers when sniffing for illicit drugs including — for now — marijuana. That gives cops probable cause for a search.

But if and when Gov. Andrew Cuomo achieves his goal of legalizing weed in the state, the dogs’ actions could be called into question in court.

“The dog obviously can’t talk to us, so if he hits, that gives you probable cause now to search. We don’t know if he’s hitting on marijuana or cocaine. He doesn’t tell us,” a high-ranking police source told The Post.

“So, if he’s trained for both, and now marijuana’s legal, if he’s hitting for the marijuana, you’re not legally searching. The dog can’t tell us, ‘Hey, this one’s cocaine.’ ”