This country, which for years was held up as a model of pro-Western, capitalist success, is now heading down the same rocky road of economic deterioration as the rest of Africa, raising the threat of accompanying political uncertainty.

"In five or 10 years' time I wouldn't want to be here," one Western diplomat said. "There is going to be an unemployment problem that will shake the hell out of this place."

Although Kenya is technically nonaligned, it has been moving closer to Washington, and its unabashed capitalism makes the current malaise all the more significant for the West, particularly the United States. Although he Nairobi government is heavily involved in the economy, Kenya is identified as a model for Africa of the Western, free-market system.

Were it to fail, at a time socialism is being questioned by many Africans, it "would be viewed widely as proof that the Western system cannot provide for African needs," a diplomat said.

Kenyans, although not so forthcoming as outsiders, have mixed views of the direction in which the country is going.

"All we have done in Kenya is replace white capitalism with black capitalism," said a professor at the University of Nairobi, in commenting on progress made during the 18 years since the East African nation gained its independence from Britain. The professor, who called himself "an aspiring capitalist," said the gap here between the rich and poor blacks is getting wider, but he also noted that "at least the whole system is moving up."

Criticism of Kenya's current troubles is increasingly centering on President Daniel arap Moi, although nobody will criticize Moi publicly. There is no serious suggestion that Moi is in danger of being ousted, but the dissatisfaction is palpable as the political fabric of the country reflects the strain of growing economic problems.

The country, which is bordered by Marxist Ethiopia, socialist Tanzania and the failing economies of Uganda, Somalia and Sudan, has been one of the major recipients of U.S. assistance in Africa. The Reagan administration has proposed a large increase to $120 million in grants and loans to Kenya in 1982.

More than $50 million is in military assistance because of the volatile situation in the Horn of Africa. The strategically located port of Mombasa is the only naval base at present on the east coast of Africa for the U.S. Navy and the Rapid Deployment Force designed to confront the Soviets in the Indian Ocean.

For all its problems, no one questions that the country has made great strides in the last 19 years. Its current problems should be measured against its relative successes to get a true gauge of the country's position.

Manufacturing production, for example, has doubled. In education, primary school enrollment is universal, compared with less than 50 percent attendance 20 years ago.Secondary school enrollment has shot up from 2 percent of the age group to 17 percent, one of the highest enrollments in black Africa. Adult literacy has doubled.

Unlike Zimbabwe, another key former British colony in Africa, Kenya does not have a pressing race problem. Blacks and whites mix far more freely here than in Africa's newest independent nation.

The white population seems to have stabilized at about 40,000, down from 55,000 at the time of independence. The people, however, are different -- mostly expatriates rather than settlers and colonial administrators.

Although thee is a one-party state, the political system is one of the most open in Africa and until recently the press has been given wide range, although the president has always been sacrosanct.

About half the members of parliament have been voted out in each of the three national elections. The judiciary is firmly independent. Ten members of parliament elected in 1979, including a member of the Cabinet,have been thrown out by the courts on grounds of election irregularities.

Through most of the 1970s the Kenyan economy expanded at an average rate of 6 percent annually. Last year, however, the rate was 2 percent, meaning that with record 4 percent population growth rate, per capital income is down. It is this slippage in the economic sphere that is causing the greatest worry, and the problem is not Kenya's alone.

"There are no prospects of the situation changing for the better in the foreseeable future," Mwai Kibaki, the vice president and finance minister, said recently in a reference to the overall Third World problem, which Kenya shares.

"I see deterioration everywhere -- electricity, phones, roads, government services," one resident said.

A British banker said, "It is difficult to see the government being able to turn [the economic situation] around." Although acknowledging that Kenya is still one of the best places in Africa to do business, he added that his bank "has cut down its long-term exposure." Instead, it has switched to loans of about one-year duration "because we're not too sure it will be stable here in a couple years."

As in other African countries, the problems of rising oil bills and falling prices for agricultural exports combined with the world economic slowdown have had a major impact here.

Kenya spends 35 percent of its export earnings on oil. The price for its major export, coffee, has decreased by 75 percent since the boom in the mid-1970s caused by a Brazilian frost.

But Kenya is better off than most Third World non-oil-producing nations since it exports finished petroleum products and residuals from its Mombasa refinery.

For Kenya's president, the country's relative economic standing is no salve for politicl problems that stand in starker relief because Moi succeeded Jomo Kenyatta, the man who led Kenya to independence. Kenyatta, who died three years ago, "was a legend," the critical professor said. "Moi's instincts are right: he's solid, but he can't rely on Kenyatta's charisma."

Nevertheless, many of the problems are the Moi government's own doing. Mismanagement and corruption in the agriculture field have led to declining production and vast food shortages, exacerbated by drought last year. Food is Kenya's key problem. The country is spending more than $200 million in foreign exchange to import more than half a million tons of grain when just over a year ago it was exporting corn, the staple of the diet.

"All the political problems are triggered by economic ones," a Western diplomat commented. He cited difficulties in food production, population growth, energy and import policy that are not being adequately handled. "There is a reluctance to face up to problems," he said.

The trade deficit last year was almost $1 billion. Reserves now could cover only two months' imports.

Attempts to put a clamp on imports led to shortages and reports of increased corruption. The backlog in obtaining import licesnes is as much as nine months.

"A score of Kenya's major industries are not threatened with closure because of delays in clearing import licenses for essential raw materials," according to the Kenyan association of manufacturers.

The manager of an American company accused the government of poor management and lack of direction. Instead of dealing with pressing problems, Moi "is lashing out at all sorts of petty things," he said.

"The favoirte headline in the Kenya press," one cynic said, "is 'Moi Attacks' or 'Moi Blasts.'"

Lately those on the receiving end have included striking doctors (some of whom have been jailed) and demonstrating students (the University of Nairobi has been closed indefinitely).

Adding to the president's troubles was a clumsy treason trial, the country's first. It exposed rifts among politicians in the Kikuyu tribe, Kenya's largest, as they jockey for position to succeed Moi. Attorney General James Karugu, an American-educated, new-generation Kenyan politician, resigned after the judge acquitted the defendants and criticized the prosecution for bringing the case.

The key defendant, Andrew Muthemba, is a relative of Charles Njonjo, a leading Kikuyu and one of the officials closest to Moi Njonjo called the trial "political blackmail," implying that he was the target of the other Kikuyu camp, led by Vice President Mwai Kabaki.

A further political setback involved Moi's attempt to rehabilitate a former vice president. This was scotched when the former official inexplicably attcked Kenyatta.

As an offshoot of his political woes, Moi has become testy with the press. Six senior editors and reporters on the Daily Nation, owned by the Aga Khan, were temporarily jailed over an article Moi objected to. It was an unprecedented move in a country that has been proud of its relative press freedom. The editor, Joe Rodriguqz, who was jailed overnight, resigned this month. The president also threatened to close the paper, the country's largest.

Much of the private criticism of Moi is centered on the growth of power in the presidential office. Many key decisions are now made by a small coterie of officials around Moi without proper staff work or consultations with the relevant ministries. Often the decisions have had to be abruptly reversed.

The current four-year development plan has been trimmed by about 25 percent because of the economic crisis, but the plan's share of expenditures for the president's office increased from less than 7 percent to more than 10 percent.

Businessmen and diplomats complain that many ministers are emasculated and that it is hard to reach the decision-makers.

A senior civil servant, complaining about frequent shakeups and lack of advance information, was quoted by a Kenyan businessman as saying, "I have to listen to the radio ti know if I still have a job."

One insider said what the country needs to do to prosper once more is to develop competitive industries capable of exporting so that the agricultural sector does not have to continue subsidizing the inefficient domestric manufacturers.

An Englishman, deeply involved in Kenya for more than a decade, was less sanguine.

Noting the decline in telephone and electricity service, import problems and food shortages, he sid sarcastically: "Kenya's success is that it is declining slower than any other black African country."

Often, however, the relative openness of Kenyan society permits venting of criticism that would be stifled in other African countries. Even critics acknowledge that Kenya has made vast strides since independence.

A black Kenyan printer, James Mwanthi, 46, put the situation in context in an interview. Mwanthi made the routine complaints common to businessmen about hard times.

Then, reflecting on the days before independence, he said, "All Kenyans are better off. Sometimes ignorance is bliss. Before, they didn't realize how bad off they were. Now they're better educated, so they complain more."