Built-In BYOK AI Agent: Setup, Multi-Provider Vault, 3-Viewport Lab & Custom CSS
Step-by-step illustrated guide to connecting OpenAI, Claude, Gemini, or OpenRouter keys inside WP Admin -> KadiCache -> AI Agent, inspecting live tool traces, verifying 3-viewport CSS drafts, and rolling back changes in 1 click.
- Prerequisites: Active KadiCache Cloud Pro pairing (
WP Admin -> KadiCache -> Cloud Connection) + your own API key from OpenAI, Anthropic Claude, Google Gemini, or OpenRouter. - Zero Proxy & Encrypted Vault: Keys are encrypted at rest with
SecretBox(libsodium/ AES-256-GCM) inAiKeyVault.php; all LLM traffic travels directly from WordPress to strictly allowlisted provider endpoints viawp_safe_remote_post. - Safe Tool Execution: Read-only diagnostics (
get_status,diagnose_url,get_settings,get_rum_analytics,inspect_page_dom,run_pagespeed_audit,simulate_settings) run automatically with collapsible millisecond traces, while all writes pause for admin approval and create a 1-click rollback checkpoint. - 3-Viewport Custom CSS Workflow: Stage a non-live CSS draft (
stage_draft), verify Mobile (390px), Tablet (820px), and Desktop (1440px) via signed URLs (PreviewResponder.php), approve publication (publish), or roll back instantly from Chat or the Custom CSS sub-tab.
Prerequisites & Entitlement Check#
Before using AI Agent inside WordPress, confirm two requirements:
- Active KadiCache Cloud Pro Connection: Open
WP Admin -> KadiCache -> Cloud Connectionand ensure your site displaysActive Link · Cloud Pro.AiKeyVault::entitlement()checks pairing plus a cached daily subscription verification (ENTITLEMENT_TTL = 86400s). Sites running KadiCache Free Core see a read-only preview tab explaining the workflow until Cloud Pro is connected. - At Least One BYOK Provider API Key: Obtain an API key directly from OpenAI, Anthropic, Google AI Studio (Gemini), or OpenRouter. Because AI Agent is strictly BYOK, KadiCache never bills per token and never sees your prompts or keys.
Step 1: Configure Your Multi-Provider BYOK Key Vault (API & Models)#
Open WP Admin -> KadiCache -> AI Agent and click the API & Models sub-tab:
- Select a Provider Card: Choose OpenAI, Anthropic Claude, Google Gemini, or OpenRouter. You can configure multiple providers — saving a second key never overwrites keys already stored for other providers (
encrypted_keys_by_provider). - Paste Your API Key & Confirm Disclosure: Paste your key into the write-only API Key input (only the last 4 characters are kept as a visual hint such as
••••Ndqw) and check the direct-to-provider data disclosure checkbox. - Click
Test Key & Sync ModelsorSave & Open Chat:AiKeyVault::save()validates unmistakable cross-provider prefixes (sk-or-for OpenRouter,sk-ant-for Anthropic,AIza/AQ.for Gemini), encrypts the key viaSecretBox, fetches the provider's live/modelslist (AiProviderClient::fetchLiveModels()), and marks the provider card● Connected.
Step 2: Switch Active Providers & Run Guided Diagnostics in Chat#
Once at least one provider key is saved, the API setup notice disappears cleanly and the top bar displays a green ● Connected badge. Right below the header, the Active Agent strip lets you switch between your configured providers and their synced models without leaving Chat (POST /wp-json/kadicache-pro/v1/ai-settings with action: "switch_model").
You can start in three ways:
- Click One of the 6 Starter Cards: Launch targeted workflows for Fix Delay JS / Broken UI, Fix Layout Shift (CLS), Speed Up Mobile LCP, Why Is This Page MISS?, Fix Broken Images / CSS, or Full Site Speed Audit.
- Set a Target URL & Describe the Symptom: Enter any same-site path (for example
/shop/or/checkout/) in the Inspecting bar and ask a specific question. - Paste a Visual Screenshot (
Ctrl+V) or ClickScreenshot: Attach a PNG, JPEG, or WebP screenshot (up to1.2 MBafter client compression).AiProviderClient::validateImage()verifies magic bytes strictly in request memory — screenshots are never saved to disk.
Step 3: Inspect Live Tool Execution Traces & Export Reports#
During a run, AI Agent executes one LLM step or one tool call per HTTP request (POST /wp-json/kadicache-pro/v1/ai-chat/step) so shared-host PHP timeouts never interrupt long analyses. You can cancel an in-flight turn immediately with the Stop button (AbortController).
When the assistant replies:
- Expand the Collapsible Tool Trace (
▼ Used X tools · Y ms): Verify the exact read-only tools executed (such asget_status,diagnose_url,get_settings,get_rum_analytics, orinspect_page_dom) along with each tool's millisecond runtime. - Click
Copy Report: Copy the formatted markdown summary directly to your clipboard for client updates, QA tickets, or team documentation.
Read-Only Auto-Executed Tools vs Approval-Gated Actions#
| Execution Mode | Tools (AiAgentController.php) | Safety Guarantee |
|---|---|---|
| Auto-Executed Read-Only | get_status, diagnose_url, get_settings, get_preload_status, inspect_database, get_rum_analytics, get_approval_status, run_pagespeed_audit, simulate_settings, inspect_page_dom, plus read sub-actions (manage_cloudflare.get_state, manage_object_cache.get_state/probe, manage_script_manager.inspect_url/list_rules, manage_pro_cloud.status, manage_custom_css.list/stage_draft) | Zero changes to live site options, cache, or frontend HTML |
| Non-Live 3-Viewport Lab | run_viewport_lab (PreviewResponder::signedUrl()) | Renders Mobile (390px), Tablet (820px), and Desktop (1440px) against an isolated signed draft preview — never live visitors |
| Approval-Gated Writes | update_settings, optimize_site, purge_cache, manage_script_manager writes, manage_cloudflare writes, manage_object_cache writes, manage_custom_css (publish / toggle / delete) | Pauses for explicit admin click on a server-hashed approval card and creates an automatic McpCheckpoints rollback checkpoint (cp_...) |
Step 4: Verify 3-Viewport Custom CSS Fixes & Use 1-Click Rollback#
When you ask AI Agent to fix a visual overflow, overlapping button, or layout shift with CSS:
- Draft Staging (
stage_draft): AI Agent stages a sanitized, path-scoped CSS draft (for example scoped to/or/product/*, using@mediaqueries for responsive breakpoints) without affecting live traffic. - 3-Viewport Lab Verification (
run_viewport_lab): The built-in viewport runner inspects Mobile (390px), Tablet (820px), and Desktop (1440px) and returns before/after overflow, overlap, CLS, and console telemetry to the agent. - Approve & Publish (
publish): Review the proposed CSS diff and click Approve to publish. Published rules inject cleanly after Cloud Remove Unused CSS (RUCSS), serve directly from Early Cache, and appear under theCustom CSSsub-tab. - 1-Click Rollback: Click Rollback on the checkpoint card in Chat — or toggle/delete any rule anytime inside the
Custom CSSsub-tab (CustomCssStore.php), which automatically purges affected cached pages.
Troubleshooting & Error Reference#
Frequently Asked Operational Questions
Why does the Active Agent dropdown in Chat only show some of the 4 providers?
What happens if I remove a saved API key for one provider while another provider is configured?
Does KadiCache AI Agent store my pasted screenshots on my WordPress server?
How do I reset the conversation or clear token history?
Are Custom CSS rules kept if I purge my page cache?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.