Elon Musk is suing OpenAI and its CEO Sam Altman over what he says is a betrayal of the ChatGPT maker’s founding aims of benefiting humanity rather than pursuing profits.

In a lawsuit filed at San Francisco Superior Court, billionaire Musk said that when he bankrolled OpenAI’s creation, he secured an agreement with Altman and Greg Brockman, the president, to keep the AI company as a nonprofit that would develop technology for the benefit of the public.

Under its founding agreement, OpenAI would also make its code open to the public instead of walling it off for any private company’s gains, the lawsuit says.

However, by embracing a close relationship with Microsoft, OpenAI and its top executives have set that pact “aflame” and are “perverting” the company’s mission, Musk alleges in the lawsuit.

OpenAI declined to comment on the lawsuit Friday.

WATCH:What led to the OpenAI leadership shakeup and what it means for the future of AI

“OpenAI, Inc. has been transformed into a closed-source de facto subsidiary of the largest technology company in the world: Microsoft,” the lawsuit filed Thursday says. “Under its new Board, it is not just developing but is actually refining an AGI to maximize profits for Microsoft, rather than for the benefit of humanity.”

AGI refers to artificial general intelligence, which are general purpose AI systems that can perform just as well as — or even better than — humans in a wide variety of tasks.

Musk is suing over breach of contract, breach of fiduciary duty and unfair business practices. He also wants an injunction to prevent anyone, including Microsoft, from benefiting from OpenAI’s technology.

Musk was an early investor in OpenAI when it was founded in 2015 and co-chaired its board alongside Altman. Musk’s lawsuit said he invested “tens of millions” of dollars in the nonprofit research laboratory.

WATCH: OpenAI CEO Sam Altman testifies before Senate Judiciary Committee

Musk resigned from the board in early 2018 in a move that OpenAI said at the time would prevent conflicts of interest as the Tesla CEO was recruiting AI talent to build self-driving technology at the electric car maker. “This will eliminate a potential future conflict for Elon,” OpenAI said in a February 2018 blog post. Musk has since said he also had disagreements with the startup’s direction, but he continued to donate to the nonprofit.

Later that year, OpenAI filed papers to incorporate a for-profit arm and began shifting most of its workforce to that business, but retained a nonprofit board of directors that governed the company. Microsoft made its first $1 billion investment in the company in 2019 and the next year, signed an agreement that gave the software giant exclusive rights to its AI models. That license is supposed to expire once OpenAI has achieved artificial general intelligence, the company has said.

When the nonprofit board abruptly fired Altman as CEO late last year, for reasons that still haven’t been fully disclosed, it was Microsoft that helped drive the push that brought Altman back as CEO and led most of the old board to resign. Musk’s lawsuit alleged that those changes caused the checks and balances protecting the nonprofit mission to “collapse overnight.”