AI assistant Pro
Pro · This feature is part of Snipfire Pro. Plans
The AI assistant works inside the editor, with your own API key:
- Explain this snippet: what the code does, in plain language.
- Fix this error: a proposed fix for the problems in the Problems panel, shown as a change you can review before applying it.
- Write with AI: describe what you need, and get a new snippet to check before you save it.
It only does something when you click, and your key never leaves your server. You pay your AI provider for what you use; Snipfire adds no charge and no service of its own.
This is different from WordPress abilities, which let an AI assistant you already use (such as Claude Desktop) work with your snippets from outside. Both can be used together.
Set it up
- In the editor, click AI assistant at the bottom of the sidebar.
- Choose the Provider:
- Anthropic (Claude),
- OpenAI,
- OpenAI-compatible provider: any service or local server that speaks OpenAI's Chat Completions API, such as OpenRouter, Ollama or LM Studio. Enter its API address, the part that ends before
/chat/completions, for examplehttp://127.0.0.1:11434/v1for Ollama on the same server. It must start withhttps://;http://only works for a server on the same machine (localhost,127.0.0.1).
- Model: leave it empty to use the provider's default model (shown as the placeholder), or type any model name your provider offers, as they spell it. The default is only a starting point: providers bring out new models often, so check their list. For an OpenAI-compatible provider, type the model name.
- API key: paste the key from your provider's dashboard. It's saved in the secrets vault as
ai_api_key, encrypted, and never comes back to the browser. (A local server that needs no key can leave it empty.) - Who can use it: People with full Snipfire access (the default), or Also people with CSS, JS and HTML access.
- Tick Use the AI assistant in the editor, click Save, then Test the connection. You should see Connected: … answered "OK".
Time limit (seconds) (default 60) and Longest answer (tokens) (default 4096) can usually stay as they are. Raise the time limit for slow local models.
Setting it up needs the same access as the secrets vault: administrators with full Snipfire access (super admins on multisite).
Explain and fix
Open a snippet and click AI assistant in the toolbar. A panel opens beside the code:
- Explain this snippet sends the code and shows an explanation under the buttons.
- Fix this error is available when the Problems panel lists errors (or the snippet was switched off after one). It sends the code and the errors, and shows the proposed change as a comparison (Proposed change: +3 −1 lines). Apply to editor puts it in the editor; Discard drops it. Nothing is saved until you save the snippet, and saving runs the usual checks and test load. If you changed the code while waiting, you're asked before the fix replaces it.
A fix is only offered for code you're allowed to change: with CSS, JS and HTML access, not for PHP snippets.
Write a snippet with AI
Click + New → Write with AI… (or, on a new, empty snippet, Not sure how to write it? Describe it and let AI write it).
- Under What should the snippet do?, describe it, for example Show a "Free shipping over €50" notice above the cart on WooCommerce pages.
- Choose the Type, or Let the AI choose.
- Click Write snippet.
The snippet opens in the editor switched off and not saved yet, with the AI's notes in its description. Read it, test it, then save and switch it on: it goes through the same checks and test load as any snippet.
People without full access (and everyone while SNIPFIRE_DISABLE_PHP is set) never get PHP from it. It doesn't write snippets that go next to an element; set that location yourself.
What is sent, and where
Only when you click, and only to the provider you chose:
- Explain: the snippet's code, type, title and where it runs.
- Fix: the same, plus the errors.
- Write: your description and the type.
- Include site context (a tick box, off unless you tick it): your WordPress and PHP versions, site language, theme, and the names and versions of your active plugins, so the answer fits your site.
Never sent: your other snippets, your secrets (if a secret's value appears in the code, it's removed before sending), your content, or anything about your visitors. Snipfire asks the provider to answer in your profile language.
Your provider's own terms decide what they keep and whether they train on it. Check them, or use a local model through an OpenAI-compatible server if the code mustn't leave your server.
Limits and costs
- 30 requests per person per hour. After that: You've used the AI assistant 30 times in the last hour, the most allowed. Try again in … minutes. Developers can change the limit with the
snipfire_ai_rate_limitfilter. - Costs: each request uses tokens from your provider account, more for long code and long answers. Your provider's dashboard shows what you've used. Test the connection uses only a few.
- Answers can be wrong. Treat them like code from a colleague: read it before you switch it on. Crash protection still applies, but it can't catch code that runs without errors and does the wrong thing.
When something goes wrong
| Message | What to do |
|---|---|
| Add your API key in the AI settings first. | Enter the key under AI assistant |
| The AI assistant isn't set up. An administrator can switch it on in the AI settings. | Tick Use the AI assistant in the editor and save |
| The AI API key can't be decrypted any more (the site's encryption key changed)… | The encryption key changed. Enter the key again |
| The AI provider didn't answer within 60 seconds… | Try again, or raise Time limit (seconds) |
| Couldn't reach the AI provider: … | Your server can't connect. Ask your host to allow outgoing connections to the provider |
| An error from the provider (wrong key, no credit, rate limit, overloaded) | Check your provider account. For refused requests, the provider's own message is shown |
From the command line
printf %s "$ANTHROPIC_API_KEY" | wp snipfire secret set ai_api_key
wp snipfire ai setup --provider=anthropic --enable
wp snipfire ai setup --provider=compatible --base-url=http://127.0.0.1:11434/v1 --model=llama3.1 --enable
wp snipfire ai test
wp snipfire ai status
setup only changes the options you give: --provider, --model ("" for the default), --base-url, --timeout, --max-tokens, --access (full or design), --enable, --disable. See WP-CLI and the REST API.
The default models can be changed for all sites you build with the snipfire_ai_default_models filter: see PHP hooks.
Something unclear or missing? Tell us