President Reagan is alternating between the olive branch and the lash in an effort to have his way with a Congress more recalcitrant than at any other time in his first two years.

He delivered a blustery veto threat this week when it appeared that Congress would walk away from his tax cuts and defense buildup. But at the same time he offered a bipartisan peace pipe to Capitol Hill when it appeared to be the only way to secure approval of the MX missile.

He has shown a willingness to stride hand-in-hand with opposition Democrats when it suits his purpose, but also demonstrated that he will happily campaign against the Congress as a whole when the need arises.

"We use what works," said one White House official after Reagan took both approaches in the opening statement of his news conference Tuesday night, praising a "bipartisan consensus on arms control" while vowing to wield his veto power in a war with Congress over spending and taxes this summer.

Repeating a pattern set by other presidents and Congress since World War II, Reagan is attempting to forge bipartisan cooperation on some, but not all, issues of national security, while reverting to more partisan treatment of domestic economic matters.

In the case of the MX missile, Reagan turned to bipartisanship after Congress voted to deny funds for the weapon last December. Showing a willingness to compromise with Democrats that he had not always displayed before, Reagan agreed to integrate the recommendations of the bipartisan Scowcroft commission into the U.S. negotiating position in arms talks with the Soviets. So far, the reward has been three key victories for the MX on Capitol Hill in the last two weeks.

On the budget, Reagan's tactics have been far more fluid. He dickered for several months with his fellow Republicans in the Senate but grew impatient with their insistence on narrowing the deficit by tax increases and less defense spending than he wanted.

This impatience was evident last Friday afternoon at an unannounced luncheon that Sen. Paul Laxalt (R-Nev.) had with the president. Laxalt sought to sound out Reagan on a compromise budget resolution, but was turned down, officials said.

Reagan, who had used the congressional budget resolution for two years to impose his own spending blueprint on Congress, then decided to send a strong signal to Capitol Hill that he might walk away from it altogether rather than bargain away the third year of his tax cut or his defense buildup.

"The feeling in the White House is that the Senate is going through one of their craziness periods, and Reagan is playing the policeman type to get these guys into line," said one official of Reagan's strong language on the budget this week, as the Senate writhed to avoid deadlock. "He's saying, 'If you want war, we'll give you war.' "

It is also true that for Reagan the budget resolution loses importance if it's no longer a tool for his own goals. "The minute we walk away from it, it loses significance," said another administration official.

From a political standpoint, White House officials believe Reagan cannot suffer, and may well benefit, from a summer-long test of wills with Congress over spending and taxes. "The one thing you have to remember," one official commented this week, "is that whatever the president's public approval rating, the Congress is lower."