Martin Shkreli apologized to a federal judge and asked her not to revoke his bail for offering money to anyone who could grab a lock of Hillary Clinton's hair.

"I wanted to personally apologize to this court and my lawyers for the aggravation that my recent postings have caused," Shkreli wrote in a letter to Judge Kiyo Matsumoto.

Shkreli was convicted of fraud last month for misleading investors. He is scheduled to attend a hearing Wednesday afternoon on a request by prosecutors to revoke his bail because of what he said about Clinton.

"I understand now, that some may have read my comments about Mrs. Clinton as threatening, when that was never my intention when making those comments," Shkreli wrote in the letter, filed Tuesday. "I used poor judgment but never intended to cause alarm or promote any act of violence whatsoever."

In a Facebook post Sept. 4, Shkreli promoted a conspiracy theory about the Clinton Foundation and offered money for a lock of Clinton's hair. Prosecutors called the post part of "an escalating pattern of threats and harassment." They said it triggered an investigation by the Secret Service.

Shkreli later edited the post to say it was "satire" and then removed it altogether. He noted in his letter to the judge that he had followed it up with another post saying that he was not encouraging assault.

"It never occurred to me that my awkward attempt at humor or satire would cause Mrs. Clinton or the Secret Service any distress," Shkreli wrote in his letter to the judge. "I want to assure Your Honor that I am not a violent person, have never personally engaged in any violent behavior, nor have I ever intentionally encouraged anyone to do so."

Related: Prosecutors ask judge to revoke Shkreli bail

In a separate letter to the judge, Shkreli's lawyer Ben Brafman said the posting shouldn't be considered a threat.

"While Mr. Shkreli's comments were tasteless to many, they were not made in a threatening manner," Brafman said.

Shkreli, a former portfolio manager and pharmaceutical executive, was convicted on Aug. 4 of two counts of fraud and one count of conspiracy for misrepresenting the financial state of his hedge funds to investors. The top charge carries a sentence of up to 20 years. A sentencing date has not been set.

Shkreli, 34, is best known for jacking up the price of Daraprim, a drug used by AIDS and transplant patients, to $750 a pill from $13.50 while he was CEO of Turing Pharmaceuticals in 2015.

But that had nothing to do with the fraudulent behavior that led to his conviction. His lawyer took great pains to try to insulate the jury from the caustic reputation of Shkreli, who smirked his way through a congressional hearing last year while pleading the Fifth and tweeting that lawmakers were "imbeciles."

Related: Shkreli convicted of securities fraud, conspiracy

His antics continued in court. The judge chastised him for entering a room reserved for reporters unaccompanied by his lawyer, where he dismissed his prosecutors as "junior varsity." He also maintained an active presence on social media throughout the trial, where he offered commentary about the proceedings. Prosecutors also mentioned his online harassment of a Teen Vogue editor in January, which got him kicked off Twitter.