Connecting WordPress to NordRouter
Execute the request on the PHP server. Never put a key in the site's JavaScript.
In wp-config.php:
php
define('NORDROUTER_API_KEY', 'sk-nr-ВАШ-КЛЮЧ');In your own plugin or child theme:
php
$response = wp_remote_post('https://nordrouter.com/v1/chat/completions', [
'timeout' => 60,
'headers' => [
'Authorization' => 'Bearer ' . NORDROUTER_API_KEY,
'Content-Type' => 'application/json',
],
'body' => wp_json_encode([
'model' => 'anthropic/claude-sonnet-4.6',
'messages' => [['role' => 'user', 'content' => 'Напиши описание']],
]),
]);Check is_wp_error($response) and HTTP code before parsing JSON. Do not edit the working theme directly: the update will overwrite the changes.