---
title: How to Use the WordPress AI Client
description: WordPress 7.0 introduces the WP AI Client, a provider-agnostic API for seamless integration of AI models like OpenAI and Google into your site.
doc_version: current
last_updated: '2026-04-06T18:29:09.000Z'
date: '2026-02-26T10:39:48.000Z'
author: Rich Tabor
summary: WordPress 7.0 introduces the WP AI Client, a provider-agnostic API for seamless integration of AI models like OpenAI and Google into your site.
tags:
  - AI
  - WordPress
published: true
type: blog
url: /wordpress-ai-client
canonical: https://richtabor.com/wordpress-ai-client
id: 7632
---

The upcoming release of WordPress 7.0 ships with the new [WP AI Client](https://make.wordpress.org/core/2026/02/03/proposal-for-merging-wp-ai-client-into-wordpress-7-0/). You will be able to can call any AI model (Anthropic, Google, OpenAI, others) through a single API, in PHP directly and from JavaScript using the [Abilities API](https://developer.wordpress.org/news/2025/11/introducing-the-wordpress-abilities-api/).

![Black and white engraving-style illustration of a spiral galaxy with tiny human figures standing on rocky terrain below, gazing upward.](https://i0.wp.com/rich.blog/wp-content/uploads/2026/02/Halftone-CMYK%402x.png?ssl=1&resize=1024%2C768)

WP AI Client is infrastructure.

It doesn’t ship any [providers](/wordpress-ai-providers) or make any AI calls by default. It’s only the plumbing that your plugin can build on. If you don’t want to use AI with your website, it’s all good.

Let’s look at what it is, then build something with it.

## Why core

Today, any AI-powered WordPress plugin ships its own API wrapper, own settings page for credentials, and own provider logic. If you install three plugins that use AI, you’ll end up configuring three separate API keys for the same provider. And if said provider changes their API for any reason, all three plugins break independently.

The WP AI Client fixes this the same way WordPress fixed database access with `$wpdb` or HTTP requests with `wp_remote_post()`, with one shared layer.

Configure once, use everywhere.

## How it works

The [WP AI Client](https://make.wordpress.org/core/2026/02/03/proposal-for-merging-wp-ai-client-into-wordpress-7-0/) is a provider-agnostic API for calling generative AI models.

It sits on top of the [PHP AI Client](https://github.com/WordPress/php-ai-client), adapted for WordPress conventions: WP HTTP transport, `WP_Error` handling, provider credential discovery from environment variables/constants, and an Abilities/REST-backed JavaScript path for browser contexts.

To try it out today, you’ll need WordPress 7.0 (currently in beta) and at least one [provider](/wordpress-ai-providers).

There are currently providers for [Anthropic](https://wordpress.org/plugins/ai-provider-for-anthropic/), [Google](https://wordpress.org/plugins/ai-provider-for-google/), and [OpenAI](https://wordpress.org/plugins/ai-provider-for-openai/) are on WordPress.org, with others already showing up, like [Grok](https://github.com/aslamdoctor/ai-provider-for-grok) and [OpenRouter](https://github.com/jonathanbossenger/wp-openrouter-provider). Install one and define your API key (e.g. `ANTHROPIC_API_KEY`) to run abilities.

It’s heavy and manual in the current beta, but there’s an [admin page](https://github.com/WordPress/gutenberg/pull/75833) in the works that will make it easier to add and configure providers.

The plugins we write never touch credentials or provider logic. We just write the prompts and functions while the client handles the rest, like this:

In PHP:

```
$text = wp_ai_client_prompt( 'Summarize this post.' )
    ->using_system_instruction( 'You write concise summaries. Return plain text only.' )
    ->generate_text();
```

In JavaScript (via abilities):

```
import '@wordpress/core-abilities';
import { executeAbility } from '@wordpress/abilities';

const result = await executeAbility(
    'ai-content-helpers/generate-excerpt',
    { post_id: 123 }
);
```

We can also check whether a provider is configured before rendering an AI feature, so plugins degrade gracefully:

```
if ( function_exists( 'wp_ai_client_prompt' ) ) {
    // Show the AI feature.
} else {
    // Show setup instructions.
}
```

And notably, REST/JavaScript execution permissions are controlled per ability via each ability’s `permission_callback`.

Now let’s see this in practice.

## Example: Auto-generating alt text

I built a companion plugin to this post called [WP AI Content Kit](https://github.com/richtabor/wp-ai-content-kit) to serve as an example. It’s a working plugin that you can install, test, look at the code, and learn more, without overcomplicating things.

This first example is a feature that auto-generates alternative text for images as you upload them, or manually for older media.

The `using_system_instruction()` method sets the role and rules, the prompt is the actual task, and `with_file()` attaches the image so the model can see it.

```
$image_file = get_attached_file( $attachment_id );
$mime_type  = get_post_mime_type( $attachment_id );

$alt_text = wp_ai_client_prompt( 'Generate alt text for this image.' )
    ->using_system_instruction(
        'You are an accessibility expert that generates alt text for website images. '
        . 'Keep it under 125 characters. Describe visible content objectively. '
        . 'Do not start with "Image of" or "Photo of". Return plain text only.'
    )
    ->with_file( $image_file, $mime_type )
    ->using_model_preference( 'claude-sonnet-4-6', 'gpt-5.1' )
    ->generate_text();
```

The `using_model_preference()` method sets preferred models in priority order, falling back to automatic selection if none are available.

## Example: Auto-generating excerpts

Today WordPress will take the first 50 or so words from a post and call it an excerpt. But what if excerpts actually summarized the post? In this example I’m showing how to leverage the `as_json_response()` method, which tells the model to return structured JSON matching a schema I’ve defined.

This way you get a predictable object instead of free-form text you’d have to parse:

```
$content = wp_strip_all_tags( $post->post_content );

$schema = array(
    'type'       => 'object',
    'properties' => array(
        'excerpt' => array(
            'type'        => 'string',
            'description' => 'A 1-2 sentence summary of the post.',
        ),
    ),
    'required'   => array( 'excerpt' ),
);

$json = wp_ai_client_prompt( "Write an excerpt for this post:\n\n" . $content )
    ->using_system_instruction(
        'You generate post excerpts for WordPress. '
        . 'Write 1-2 sentences. Be specific about what the content covers. '
        . 'Preserve the source tone. Avoid generic filler and cliches.'
    )
    ->as_json_response( $schema )
    ->generate_text();
```

## Going deeper

Do check out [WP AI Content Kit](https://github.com/richtabor/wp-ai-content-kit) on GitHub, and if you want to see these APIs used at a bigger scale, the [AI Experiments plugin](https://github.com/WordPress/ai) goes deeper with more abilities.

WordPress 7.0 Beta 1 is out, and there’s no better time to start building AI into your plugins. The full release is scheduled for [April 9](https://wordpress.org/news/2026/02/wordpress-7-0-beta-1/), coinciding with WordCamp Asia (I’ll be there!).

So what will you build with it?

## Sitemap

[Full site index](/sitemap.md)
