PHP code example of cheinisch / openrouter-php-client
1. Go to this page and download the library: Download cheinisch/openrouter-php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cheinisch / openrouter-php-client example snippets
echo OpenRouterClient::OpenRouterChat(
$apiKey,
'mistralai/mistral-small',
'Give me one short fun fact about PHP.',
'https://my-app.com', // optional – HTTP-Referer
'My App' // optional – X-Title
);
$client = new OpenRouterClient($apiKey);
$answer = $client->chat(
[['role' => 'user', 'content' => 'What is the capital of France?']],
'openai/gpt-4o-mini'
);
echo $answer; // plain string