AI
The AI edition adds an AI assistant, an AI chat, a text review, autocomplete, alt text and texts for publishing. AI functions run through your own endpoint on your own API key with OpenAI, Anthropic or an OpenAI-compatible service. The API key never reaches the browser, and the vendor is not involved in AI requests or payments.
How it works
- The editor sends
{ action, data }to your endpoint (ai.url) with the CSRF token in theX-CSRF-Tokenheader. - Your endpoint checks that the user may edit content and passes the request to
VEditor\AiApi. AiApichecks POST, the CSRF token, the request size, the licence (AI edition) and the features allowed for the user, then calls the provider throughAiClient.- HTML from the model is sanitized on the server and again by the editor schema before the preview.
Prompts live only on the server (VEditor\AiActions). The browser sends the content, the action name, a tone and a language from whitelists and the user’s own prompt, which goes into the model input, never into the instructions.
Endpoint
The Laravel, Symfony and Yii2 integrations include the endpoint. Without a framework see PHP without a framework. In the editor:
await VEditor.create('#content', {
ai: { url: '/veditor/ai', csrfToken: token, autocomplete: false },
});
If the editor cannot load the AI settings from ai.url (wrong address, server error), the AI buttons stay hidden and the browser console shows “AI settings could not be loaded.” The AI buttons appear only when ai.url is set and the licence covers the AI edition (on local and test addresses: a trial key or an AI edition key).
Supported AI models
The model name (aiTextModel) selects the provider: a claude-… model uses Anthropic (Claude), any other model uses OpenAI. Without a model, VEditor uses OpenAI gpt-6.1-terra.
| Provider | Model | API key | API address |
|---|---|---|---|
| OpenAI (default) | gpt-6.1-terra or another non-Claude model | aiApiKey (OPENAI_API_KEY) | aiEndpoint |
| Anthropic (Claude) | claude-haiku-5-5, claude-sonnet-5-5, claude-opus-5-5 | aiAnthropicKey (ANTHROPIC_API_KEY) | aiAnthropicEndpoint |
| OpenAI-compatible service | required, for example llama3.1 | aiApiKey | aiEndpoint (required) |
You need only the key of the provider of the chosen model. Without it the editor shows no AI buttons. Never put a Claude key in aiApiKey. aiProvider is needed only for an OpenAI-compatible service (openai-compatible). The API address can point to a company proxy; empty means the provider’s default address.
Tested models: gpt-6.1-terra, claude-haiku-5-5, claude-sonnet-5-5 and claude-opus-5-5. Another model works, but VEditor writes a warning with the list of tested models to the PHP error log once. To have a model tested and added, send a request.
With Claude, simple tasks (alt text, SEO title and description, autocomplete) use low effort, which is faster and cheaper. The answer limit is at least 4,000 tokens, because the model’s thinking counts towards it; you pay only for the tokens the model generates.
Functions
| Function | What it does |
|---|---|
| AI assistant | for a selection: “Improve writing”, “Fix spelling and grammar”, “Make shorter”, “Make longer”, “Simplify”, “Continue writing”, “Change tone” (professional, casual, friendly, confident, empathetic, formal), “Translate”, or your own prompt in “Ask AI to write or edit…”; without a selection the same actions work on the current paragraph, and in an empty paragraph your prompt or “Continue writing” writes new text at the caret |
| Document translation | “Whole document” → “Translate”: the whole content with its structure, preview in a window, “Replace document” or “Cancel” |
| Texts for publishing | summary (lead), SEO description, 3 title ideas, slug; copy or insert the summary at the top |
| Alt text | “Describe (AI)” next to the alt text field in the image dialog |
| AI chat | a side panel conversation about the document and the selection; insert the answer, replace the selection or copy; nothing is stored |
| Text review | “Check the text (AI)” in the review panel: spelling, grammar, punctuation, style, clarity and consistency, each remark highlighted with “Apply” and “Skip” |
| Autocomplete | with ai.autocomplete: true, after a pause at the end of a paragraph (20+ characters) a grey suggestion of a few words; Tab accepts, Esc or typing rejects |
| Your actions | actions defined by the administrator (aiActions), with prompts on the server |
Every result first goes to a preview. A changed selection or paragraph offers “Replace”, “Insert below”, “Try again” and “Discard”; new text at the caret offers “Insert”, “Try again” and “Discard”; a translated document offers “Replace document” and “Cancel”. Applying a result is one undo step. The assistant, the document translation and the chat are streamed: the text appears as the model writes; “Cancel” (before the first words) or “Stop” ends the assistant and the chat, and the × closes the translation window.
Text review
“Check the text (AI)” sends the document to the model and lists its remarks under “Text” in the review panel. Each remark shows its type, the original fragment crossed out, the suggestion (“∅” when the suggestion removes the fragment) and, if the model gave one, an explanation. Pointing at a remark with the mouse or the keyboard highlights the fragment in the content without changing the document, and clicking the change scrolls to the fragment.
- Apply replaces the fragment in the content with the suggestion as one undo step and removes the remark from the list. The fragment is looked up by its text (first with matching case, then ignoring case). If it is no longer in the text, for example because you edited it, “Apply” is disabled and the remark says “The fragment is no longer in the text.”
- Skip removes the remark from the list without changing the content.
When every remark is handled, the panel shows “All suggestions handled.” “Check again” appears once a remark has been handled or when there are no remarks, and sends the current content again. Remarks are not stored: after closing and reopening the panel, the text check starts again from “Check the text (AI)”.
Editor options
| Option | Default | Description |
|---|---|---|
ai.url | none | your endpoint |
ai.csrfToken | none | sent in X-CSRF-Token |
ai.headers | {} | extra headers |
ai.languages | en, pl, de, fr, es, it, uk, cs | translation targets. Accepted codes: the 36 interface languages plus ru, ja, zh, ko, ar and no; regional codes such as pt-BR use the base language. |
ai.language | editor language | language of alt text |
ai.autocomplete | false | autocomplete; every suggestion is a paid request |
ai.autocompleteDelay | 900 | pause in milliseconds before a suggestion |
For your application
const meta = await editor.aiTools.metadata(); // { summary, metaDescription, titles, slug }
document.querySelector('#seo-description').value = meta.metaDescription;
const alt = await editor.aiTools.describeImage('/uploads/photo.webp');
editor.on('aiMetadata', (meta) => { /* texts generated in the dialog */ });
Images and privacy
For alt text the browser scales the image down to 1024 px and sends it as JPEG; the server never fetches URLs. The image must come from the same domain or allow CORS. Content is sent to the provider only when a user starts an AI function; mention this in your privacy policy.
Costs and control
- You pay the provider directly according to its pricing.
aiFeatureslimits functions per user,aiBeforeRequestruns before every paid request (for example a daily limit), andaiContextadds your brand guidelines to every request. See Server configuration.- Errors from the provider are shown as short messages; details go to the PHP error log, never with the key.
Limits
| What | Limit | When exceeded |
|---|---|---|
| request body | aiMaxRequest, 2,000,000 bytes by default | HTTP 413 “The request is too large.” |
| text for an action | 60,000 characters | “The text is too long for the AI function.” |
| your own prompt | 2,000 characters | the request is refused |
| document context sent with “Continue writing”, your own prompt and in an empty paragraph | 8,000 characters (for “Continue writing”: the text up to the paragraph or selection) | shortened |
| text before the caret for autocomplete | the last 3,000 characters | earlier text is not sent |
aiContext | 6,000 characters | shortened |
| AI chat | a question up to 4,000 characters (the field limit); the last 20 messages; the first 55,000 characters of the document HTML | older messages are not sent |
| image for alt text | 1.5 MB, data:image/jpeg, png or webp only | “The image could not be read.” |
Entries of aiActions need an id matching ^[a-z0-9_-]{1,40}$ and a non-empty label and prompt; the label is cut to 80 characters and the prompt to 4,000. Invalid entries are skipped without an error, and with a repeated id the last entry wins.
Endpoint protocol
You need this only for your own endpoint in another language; the PHP classes and the integrations implement it. The editor sends POST with JSON { "action": "…", "data": { … } } and the X-CSRF-Token header; streamed actions add "stream": true.
| Action | Paid | Answer |
|---|---|---|
status | no | { "ai": true, "version": "1.0.0" } (ai: the API key of the chosen model’s provider is configured) |
config | no | { "features": [...], "actions": [{ "id", "label" }] } for the current user |
transform, chat | yes | JSON, or a stream with "stream": true |
review, metadata, describeImage, complete | yes | JSON |
Errors are JSON { "error": "…", "params": { … }, "stop": true }. error is an English message that the editor translates, params fills its {placeholders}, and stop: true means that trying again will not help (for example an invalid API key or no credit).
| HTTP | When |
|---|---|
| 400 | unknown action, invalid data, or an error reported by the provider |
| 403 | invalid CSRF token, no AI edition licence, or a function not allowed by aiFeatures |
| 405 | not a POST request |
| 413 | request body over aiMaxRequest |
| 429 | refused by aiBeforeRequest |
| 500 | server error, for example an unknown aiProvider (details in the PHP error log) |
A stream is text/event-stream with lines data: {json}: first { "delta": "…" } with raw text, then { "done": true, "html": "…" } with the HTML sanitized on the server, or { "error": … }. The HTTP status of a stream is always 200; errors arrive as events.
Streaming behind a proxy
Streamed responses use text/event-stream. AiApi::sendStream() sends X-Accel-Buffering: no for nginx and disables mod_deflate on Apache with mod_php. If you put a CDN or another proxy in front, disable response buffering for the AI endpoint.
Something unclear? Send feedback on the documentation.