Download the PHP package wordpress/wp-ai-client without Composer

On this page you can find all versions of the php package wordpress/wp-ai-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-ai-client

WordPress AI Client

Deprecated: This package is deprecated in favor of the built-in AI client in WordPress 7.0+. On 7.0+, the PHP SDK infrastructure is disabled (core handles it natively), but the REST API endpoints and JavaScript API remain active since they are not yet in core. See UPGRADE.md for migration details.

Part of the AI Building Blocks for WordPress initiative

An AI client and API for WordPress to communicate with any generative AI models of various capabilities using a uniform API.

Built on top of the PHP AI Client, adapted for the WordPress ecosystem.

Features

Note: The client-side JavaScript API and REST endpoints are by default limited to only administrators since they allow arbitrary prompts and configuration. A prompt_ai capability is used to control access, and sites are able to customize how that capability is granted to users or specific roles.

Installation

Configuration

1. Initialize the Client

You must initialize the client on the WordPress init hook. This sets up the HTTP client integration and registers the settings screen. If you are using this as a plugin, this is already handled for you in plugin.php.

2. Configure API Credentials

Before making requests, you need to configure API keys for your desired providers (e.g. Anthropic, Google, OpenAI).

  1. Go to Settings > AI Credentials in the WordPress Admin.
  2. Enter your API keys for the providers you intend to use.
  3. Save changes.

3. Load the JavaScript API (Optional)

To use the client-side JavaScript API, you need to enqueue the script.

Usage

The SDK provides a fluent Prompt_Builder interface to construct and execute AI requests.

Text Generation

PHP:

JavaScript:

Image Generation

PHP:

JavaScript:

Advanced Usage

JSON Output and Temperature

PHP:

JavaScript:

Generating Multiple Image Candidates

PHP:

JavaScript:

Multimodal Output (Text & Image)

PHP:

JavaScript:

Best Practices

Automatic Model Selection

By default, the SDK automatically chooses a suitable model based on the prompt's requirements (e.g., text vs. image) and the configured providers on the site. This makes your plugin provider-agnostic, allowing it to work on any site regardless of which AI provider the admin has configured.

Using Model Preferences

If you prefer specific models for better performance or capabilities, use using_model_preference(). The SDK will try to use the first available model from your list. If none are available (e.g., provider not configured), it falls back to automatic selection.

Pass preferences as either a model ID string, or as an array of [ provider_id, model_id ]. For broader compatibility, it is recommended to pass only the model ID string, since there can be different providers offering the same model - e.g. many AI cloud services proxy through calls to models from third party model labs. Only pass the array of provider ID and model ID if you (for whichever reason) only want to allow the model to be served from the specific provider.

PHP:

JavaScript:

Setting max tokens

Control the maximum number of tokens the AI model can generate in its response. Higher values allow for longer, more detailed outputs, while lower values help keep responses concise and reduce API costs.

PHP:

JavaScript:

Using a Specific Model

Enforcing a single specific model using using_model() restricts your feature to sites that have that specific provider configured. For most scenarios, this is unnecessarily opinionated. Only use this approach if you really only want to offer the feature in combination with that model.

PHP:

JavaScript:

Feature Detection

Before actually sending an AI prompt and getting a response, always check if the prompt is supported before execution.

This is always recommended, but especially crucial if you require the use of a specific model.

PHP:

JavaScript:

The above condition will only evaluate to true if the site has one or more providers configured with models that support text generation including a temperature configuration.

Generally, using is_supported_for_text_generation() (or is_supported_for_image_generation(), etc.) ensures you only expose AI features that can actually run on the current site configuration.

Error Handling

The wp_ai_client_prompt() function returns WP_Error on failure, following WordPress conventions.

Exception-based (advanced)

If you prefer exceptions, use AI_Client::prompt() directly.

Architecture

This library is a WordPress-specific wrapper around the PHP AI Client.

Further reading

See the Prompt_Builder class and its public methods for all the ways you can configure the prompt.

See the contributing documentation for more information on how to get involved.


All versions of wp-ai-client with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
psr/simple-cache Version ^1.0
wordpress/php-ai-client Version ^1.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wordpress/wp-ai-client contains the following files

Loading the files please wait ...