BOSTON (AP) — Massachusetts Gov. Charlie Baker says he may spend up to $20 million in the campaign to keep his seat in the corner office.

The Republican and his running mate, Lt. Gov. Karyn Polito, were required to set the cap because they didn't accept public financing and the $1.5 million limit that would have come with it.

Baker's Democratic opponent Jay Gonzalez, who agreed to the public limits, can now also spend up to $20 million, although hitting that mark may be difficult. Gonzalez had about $188,000 in his campaign account as of Aug. 31 compared to Baker's $6.3 million.

Gonzalez will receive about $743,000 from the state campaign fund, leaving no additional public funds for any other candidates who agreed to the spending limits.

State law calls for participating candidate teams for governor and lieutenant governor to be funded first, with any remaining money distributed evenly to eligible candidates for other statewide offices.

Democratic Attorney General Maura Healey, who also opted out of the public campaign funding program, set a $2.5 million spending cap over the statutory limit of $625,000. The $2.5 million limit will now also apply to her Republican opponent James McMahon.

Healey had about $2.1 million in her campaign account as of Aug. 31. McMahon had about $6,300.

In the secretary of state's race, Republican Anthony Amore set a $2 million cap above the statutory limit of $375,000. The $2 million cap now also applies to Democratic incumbent William Galvin and Juan Gabriel Sanchez of the Green-Rainbow Party.

Amore had about $20,000 in his campaign account as of Aug. 31, compared to $465,000 for Galvin.

The setting of a cap doesn't necessarily mean that a candidate will spend that amount, only that a candidate won't spend above that limit.

In the state treasurer's race, Democratic incumbent Deb Goldberg and Republican challenger Keiko Orrall both set the same $2 million spending limit over the statutory spending limit for treasurer of $375,000.

The $2 million limit will apply to Goldberg, Orrall and Jamie Guerin of the Green-Rainbow Party.

And in the race for state auditor Republican challenger Helen Brady has set a limit of $375,000, which will also apply to Democratic incumbent Suzanne Bump. Libertarian candidate Daniel Fishman; and Edward Stamas of the Green-Rainbow Party.

Two candidates received public finance funding for their primary races: Gonzalez and fellow Democratic gubernatorial hopeful Robert Massie. Gonzalez received $302,564 in public funds, and Massie received $164,842.

Gonzalez won the primary.