📄 Source: test_openrouter.php
<?php
$apiKey = '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';
$url = 'https://openrouter.ai/api/v1/chat/completions';
$data = [
'model' => 'google/gemini-2.0-flash-exp',
'messages' => [
['role' => 'user', 'content' => 'Say "Hello, API is working!"']
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "HTTP Code: $httpCode\n";
echo "Response:\n";
print_r(json_decode($response, true));
?>
← Back