fix: update image models, handle upstream errors in HTTP 200

Three issues found in activity logs:

1. Image model IDs stale — FLUX and Seedream removed from OpenRouter.
   Updated to current models: Gemini 2.5/3.1 Flash Image, Gemini 3 Pro
   Image, GPT-5 Image/Mini. Default changed to gemini-2.5-flash-image.

2. openrouter/free router wraps upstream 429 errors in HTTP 200 body
   with error object. Both text and image response parsers now detect
   this pattern and surface a proper RuntimeException.

3. Image request used modalities: ["image"] but Gemini needs
   ["image", "text"]. Updated to include both.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-18 10:47:05 +07:00
parent cf3d97c0c3
commit 862d7e40e6
6 changed files with 63 additions and 45 deletions

View File

@@ -50,6 +50,21 @@ class PRAutoBlogger_OpenRouter_Response_Parser {
* @throws \RuntimeException If response structure is invalid.
*/
public function parse_success( array $data, string $model ): array {
// OpenRouter routers (e.g. openrouter/free) may wrap upstream provider
// errors inside an HTTP 200 body with an `error` object. Surface them
// as RuntimeExceptions so the retry loop or caller can handle them.
if ( isset( $data['error']['message'] ) ) {
$upstream_code = (int) ( $data['error']['code'] ?? 0 );
throw new \RuntimeException(
sprintf(
/* translators: %1$d: upstream HTTP code, %2$s: error message */
__( 'OpenRouter upstream error (code %1$d): %2$s', 'prautoblogger' ),
$upstream_code,
$data['error']['message']
)
);
}
// Validate we have a choices array with at least one message.
if ( ! isset( $data['choices'][0]['message'] ) ) {
// Log the raw shape so we can diagnose what the model actually returned.