OpenRouter Connector is a WordPress 7.0 plugin that connects OpenRouter via the Connectors API and makes it available as a provider in WP AI Client. After installation and entering an API key, any functions and plugins that use WordPress’s standard AI API can access 200+ AI models through a single provider.
What it is and why it matters
OpenRouter Connector for WordPress adds OpenRouter as an AI provider in WordPress 7.0 using the standard Connectors API. Once configured, anything built on WP AI Client can use OpenRouter’s model catalog (GPT, Claude, Gemini, Mistral, LLaMA, and more) without changing application code.
The plugin stays minimal: no extra UI, no duplicated features. It only registers the provider and stores credentials securely.
Architectural foundation: the WordPress AI plugin
The AI plugin (wordpress.org/plugins/ai) is an official experimental plugin from the WordPress.org team. It implements user-facing AI features on top of WP AI Client. Those features become available once OpenRouter is connected.
Current features of the AI plugin
- Title generation: a “Generate” button above the post title field that suggests options in a modal
- Excerpt generation: one-click generation from the editor sidebar
- Content summarization: generates a summary of long posts and saves it as an AI Summary block
- Alt text generation: creates descriptive alt text for images (Image block and Media Library)
- Image generation: generates images from prompts in the editor or Media Library
- Image editing: prompt-based edits (background replacement, object removal, stylization)
- Review Notes: block-by-block feedback on readability, grammar, SEO, and accessibility
- Abilities Explorer: an admin screen to browse, test, and learn registered AI abilities
Experiment Framework
All features run through the Experiments system. Each feature can be enabled or disabled independently in Settings → AI. This is opt-in: nothing runs without explicit user consent.
How it works: the WordPress 7.0 AI API
Connectors API
WordPress 7.0 introduced a standard mechanism for connecting external services: the Connectors API. Each connector is a registered provider with metadata (name, logo, auth method, and a link to obtain an API key).
OpenRouter Connector registers itself via wp_connectors_init:
add_action('wp_connectors_init', function(WP_Connector_Registry $registry) {
$registry->register('openrouter', [
'name' => 'OpenRouter',
'description' => 'Access 200+ AI models through a single OpenAI-compatible API.',
'type' => 'ai_provider',
'logo_url' => plugin_dir_url(__FILE__) . 'assets/openrouter-logo.svg',
'authentication' => [
'method' => 'api_key',
'credentials_url' => '<https://openrouter.ai/keys>',
'setting_name' => 'connectors_ai_openrouter_api_key',
],
'plugin' => [
'slug' => 'ai-connector-openrouter-wordpress',
],
]);
});
After registration, the provider appears under Settings → Connectors as a card with an API key field and a link to obtain a key at openrouter.ai.
API key source priority
WordPress 7.0 checks the API key in this order:
- Environment variable:
OPENROUTER_API_KEY - PHP constant:
define('OPENROUTER_API_KEY', 'sk-...') - Database (set via the UI in
Settings → Connectors)
WP AI Client: the developer entry point
Once the provider is configured, any plugin can access AI via a single fluent API:
$text = wp_ai_client_prompt('Write an SEO description for a post about WordPress 7.0.')
->using_temperature(0.7)
->generate_text();
if (is_wp_error($text)) {
return;
}
echo wp_kses_post($text);
Use cases with code examples
1. Generate SEO meta descriptions
add_action('save_post', function(int $post_id, WP_Post $post) {
if (wp_is_post_revision($post_id) || !current_user_can('edit_post', $post_id)) {
return;
}
$builder = wp_ai_client_prompt(
sprintf('Write an SEO meta description (max 160 chars) for this post: %s', $post->post_title)
)->using_max_tokens(100)->using_temperature(0.5);
if (!$builder->is_supported_for_text_generation()) {
return;
}
$meta = $builder->generate_text();
if (!is_wp_error($meta)) {
update_post_meta($post_id, '_seo_meta_description', sanitize_text_field($meta));
}
}, 10, 2);
2. REST API endpoint with AI generation
add_action('rest_api_init', function() {
register_rest_route('my-plugin/v1', '/summarize', [
'methods' => 'POST',
'callback' => 'my_plugin_summarize_callback',
'permission_callback' => fn() => current_user_can('edit_posts'),
'args' => [
'content' => ['required' => true, 'type' => 'string'],
],
]);
});
function my_plugin_summarize_callback(WP_REST_Request $request): WP_REST_Response|WP_Error {
$result = wp_ai_client_prompt(
sprintf('Summarize in 3 bullet points: %s', $request->get_param('content'))
)
->using_model_preference('claude-sonnet-4-6', 'gpt-5.4', 'gemini-3.1-pro-preview')
->using_temperature(0.3)
->generate_text_result();
return rest_ensure_response($result);
}
3. Multimodal output: text + image
use WordPress\\AiClient\\Messages\\Enums\\ModalityEnum;
$result = wp_ai_client_prompt(
'Create a chocolate cake recipe with step-by-step illustrations.'
)
->as_output_modalities(ModalityEnum::text(), ModalityEnum::image())
->generate_result();
if (!is_wp_error($result)) {
foreach ($result->toMessage()->getParts() as $part) {
if ($part->isText()) {
echo wp_kses_post($part->getText());
} elseif ($part->isFile() && $part->getFile()->isImage()) {
echo '<img src="' . esc_url($part->getFile()->getDataUri()) . '">';
}
}
}
4. Capability checks before showing UI
function my_plugin_show_ai_button(): void {
$builder = wp_ai_client_prompt('test')->using_temperature(0.7);
if (!$builder->is_supported_for_text_generation()) {
echo '<p>Configure an AI provider in Settings → Connectors.</p>';
return;
}
echo '<button class="js-generate-ai">✨ Generate with AI</button>';
}
5. Structured JSON output
$schema = [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'tag' => ['type' => 'string'],
'relevance' => ['type' => 'number'],
],
'required' => ['tag', 'relevance'],
],
];
$json = wp_ai_client_prompt(
sprintf('Suggest 5 relevant tags for this post: %s', get_the_title())
)
->as_json_response($schema)
->generate_text();
if (!is_wp_error($json)) {
$tags = json_decode($json, true);
}
Key features of the stack
Automatic provider discovery. Once registered in the WP AI Client registry, the connector is discovered automatically and appears in Settings → Connectors.
200+ models with one key. OpenRouter aggregates GPT, Claude, Gemini, Mistral, LLaMA, Qwen, and many other models behind an OpenAI-compatible API. Developers can set preferences via using_model_preference(), and WordPress picks the first available model.
Environment-first configuration. In production, you can set OPENROUTER_API_KEY via server config or .env so the key is not stored in the database.
Capability checks without API calls. is_supported_for_*() methods are deterministic and do not contact OpenRouter. This makes it safe to hide AI UI when the provider is not configured.
REST-friendly results. GenerativeAiResult serializes through rest_ensure_response(), so you don’t need custom response formatting.
Summary
OpenRouter Connector is a minimal provider plugin. It uses WordPress 7.0 standards (Connectors API + WP AI Client) to connect OpenRouter and its model catalog.
For users: one API key unlocks the AI plugin features (titles, excerpts, images, alt text, Review Notes) and model choice (Claude, GPT, Gemini, and more).
For developers: wp_ai_client_prompt() works with OpenRouter the same way it works with Anthopic, Google, or OpenAI providers. Your code stays the same; only the provider changes.
With an integrated AI Client, WordPress 7.0 turns “AI providers” into a standard connector category. OpenRouter Connector is a reference implementation of that integration.



