Skip to content

Fix[Image Generation]: Detect support for connectors that authenticate without an API key (e.g. OAuth)#748

Open
diarmuidie wants to merge 5 commits into
WordPress:developfrom
diarmuidie:fix/image-gen-oauth-connectors
Open

Fix[Image Generation]: Detect support for connectors that authenticate without an API key (e.g. OAuth)#748
diarmuidie wants to merge 5 commits into
WordPress:developfrom
diarmuidie:fix/image-gen-oauth-connectors

Conversation

@diarmuidie

@diarmuidie diarmuidie commented Jun 19, 2026

Copy link
Copy Markdown

What?

Follow up to #679.

has_image_generation_support() skipped connectors that authenticate without an API key (e.g. OAuth) because it only checked for API-key credentials. It now exposes a wpai_has_image_generation_support filter so those connectors can advertise support — without making any live API requests.

Why?

#679 gates the image generation UI on has_image_generation_support(). That check relied solely on has_connector_authentication(), which by design only detects API-key credentials (environment variable, constant, or stored option).

As a result, a provider that is fully configured but authenticates via OAuth was never counted as supporting image generation, and the image generation UI stayed hidden even though the provider exposes an image-generation-capable model.

This mirrors how AI credential detection already lets connectors that do not rely on API key settings advertise availability through a filter (wpai_has_ai_credentials).

How?

The connector loop still only inspects connectors that have API-key credentials, which is a request-free check. Connectors that authenticate without an API key now advertise support through a new wpai_has_image_generation_support filter, applied to the computed result:

$result = (bool) apply_filters( 'wpai_has_image_generation_support', $has_support, $connectors );

This deliberately avoids is_connector_configured() / isProviderConfigured(), which issues a live API request to verify the connection. has_image_generation_support() runs on nearly every admin page load, so it must stay request-free.

A $reset_cache parameter allows the per-request memoization to be recomputed (used by the tests, and useful when connector configuration changes within a single request).

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Investigating the regression, drafting the filter-based fix, and writing the integration tests; reviewed and edited by me.

Testing Instructions

Automated: tests/Integration/Includes/HelpersTest.php covers has_image_generation_support() for the API-key path, the filter path (advertising and suppressing support), the missing-capability case, and the skip path for connectors without credentials.

Manual:

  1. Configure an AI connector that authenticates without an API key (e.g. OAuth) and exposes an image-generation-capable model, with no API key set.
  2. From the connector plugin, hook wpai_has_image_generation_support to advertise support (e.g. return true).
  3. Verify the image generation UI is now available (it was hidden before this change).
  4. Regression check: an API-key connector with image support still shows the UI; with no qualifying connectors and no filter, it stays hidden.

Changelog Entry

Fixed - Image generation is now detected for connectors that authenticate without an API key (e.g. OAuth), via the new wpai_has_image_generation_support filter.

Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: diarmuidie <diarmuidwpe@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

has_image_generation_support() skipped connectors that authenticate
without an API key (e.g. OAuth) because it only checked for API-key
credentials. Also honor connectors the registry reports as configured,
consistent with text generation credential detection.

Add integration tests covering the API-key path, the non-API-key
(configured) path, the missing-capability case, and the
unauthenticated/unconfigured skip path.
@diarmuidie diarmuidie force-pushed the fix/image-gen-oauth-connectors branch from fc4e693 to 73b28bf Compare June 19, 2026 11:45

@dkotter dkotter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a concern on the use of is_connector_configured but I'd also like more information on where you're encountering this, what AI Provider are you using? My understanding is the Connectors API in WordPress Core doesn't yet support OAuth and only supports API key authentication so trying to understand the real world use case here.

Comment thread includes/helpers.php Outdated
// covers connectors that authenticate without an API key (e.g. OAuth),
// consistent with how text generation honors connectors that do not
// rely on API key settings.
if ( ! has_connector_authentication( $connector_id ) && ! is_connector_configured( $connector_id ) ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the problem with using is_connector_configured is it uses isProviderConfigured which makes actual API requests to verify the connection. We try and stay away from using this as we don't want to make unnecessary API requests and right now, has_image_generation_support is run on basically every admin page load

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh. Good catch. I'll see if there is a better way to accomplish this...

@diarmuidie

Copy link
Copy Markdown
Author

I've left a concern on the use of is_connector_configured but I'd also like more information on where you're encountering this, what AI Provider are you using? My understanding is the Connectors API in WordPress Core doesn't yet support OAuth and only supports API key authentication so trying to understand the real world use case here.

Yes, you are correct. This is for an internal AI Gateway which uses oAuth. We handle the auth in our AI connector plugin so from the WordPress connector side it looks like a connector with authentication.method = none and as a result Image generation fails.

@dkotter

dkotter commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Yes, you are correct. This is for an internal AI Gateway which uses oAuth. We handle the auth in our AI connector plugin so from the WordPress connector side it looks like a connector with authentication.method = none and as a result Image generation fails.

So an easy approach would be to add a filter within the has_image_generation_support function so 3rd parties (in this case your internal AI Gateway) could then modify the result of that to be whatever they want (and could run whatever checks they want). We already do this in a few places, like has_ai_credentials and has_valid_ai_credentials

…nfigured

Addresses review feedback: is_connector_configured() calls isProviderConfigured(),
which issues a live API request, and has_image_generation_support() runs on nearly
every admin page load. Replace it with a request-free wpai_has_image_generation_support
filter so connectors that authenticate without an API key (e.g. OAuth) can advertise
support, mirroring the existing wpai_has_ai_credentials pattern. Update tests to cover
advertising and suppressing support through the filter.
@diarmuidie

Copy link
Copy Markdown
Author

So an easy approach would be to add a filter within the has_image_generation_support function so 3rd parties (in this case your internal AI Gateway) could then modify the result of that to be whatever they want (and could run whatever checks they want). We already do this in a few places, like has_ai_credentials and has_valid_ai_credentials

That's much nicer! @dkotter I've implemented it in a11055f

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.71%. Comparing base (27e202b) to head (41ea64b).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #748      +/-   ##
=============================================
+ Coverage      76.41%   76.71%   +0.29%     
  Complexity      1828     1828              
=============================================
  Files             87       87              
  Lines           7764     7764              
=============================================
+ Hits            5933     5956      +23     
+ Misses          1831     1808      -23     
Flag Coverage Δ
unit 76.71% <100.00%> (+0.29%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…support tests

Adds tests for the two patch lines Codecov flagged as uncovered: the memoized
cache-hit return path, and the catch/continue guard when a connector's provider
throws while listing model metadata.
Comment thread includes/helpers.php
* connectors that do not rely on API key settings (e.g. OAuth), without
* triggering a live API request.
*
* @since 1.0.3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All @since statements, both here and in the test file, should be set to x.x.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants