WASHINGTON — A growing rift among Senate Republicans over federal spending on Medicaid and the opioid epidemic is imperiling legislation to repeal the Affordable Care Act that Senate leaders are trying to put to a vote by the end of next week.

President Trump had urged Republican senators to write a more generous bill than a House version that he first heralded and then called “mean,” but Republican leaders on Tuesday appeared to be drafting legislation that would do even more to slow the growth of Medicaid toward the end of the coming decade.

And conservative senators, led by Patrick J. Toomey of Pennsylvania, are determined to hold the line on federal spending, pitting two Senate factions against each other.

Senator John Cornyn of Texas emerged from a contentious closed-door lunch with Republican senators on Tuesday saying that he hoped the Senate would be able to meet the deadline of a vote before July 4. “But,” he added, “failing that, I’ve always said we need to get it done by” the end of July.