| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite\AI\Providers; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* OpenRouter provider — OpenAI-compatible gateway to many models with one key. |
| 11 |
* |
| 12 |
* Reuses {@see OpenAIProvider}'s request/response mapping; only the endpoint, |
| 13 |
* auth headers and model list differ. OpenRouter does not offer a unified image |
| 14 |
* endpoint here, so image generation is disabled. |
| 15 |
*/ |
| 16 |
class OpenRouterProvider extends OpenAIProvider { |
| 17 |
|
| 18 |
public function get_id(): string { |
| 19 |
return 'openrouter'; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_label(): string { |
| 23 |
return 'OpenRouter'; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_models(): array { |
| 27 |
return [ |
| 28 |
'openai/gpt-4o', |
| 29 |
'anthropic/claude-sonnet-5', |
| 30 |
'google/gemini-2.5-pro', |
| 31 |
'meta-llama/llama-3.3-70b-instruct', |
| 32 |
]; |
| 33 |
} |
| 34 |
|
| 35 |
public function supports_images(): bool { |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
public function generate_image( string $prompt, array $options = [] ): array { |
| 40 |
return [ 'error' => __( 'Image generation is not available via OpenRouter in this plugin.', 'better-payment' ) ]; |
| 41 |
} |
| 42 |
|
| 43 |
protected function chat_endpoint(): string { |
| 44 |
return 'https://openrouter.ai/api/v1/chat/completions'; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* @return array<string, string> |
| 49 |
*/ |
| 50 |
protected function auth_headers(): array { |
| 51 |
return [ |
| 52 |
'Authorization' => 'Bearer ' . sanitize_text_field( (string) $this->config['api_key'] ), |
| 53 |
// Optional attribution headers recommended by OpenRouter. |
| 54 |
'HTTP-Referer' => home_url(), |
| 55 |
'X-Title' => 'Better Payment', |
| 56 |
]; |
| 57 |
} |
| 58 |
} |
| 59 |
|