Five states, 24 members of Congress and several consumer groups have filed a legal challenge to the financing arrangements for the planned $40 billion Alaska natural gas pipeline, an action that could delay or possibly cancel the entire mammoth project.

In a petition to the U.S. Court of Appeals here, the plaintiffs charged that Congress violated its own rules when it approved a waiver to the pipeline construction consortium's charter permitting construction costs to be billed to consumers in advance.

They said "the waiver exposes natural gas consumers in 36 states to the costs of financing a massive pipeline project which may never be completed or carry any gas. The expenses consumers will have to pay approximate $32 billion."

John G. McMillian, chairman of Northwest Alaskan Pipeline Co., the consortium of energy companies that received a charter to build the pipeline in 1977, said consumers would have to pay the costs of any delay caused by the litigation.

He said the court action "appears to be politically motivated and totally without foundation or merit, and we do not expect that it will succeed. However, I am extremely concerned that this action, even though unsuccessful, will seriously delay the project and result in major capital cost increases which will be borne by the gas consumer," McMillian continued. "A delay of a year will cost the consumers more than $3 billion."

The issue is not whether gas consumers should have to pay for the pipeline--the law specifies that they pay 75 percent of the construction cost--but whether they have to pay before the gas starts to flow. The possibility that they might pay for a pipeline that never was built, or from which gas was so expensive that it could not be marketed, is what stirred opposition to the waiver package.

Northwest Alaskan's original charter did not permit advance billing. It also prohibited the oil companies producing the gas on Alaska's North Slope from owning a share of the pipeline, and it required the members of the consortium to bear the cost of a $3.6 billion plant for gathering and processing the gas instead of including it in the costs that eventually would be passed on to consumers.

Northwest Alaskan, unable to obtain financing for the project under those restrictions, asked that they be waived. In October, President Reagan recommended that Congress grant the waivers, and it did so late last year.

Even with the waivers, it was not certain that Northwest Alaskan's lead banks--Bank of America, Citibank, Chase Manhattan and Morgan Guaranty--would be able or willing to arrange adequate long-term financing.

If the court overrules the waivers, the entire project might have to be abandoned, according to the pipeline company, because oil producers "are reluctant to make a considerable financing commitment without equity participation," or a share of ownership. "Without producer support, private financing will be impossible," the company said.

The pipeline is intended to transport natural gas from the North Slope to terminals in Iowa and California. Opponents of the waivers, including Ralph Nader, have argued that if the pipeline is as important and potentially profitable as Northwest Alaskan says it is, the banks should finance it like any other commercial project. If it is not, it is unfair to make consumers bear the burden, they argue.

The legal petition was filed directly with the Court of Appeals under an unusual provision of the original pipeline law designating that court to hear legal challenges involving the project. The court is expected to rule within 90 days, attorneys in the case said.

In their petition, the plaintiffs said that Congress acted illegally in voting for the waivers without public hearings before committees, and that the Federal Energy Regulatory Commission violated federal law in issuing the waivers without "notice or opportunity for hearing or comment."

The plaintiffs include Nader, the States of Iowa, Michigan, Minnesota, Ohio and Rhode Island, Rep. Parren Mitchell (D-Md.), 16 other members of the House, and Senators Howard Metzenbaum (D-Ohio), David F. Durenburger (R-Minn.), William Proxmire (D-Wis.), Donald W. Riegle Jr. (D-Mich.), Paul E. Tsongas (D-Mass.), and Harrison A. Williams Jr. (D-N.J.).