President Carter had a close call yesterday, averting a face-to-face encounter with Sen. Edward M. Kennedy (D-Mass.) by a mere 13 minutes. But he could not escape being cast as the heavy in a mock "debate" Kennedy staged with the help of a tape recorder.

Shortly after Carter spoke to the Consumer Federation of America, it was Kennedy's turn to address the same group. He made the most of the opportunity to ridicule and condemn the president's refusal to debate him in their contest for the Democratic presidential nomination.

With bellowing good humor, Kennedy noted that Carter had rushed back to the White House "to read a vital national security document -- the Portland, Maine, telephone directory." But he said the consumer group should not be denied at least the semblance of a debate, which he then proceeded to provide.

Kennedy read a question that was put to the president during a 1978 news conference on the administration's failure to control inflation.

For the answer, Kennedy held up a tape recorder, pressed a button and out came the president's recorded news conference response, which included an assertion that a projection of 9 percent inflation was "a temporary aberration." Last year's inflation exceeded 13 percent.

"Now for a comment from Sen. Kennedy," the Massachusetts Democrat said, launching into a stinging attack on Carter that included a call for the president to withdraw from the presidential race if he "truly feels that he cannot participate in the democratic process mandated by the Constitution."

The audience loved it, and Kennedy's theatrics guaranteed him a generous slice of time on last night's television news broadcasts.

But beneath the laughter and showmanship, there was a deadly serious purpose to the performance. This was Kennedy's most concerted effort to date to taunt, lure or coerce Carter out of the White House and onto the campaign trail.

Kennedy is struggling to keep his presidential candidacy alive, and in recent days has grown harsher in his criticism of the president's refusal to debate or otherwise campaign openly until the American hostages in Iran are freed. Kennedy's speech yesterday contrasted Carter unfavorably with former presidents Truman and Johnson, who Kennedy said dropped their reelection campaigns rather than "tell Americans to rally around their failures in foreign policy as a reason to reelect them."

But if there was no face-to-face confrontation yesterday, some sharp differences on key campaign issues emerged as first the president and then Kennedy delivered speeches within minutes of one another.

Kennedy labeled Carter's anti-inflation policy "a calamity" and renewed his call for mandatory wage and price controls. He condemned the removal of price controls on oil and natural gas, which Kennedy said he would reimpose, and questioned whether Carter, in calling for resumption of registration for the draft, was proposing that "another generation of the young should be sent to die for the failures of the old in foreign policy."

In his speech, the president anticipated many of Kennedy's criticisms.

"We must face facts," he said. "We have no choice but to make the painful adjustment to the worldwide reality of higher energy prices. Subsidizing oil prices to keep them artificially low [through controls] can only harm our efforts for conservation and impede the development of new energy sources in America."

Carter also warned that "inflation cannot be vanquished without effort and sacrifice. It cannot be abolished by decree or by creating a gigantic new federal bureaucracy [to administer controls]. There are no simple solutions, no magic wands to wave inflation away."

The president delivered his 30-minute speech in a flat tone, and it was received politely but with little enthusiasm. His appearance, however, was a deft example of the uses of presidential power and trappings, something that continues to frustrate the Kennedy campaign.

Carter heard the first smattering of applause halfway through his speech when he called the water projects bill passed by the House Tuesday a "textbook example of [wanton] waste" and all but threatened to veto it.

And when the president declared that "I will veto" legislation now in Congress that would "cripple" the Federal Trade Commission, he received a standing ovation from the consumer advocates.

The president spoke from a podium bearing the presidential seal. When he entered the ballroom of the Capital Hilton Hotel, he was greeted by a rendition of "Hail to the Chief," played by a Marine Corps band. The band saluted him with "The Theme from Rocky" as he left.

By the time Kennedy reached the stage, the seal was gone, and so was the band.

This did not deter Kennedy. Accusing Carter of engaging in "a form of consumer fraud" by waging "a silent campaign," and of "sheer hypocrisy" in claiming inability to take part in political activities, Kennedy said:

"If a president can manage his reelection without debating the issues, the real losers are not his opponents, but the people themselves. A presidential election is their chance to choose a vision and a program. It is their only chance to speak in a single voice about the direction of their destiny, and this is the heart of our democracy.

"We do not pick a president for eight years, but for four-year terms. The referendum we are holding in 1980 is not a secondary side show, it is a primary element of our freedom. . . . The presidency does not belong to Jimmy Carter, it belongs to the American people."