PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.3.4
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.3.4
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 66 releases
better-payment / includes / AI / Providers / OpenRouterProvider.php

OpenRouterProvider.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.3.4, at includes/AI/Providers/OpenRouterProvider.php

59 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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