The trial of Linwood Gray, the alleged mastermind of a Washington based multimillion-dollar international heroin ring, began in U.S. court here yesterday as his defense attorney said he would try to prove first that Gray did not commit the crime, but that if he did, he was insane at the time.

Gray's attorney, Kenneth Michael Robinson, told U.S. District Court Judge William B. Bryant, that his client was not capable of premeditating "the whole scheme," a purported plot in which federal prosecutors say that $30 million worth of extremely high-grade heroin was smuggled from the opium fields of Southeast Asia to the streets of Washington.

While Bryant said he would let Robinson introduce psychiatric evidence attempting to show that Gray was insane, and thus did not know the difference between right and wrong, the judge refused the defense attorney's bid to claim that Gray has "diminished capacity," meaning that he is not smart enough to mastermind the alleged smuggling operation.

A defense claiming that a defendant has a "diminished capacity" is more novel than a claim of not guilty by reason of insanity. Bryant said that if Robinson could later offer him evidence of the diminished capacity claim he might allow such testimony.

Gray, 34, has had some success in the past claiming that he was insane at the time he committed various crimes. In other cases he has been found sane.

In a 1967 court appearance, he beat up a probation officer in court and had to be removed by four court officers. He later was committed to St. Elizabeths Hospital and shortly after he was admitted he boasted to a friend that the attack on the probation officer and his feigned insanity enabled him to beat the charges against him.

Earlier this year, Gray cursed and shouted at a magistrate and berated a U.S. marshal at a bond hearing. Yesterday, he was a model of decorum as his attorney, prosecutors and lawyers for 11 codefendants argued pretrial motions and started to pick a jury.

Gray, dressed in blue prison denim shirt and pants and sneakers, sat glumly with the other defendants, most of the time cradling his chin in his left palm. Robinson said that Gray would testify at the trial, which may last six weeks.

Over Robinson's objections, Bryant ruled that there would be no mention at the trial of the Dec. 20 courthouse parking lot shooting of the chief prosecutor in the case, Assistant U.S. Attorney Barry L. Leibowitz. Law enforcement officials have suspected from the day of the shooting that Leibowitz' tenacious, 15-month investigation of the alleged heroin ring prompted someone to try to kill him. He was injured slightly in the shooting but quickly resumed the probe.

One man was charged briefly with the shooting, but the charge then was dropped and no one has been charged since.

"Why should you bring out in front of the jury that an assistant United States attorney was shot?" Bryant asked Robinson.

Robinson explained that his client was quoted in a wiretapped Jan. 18 telephone call, five days before his arrest as saying. "Leibo is trying to frame us."

The defense attorney said that was a reference to the shooting and that Gray was "in fear of a zealot pursuing him." Robinson said that in the days before his arrest Gray shopped for a lawyer. Gray also reportedly gave his wife $50,000 for his legal defense.

Bryant and the lawyers will continue to question the 165 prospective jurors this morning.