Setup

Setting Up the PHP AI Client SDK and Provider Plugins

⏱ 14 min

wp_ai_client_prompt() doesn’t call anything by itself. It’s a thin, well-designed front door, and behind that door has to be at least one configured provider plugin with a real, working API key. This lesson is the plumbing that everything else in this course depends on: getting one provider plugin installed, getting a genuine key from that provider’s dashboard, and confirming WordPress can actually reach it before you write a single line of feature code.

What you'll learn in this lesson
The three official provider plugins
AI Provider for Anthropic, AI Provider for OpenAI, and AI Provider for Google, and what each one actually installs.
Getting a real API key
Where to generate one on Anthropic, OpenAI, or Google's own developer consoles.
Connecting the key to WordPress
Where the provider plugin's settings screen expects it.
Confirming the connection actually works
A WP-CLI check that proves the round trip, not just that the plugin is active.
Prerequisites

WordPress 7.0 or later, and admin access to install plugins. You’ll also need a payment method on file with whichever provider you pick, Anthropic, OpenAI, and Google all bill API usage separately from any consumer subscription you might already have with them.

Step 1: Pick a provider plugin

WordPress 7.0 ships three official provider plugins in the plugin directory, each one a thin adapter connecting the core AI Client to a single vendor’s API:

The three official providers
1
AI Provider for Anthropic
Connects to Claude models (claude-sonnet-4-5 and similar).
2
AI Provider for OpenAI
Connects to GPT models (gpt-5.1 and similar).
3
AI Provider for Google
Connects to Gemini models (gemini-3-pro-preview and similar).

You only need one to get started, and this course’s model preference examples in later lessons are written so the same code keeps working no matter which one (or how many) you install. If you’re not sure which to pick, cost and rate limits matter more than brand loyalty here: check each vendor’s current pricing page before committing, since per-token rates and free-tier limits change more often than this lesson does.

Install and activate your chosen plugin the normal way, from Plugins > Add New in wp-admin, or with WP-CLI:

# File: terminal
wp-env run cli wp plugin install ai-provider-anthropic --activate

Adjust the slug for whichever provider you picked. If you’re not on wp-env, drop the wp-env run cli prefix and run wp directly against your site.

Step 2: Get a real API key from the provider

Each provider issues API keys from its own developer console, entirely separate from WordPress:

  • Anthropic: console.anthropic.com, under API Keys. New accounts typically need to add billing details before a key will actually authenticate requests.
  • OpenAI: platform.openai.com, under API Keys. Same story, a key exists the moment you create it, but requests fail until billing is set up.
  • Google: aistudio.google.com or console.cloud.google.com depending on which Gemini access path you’re using, under API Keys or Credentials.

Copy the key somewhere temporary and safe the moment it’s generated. All three providers show the full key exactly once, at creation time, and every conversation around it afterward only ever shows a masked prefix like sk-ant-... or sk-proj-.... If you lose it before pasting it into WordPress, you’ll need to revoke it and generate a new one, there’s no “reveal” option later.

A key existing isn't the same as a key working

It’s easy to generate a key, paste it into WordPress, and assume you’re done. Providers commonly reject requests from freshly created keys until a payment method is attached and, in Google’s case, until the right API is enabled on the underlying cloud project. Don’t debug your plugin code first if generate_text() fails right after setup, check the provider’s own dashboard for a billing or API-enablement warning.

Step 3: Paste the key into the provider plugin’s settings

Each official provider plugin adds its own settings screen, typically under Settings > AI Provider for Anthropic (or OpenAI, or Google) once activated. Paste the key into the single field it asks for and save.

This is also the point where the plugin usually offers a “test connection” button. Use it, it calls the provider with a trivial request and reports success or failure right there in wp-admin, before you’ve written any of your own code that could also be wrong.

Test it: confirm WordPress can reach the provider

With the plugin active and the key saved, run a real prompt from the command line:

wp-env run cli wp eval 'echo wp_ai_client_prompt( "Reply with exactly the word: connected" )->generate_text();'

A working setup prints:

connected

If instead you get a fatal error, a blank line, or an obviously generic error string, work through it in this order: is the provider plugin actually active (wp plugin list), is the key saved in that plugin’s settings screen (not some other settings screen), and does the provider’s own dashboard show any billing or verification warning against that key.

Recap

wp_ai_client_prompt() needs a real, configured provider behind it before any of this course’s code does anything. Pick one of the three official provider plugins, generate a genuine API key from that vendor’s own developer console (with billing attached), and paste it into the plugin’s settings screen. The one-line wp eval check above is the fastest way to confirm the whole chain, plugin, key, and network access, actually works before you build anything on top of it.

Resources & further reading

Managing API Keys Across Multiple Providers →