getRequestAuthentication(); if ($auth instanceof \WordPress\AiClient\Providers\Http\DTO\ApiKeyRequestAuthentication) { $apiKeyOpt = $auth->getApiKey(); $parts = explode('|', $apiKeyOpt); if (count($parts) > 1) { $accountId = $parts[0]; $this->setRequestAuthentication( new \WordPress\AiClient\Providers\Http\DTO\ApiKeyRequestAuthentication($parts[1] ?? '') ); } } } catch (\Throwable $e) { // Ignore if not set } // Fallback if not in header if (empty($accountId)) { $apiKeyOpt = ''; if (class_exists('\WordPress\AiClient\AiClient')) { try { $auth = \WordPress\AiClient\AiClient::defaultRegistry()->getProviderRequestAuthentication('cloudflare'); if ($auth instanceof \WordPress\AiClient\Providers\Http\DTO\ApiKeyRequestAuthentication) { $apiKeyOpt = $auth->getApiKey(); } } catch (\Throwable $e) { // Ignore } } if (empty($apiKeyOpt) && defined('CLOUDFLARE_API_KEY')) { $apiKeyOpt = constant('CLOUDFLARE_API_KEY'); } elseif (empty($apiKeyOpt) && getenv('CLOUDFLARE_API_KEY')) { $apiKeyOpt = getenv('CLOUDFLARE_API_KEY'); } $parts = explode('|', $apiKeyOpt); $accountId = $parts[0] ?? ''; } $url = 'https://api.cloudflare.com/client/v4/accounts/' . $accountId . '/ai/v1/' . ltrim($path, '/'); return new Request( $method, $url, $headers, $data, $this->getRequestOptions() ); } }