TOKYO, JUNE 4 -- Japan is willing to contribute to "international cooperation" aimed at protecting commercial shipping in the Persian Gulf and will make new diplomatic initiatives to try to end the war there, Prime Minister Yasuhiro Nakasone told foreign journalists today.

Nakasone did not spell out what type of international cooperation he meant. He sidestepped questions over whether his government is prepared to help fund escort operations by U.S. or other military forces.

He said Japan would decide its role if and when an "international and workable scheme" to guard shipping is devised. In any case, Japan's role would be "peaceful and nonmilitary," he said.

Nakasone's remarks came as he prepared to leave for the seven-nation summit meeting in Venice next week. Security in the gulf, where Japan buys 60 percent of its oil, is set to be a major subject of discussion.

Sending Japanese warships there is considered here to be politically and legally out of the question. The country has a "peace constitution" that rules out foreign expeditions, and antimilitary sentiments left by World War II remain strong in much of society.

But with pressure mounting from Washington, some Japanese officials favor paying some of the costs incurred by other forces there, providing they are deployed under the flag of the United Nations or some multilateral grouping.

In his 4 1/2 years in office, Nakasone has favored gradually expanding Japan's role in international security affairs, which he argues is its responsibility as it emerges as an economic superpower. However, he faces stiff opposition in many quarters.

Since the attack on the USS Stark last month, President Reagan has been calling on U.S. allies to help in the gulf. Members of Congress have criticized Japan, complaining that it is getting a military "free ride" from the United States.

Many Japanese have bridled at this criticism, seeing it as another example of Japan-bashing born out of trade disputes.

A sustained shut-off of gulf oil would mean economic catastrophe here, as Japan maintains only a 90-day emergency reserve. Over the past three years, five ships crewed by Japanese or operated under the Japanese flag have been attacked in the gulf and one Japanese sailor killed.

Opposition circles here have assailed the U.S. naval presence in the gulf as foolhardy and demanded Japan take no role.

But in the Japanese government, the U.S. effort is generally regarded as a common-sense response to a threat to commercial shipping. "We would like to pay tribute as well as express gratitude for the efforts that are being made by the United States and some other countries for the maintenance of safety of navigation in that area," Nakasone said today.

The idea of Japanese forces going to the gulf is seen as so outlandish here that laughter swept the room at a press luncheon in Tokyo last week when the guest speaker, Foreign Minister Tadashi Kuranari, was asked about it. He said no.

Still, many members of the government feel that funding multilateral peace-keeping operations would be a good way for Japan to expand its security role.

In the gulf, directly underwriting a lone effort by the United States would be too much for the public to accept, many Tokyo analysts say. But if the force operated under the flag of the United Nations or some multilateral organization, it would be easier to peddle politically.

Throughout the Iran-Iraq war, Japan has kept full diplomatic relations with both sides and it buys oil from both.

Nakasone promised efforts to pursue peace in the U.N. Security Council, to strengthen political and economic stability of the gulf states, and to aid reconstruction once the war is over. Foreign Minister Kuranari is reported to be trying to arrange a visit to Iran after the Venice meeting, presumably to discuss a possible settlement.