| Server IP : 5.129.245.98 / Your IP : 216.73.217.19 Web Server : Apache/2.4.66 (Debian) System : Linux 1b8c17c336b9 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/plugins/content-egg/application/components/ai/ |
Upload File : |
<?php
namespace ContentEgg\application\components\ai;;
defined('\ABSPATH') || exit;
/**
* ClaudeClient class file
*
* @author keywordrush.com <support@keywordrush.com>
* @link https://www.keywordrush.com
* @copyright Copyright © 2025 keywordrush.com
*/
class ClaudeClient extends AiClient
{
const API_VERSION = '2023-06-01';
const MAX_TOKENS = 4096;
public function getChatUrl()
{
return 'https://api.anthropic.com/v1/messages';
}
public function getHeaders()
{
return array(
'Content-Type: application/json',
'x-api-key:' . $this->api_key,
'anthropic-version: ' . self::API_VERSION,
);
}
public function getPayload($prompt, $system = '', $params = array())
{
$payload = $messages = array();
if ($system)
$payload['system'] = $system;
$message = array(
'role' => 'user',
'content' => $prompt,
);
$messages[] = $message;
$payload['messages'] = $messages;
$payload['max_tokens'] = self::MAX_TOKENS;
$payload = array_merge($params, $payload);
return $payload;
}
public function getContent($response)
{
if (!$data = json_decode($response, true))
throw new \Exception('Invalid JSON formatting.');
if (!isset($data['content'][0]['text']))
throw new \Exception('No content in the claude response.');
$content = $data['content'][0]['text'];
if (isset($data['usage']))
$this->last_usage = $data['usage'];
else
$this->last_usage = array();
return $content;
}
}