WP Manifestindependent plugin directory
manifest / unclassified / zactonz-ai-connector-for-openrouter

Zactonz AI Connector for OpenRouter

OpenRouter connector for the WordPress AI Client. Adds OpenRouter to Settings → Connectors so anything built on wp_ai_client_prompt() can reach hundreds of models behind one API key, with capabilities read from the OpenRouter catalogue rather than guessed.

by Zactonz Technologies · github.com/zactonz/zactonz-ai-connector-for-openrouter · website

★ 0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/zactonz/zactonz-ai-connector-for-openrouter/archive/refs/heads/main.zip

Adds an OpenRouter connector to Settings > Connectors for the WordPress AI Client, with access to hundreds of routed models.

OpenRouter is a routing gateway that exposes hundreds of models from dozens of labs behind one OpenAI-compatible API and one bill. This connector brings that catalogue into WordPress: every model your key can reach is discovered automatically, with vision, tool calling, and structured output detected per model from the OpenRouter catalogue rather than guessed.

WordPress 7.0 introduced the AI Client and a Settings > Connectors screen where every provider's credentials live in one place. Core ships OpenAI, Anthropic and Google. This plugin adds OpenRouter to that same screen, so anything built on wp_ai_client_prompt() can use it without knowing anything about this plugin.

Version 1.0.0 · Developer: Zactonz Technologies

Documentation: developers.zactonz.com · Releases · Report an issue

OpenRouter is a third-party service. This plugin is developed by Zactonz Technologies and is not affiliated with, endorsed by or sponsored by its owner. OpenRouter is a trademark of OpenRouter, Inc.

Requirements

  • WordPress 7.0 or higher
  • PHP 7.4 or higher
  • An OpenRouter account and API key

Installation

  1. Copy this directory to wp-content/plugins/zactonz-ai-connector-for-openrouter/.
  2. Activate Zactonz AI Connector for OpenRouter from the Plugins screen.
  3. Add the credentials on Settings > Connectors, or on Settings > OpenRouter.

Credentials

You can supply the API key in three ways. They are checked in this order, and the first one found wins:

  1. A PHP constant, defined before WordPress loads — normally in wp-config.php:

    define( 'OPENROUTER_API_KEY', 'your-api-key' );
  2. An environment variable of the same name:

    export OPENROUTER_API_KEY="your-api-key"
  3. The admin field on Settings > Connectors, stored in its own option and never rendered back into the page.

When a constant or environment variable is set, the admin field is disabled and labelled as overridden, so nobody edits a value that cannot take effect. This is the recommended setup for version-controlled or multi-environment sites: the key stays out of the database and out of any export of it.

Get a key at openrouter.ai.

Usage

Once the connector is configured, use it through the WordPress AI Client by provider ID. Nothing in your code needs to reference this plugin:

$text = wp_ai_client_prompt( 'Write a short WordPress release note.' )
    ->using_provider( 'openrouter' )
    ->generate_text();

To pin a specific model rather than the configured default:

use Zactonz\AiConnectorForOpenRouter\Provider\OpenRouterProvider;

$model  = OpenRouterProvider::model( 'your-model-id' );
$result = $model->generateTextResult(
    array( new UserMessage( array( new MessagePart( 'Write a release note.' ) ) ) )
);

Streaming

The AI Client has no provider-neutral streaming contract yet, so the text model exposes generateStreamResult(). Each event has a type of content_delta, thinking_delta, tool_call_delta or done. Return false from the callback to stop and receive the partial result.

use WordPress\AiClient\Messages\DTO\MessagePart;
use WordPress\AiClient\Messages\DTO\UserMessage;
use Zactonz\AiConnectorForOpenRouter\Provider\OpenRouterProvider;

$model  = OpenRouterProvider::model( 'your-model-id' );
$result = $model->generateStreamResult(
    array( new UserMessage( array( new MessagePart( 'Write a release note.' ) ) ) ),
    static function ( array $event ) {
        if ( 'content_delta' === $event['type'] ) {
            echo esc_html( $event['delta'] );
            flush();
        }
    }
);

Streaming is an ordinary wp_remote_post(). The body arrives through the requests-request.progress action that WordPress has bridged from the Requests library since 4.7, so there is no cURL call anywhere in this plugin. Where a host has no transport that delivers incrementally, the whole response is replayed through the same parser: every event still arrives, just at once.

Configuration

Setting Purpose
API key The credential sent with every request. Stored in its own option and never rendered back.
Default models One default per capability: text, and whichever of vision, images, embeddings and tool calling this provider supports.
Reasoning effort Applied to the default text model when the model reports reasoning support.
API base URL Overrides the default endpoint for a proxy or private gateway.
Timeouts Separate request windows for text, embeddings and images.

Model discovery

Models are listed from the OpenRouter catalogue your API key can reach.

Capabilities are read from the provider's own model listing rather than guessed. A model is advertised as vision, tool-calling, structured-output or embedding capable only when the provider reports it, which keeps the WordPress model picker honest.

Diagnostics

Settings > OpenRouter has a diagnostics button reporting the endpoint, HTTP status, latency, number of discovered models, any configured defaults missing from the current model list, and the AI Client version. Credentials never appear in the report. The same check is registered as a WordPress Site Health test.

Development

composer install
composer lint

composer lint runs PHP_CodeSniffer against the WordPress standards, PHPStan at level 6, and the PHPUnit suite.

Changelog

See CHANGELOG.md.

Security

See SECURITY.md for how to report a vulnerability.

License

GPL-2.0-or-later. See LICENSE.