President Reagan vetoed emergency farm-credit relief legislation yesterday, lambasting Congress for approving a "massive new bailout" that he said "would not really help farmers" but "would add billions to the deficit over the next several years."

Striking a defiant tone in the first veto of his second term, Reagan told reporters who were called to the Oval Office that "Congress failed" its first major budget test of the year and added: "Someone must stand up to those who say, 'Here's the key to the Treasury -- just take as many of those hard-earned tax dollars as you want.' "

House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.) said he would not seek to override the veto but was asking farm-state lawmakers to compromise with Reagan instead. "The veto is not the answer to the problems of the American farmer," he said. Tuesday's House vote approving the bill to provide short-term aid to farmers was 255 to 168 -- less than the two-thirds vote necessary to override a veto.

White House spokesman Larry Speakes immediately rejected the suggestion of a compromise.

Republicans had accused Democrats of sending the farm bill to the president only to score political points in the Farm Belt. Reagan said the bill "is merely designed to convey the impression of helping farmers" but came "too late in the season" to do any good.

The farm credit legislation was tacked onto a bill authorizing $175 million in disaster and refugee assistance to drought-ravaged African nations. In a shift, Reagan said he would sign the disaster legislation if it stood alone. White House officials earlier said Reagan would take a "hard look" at the Africa bill because it was more expensive than he wanted.

The African relief funds are expected to reach the Senate floor soon. Reagan said his veto would not interrupt the flow of aid to Africa.

Reagan acknowledged that "some of our farmers are facing severe financial problems" but said less than 4 percent "are in need of immediate help." He ascribed farmers' economic woes to "a generation of failed policies that drove down farm prices and drove up the cost of their land, seed and equipment," and also cited the inflation and grain embargoes of the late 1970s.

Farmers in trouble "deserve our sympathy and our support" and "the federal government mustn't shirk its responsibility to help undo some of the damage that it created," Reagan said. He said his administration's already-announced emergency measures are adequate.

"But I've pleaded and warned repeatedly that, just as your families don't have a blank check for whatever your needs may be, neither can government -- and that means taxpayers -- bail out every farmer hopelessly in debt or every bank which made imprudent or speculative loans and bet on higher inflation," Reagan said.

Congress was "bemoaning the size of the deficits" earlier this year but "a majority proved itself incapable of resisting the tax-and-spend philosophy that brought America to its knees and wrecked our economy," he said.

In his veto message, Reagan said the farm credit bill would add at least $2.5 billion to the deficit over the next few years; O'Neill said it would cost $250 million over six years, and less if farmers pay back their loans with interest.

In a point-by-point attack on the legislation, Reagan objected to requiring the government "to assume an unwarranted 90 percent of the risk on all new loans made by private lenders through a $1.85 billion debt adjustment program."

He assailed as "unprecedented and unjustified" a provision giving farmers advance payments on unplanted crops from the Commodity Credit Corp. He said the legislation "substantially and unnecessarily" increases the loan guarantee level for farmers above the administration's $650 million, and he declared that $100 million in payments to rural banks would "soon grow into an uncontrollable spending program."