PHP code example of level7up / openrouter-client

1. Go to this page and download the library: Download level7up/openrouter-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/ */

    

level7up / openrouter-client example snippets


use Level7up\OpenRouter\OpenRouterClient;

class ChatController extends Controller
{
    public function ask(OpenRouterClient $client)
    {
        $response = $client->getCompletion('Tell me a joke.', 50);
        return response()->json(['reply' => $response]);
    }
}

return [
    'api_key'    => env('OPENROUTER_API_KEY'),
    'base_url'   => env('OPENROUTER_BASE_URL', 'https://openrouter.ai/api/v1'),
    'referer'    => env('OPENROUTER_REFERER'),
    'site_title' => env('OPENROUTER_SITE_TITLE'),
];
bash
php artisan vendor:publish --tag=config