Mayor Bill de Blasio’s administration, seeking to be generous to its allies in labor without jeopardizing New York’s finances, is pushing for what would be the longest-ever contract with the teachers’ union: a nine-year deal that would let the city stretch out potentially huge retroactive pay increases.

In intense negotiations over the past week, people briefed on the talks say, the city has asserted that it cannot afford the $3.4 billion in retroactive raises that the union is demanding for two of the four and a half years it has been working without a contract — let alone for the other years.

The administration’s dealings with the union have become all the more tricky, and pivotal, because whatever deal the teachers receive could set a pattern for the city’s other municipal unions, which want billions in retroactive raises of their own.

A meager settlement could enrage the other unions, all 151 of which are seeking new contracts with City Hall after working under expired ones for several years. Taken together, some city officials say, the demands for back pay alone could cost more than $8 billion, with any prospective raises adding further to the tab.