AI setup (bring your own key)
5 min read
Mass Custom Fields can write content for your generated pages with AI. It works on the BYOK principle: you bring your own API key from OpenAI, Anthropic or Google. Requests go from your server straight to the provider; nothing passes through WPMass, and the provider bills you for the usage (see AI privacy and costs).
AI is part of Pro and higher. Without the plan the AI tab does not exist.
Open the settings
Go to WPM Fields › Settings › AI. The card AI provider says: "Programmatic SEO uses this provider to write field content for each generated page. You bring your own API key."
1. Choose the provider and model
Provider | Default model | Models suggested before you add a key |
|---|---|---|
OpenAI |
| GPT-5 mini, GPT-5, GPT-4.1 mini |
Anthropic |
| Claude Haiku 4.5, Claude Sonnet 5.5 ( |
Google Gemini |
| Gemini 2.5 Flash, Gemini 2.5 Pro |
Pick the Provider, then the Model. "Smaller models are cheaper and usually good enough for field content." When you switch the provider without choosing a model, the new provider's default is used.
The model list is live once a key is saved: "%d model available to your API key." It shows the text models your account can use (OpenAI: chat models, no audio, image, search or embedding models; Anthropic: its models; Gemini: text models). It is cached for 12 hours per provider and refreshed when you save or remove the key or click Refresh list. Before a key exists you see "Suggested models. Save an API key to list every model your account can use." If the list cannot be loaded: "Could not load the models of your account: …".
Choose Other model… to type a Model id "Exactly as the provider names it in its API documentation." (letters, digits and . _ : / -, up to 100 characters).
Providers retire and add models; if a model stops working use Refresh list or type the new id.
2. Add the API key
Create a key in your provider's console (OpenAI Platform, Anthropic Console, Google AI Studio), then:
Option A (recommended): define it in wp-config.php.
define( 'WPMCF_AI_OPENAI_KEY', 'sk-…' );
define( 'WPMCF_AI_ANTHROPIC_KEY', 'sk-ant-…' );
define( 'WPMCF_AI_GEMINI_KEY', '…' );The key never enters the database. The field then shows the badge Defined in wp-config.php and "Set in wp-config.php with WPMCF_AI_OPENAI_KEY. Remove the constant to manage the key here." A constant always wins over a saved key.
Option B: paste it in the settings. Paste into API key ("Paste your API key") and click Save key ("API key saved."). Keys may not contain spaces and are at most 500 characters ("Paste the API key without spaces.").
Each provider has its own key field (OpenAI API key, Anthropic API key, Google Gemini API key); saved keys of other providers are kept when you switch.
How keys are protected
- Saved keys are stored encrypted (libsodium secretbox, with a key derived from your site's security salts) in the option
wpmcf_ai_keys, which is not autoloaded and never exported. - A key is never sent to the browser. After saving, the field shows only "A key ending in …abcd is saved (encrypted). Paste a new key to replace it." (the last four characters; shorter keys show nothing).
- Keys are scrubbed from the error messages of providers.
- If you change the salts in
wp-config.php(or move the database to a site with other salts) the saved key can no longer be decrypted: "The saved key can no longer be read (the site salts changed). Enter it again." Constants are not affected. - Remove deletes a saved key ("API key removed.").
- Only administrators can manage keys; other roles get HTTP 403.
3. Limits and answer length
Setting | Default | Range | Meaning |
|---|---|---|---|
Requests per minute | 20 | 1 to 600 | "Keep this below your provider account limit." The AI run waits when it reaches it. |
Maximum answer length (tokens) | 2,000 | 256 to 16,000 | The longest answer one request may produce. A request for many fields or long FAQ lists needs more; a cut-off answer fails with "The AI answer was cut off at the maximum answer length. Raise "Maximum answer length (tokens)" in Settings › AI or ask for fewer or shorter fields." and is not retried. |
Requests wait up to 60 seconds for an answer. Click Save changes ("AI settings saved.") to store provider, model and limits.
4. Test the connection
Save your changes, then click Test connection. It sends one tiny request (about 64 output tokens, an amount of money you will not notice) and answers "Connected. The model gpt-5-mini answered." or Connection failed with the provider's message. If you changed the provider or model first, the page asks you to "Save your provider and model changes before testing the connection."
Typical errors:
Provider message | Meaning |
|---|---|
"Incorrect API key provided" (HTTP 401/403) | Wrong or revoked key |
"You exceeded your current quota…" | No credit or quota left on the provider account |
"Rate limit…" (HTTP 429) | Too many requests; lower Requests per minute |
Server error (HTTP 5xx) or timeout | Provider problem; try again later |
What happens when something fails during a run
See AI briefs and runs: rate limits pause the run, a rejected key or an empty account stops it with a message, a broken answer fails only that page.
For developers
The providers come from the filter wpmcf/ai/providers (provider id → an object implementing the plugin's Provider interface); this is how a custom or self-hosted gateway can be added. Keys of added providers use the constant name WPMCF_AI_{PROVIDER}_KEY with the provider id in capitals.
Still stuck? Contact support