Elon Musk filed a lawsuit against OpenAI and its chief executive, Sam Altman, for breaching a contract by prioritizing profit and commercial interests in developing artificial intelligence over the public good.

Mr. Musk, who helped create OpenAI with Mr. Altman and others in 2015, said the company’s multibillion-dollar partnership with Microsoft represented an abandonment of its founding pledge to carefully develop A.I. and make the technology publicly available.

“OpenAI has been transformed into a closed-source de facto subsidiary of the largest technology company, Microsoft,” said the lawsuit, which was filed Thursday in Superior Court in San Francisco.

The lawsuit is the latest chapter in an ongoing fight between the former business partners that has been simmering for years. After Mr. Musk left OpenAI’s board of directors in 2018, the company went on to become a leader in the field of generative A.I. and created ChatGPT, which can produce text and respond to queries in humanlike prose. Mr. Musk, who has his own A.I. company, called xAI, said OpenAI is not focused enough on the technology’s existential risk to humanity.

Mr. Musk’s lawsuit said OpenAI was created as a nonprofit to develop artificial intelligence for the “benefit of humanity.” A key component of that, the lawsuit said, was to make its technology open source, meaning it would share the underlying software code with the world. Instead, the company created a for-profit business and has restricted access to its technology.

OpenAI and Mr. Musk did not respond to requests for comment.

The lawsuit is a fresh challenge for Mr. Altman, who was briefly ousted as OpenAI’s chief executive last year before regaining control of the company. In addition to Mr. Altman, the lawsuit also names Greg Brockman, the president of OpenAI, as a defendant.

The New York Times sued OpenAI and Microsoft in December, claiming copyright infringement of news content which was used to train the chatbots.