1. Go to this page and download the library: Download cable8mm/nano-ai 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/ */
cable8mm / nano-ai example snippets
use Cable8mm\NanoAI\Client;
// If API Key is omitted, it will be automatically read from the OPENAI_API_KEY / OPENROUTER_API_KEY environment variables.
$client = new Client(
provider: 'openai',
apiKey: <openai api key>,
model: <model name>
);
echo $client->generate('Hello?');
// Images: supports URL, data URI, and local file path (auto base64 conversion)
echo $client->generate('Describe this photo', imageUrl: '/path/to/photo.jpg');
$client = new Client(
provider: 'openrouter',
apiKey: <openrouter api key>,
model: 'deepseek/deepseek-chat:free', // Check the latest list at https://openrouter.ai/models?max_price=0
);
use Cable8mm\NanoAI\Client;
use Cable8mm\NanoAI\Http\GuzzleHttpClient;
// Use Guzzle with default timeout settings (30s / 10s connect)
$client = new Client(
provider: 'openai',
apiKey: 'sk-...',
httpClient: new GuzzleHttpClient(),
);
// Or inject a pre-configured Guzzle client for full control
$guzzle = new \GuzzleHttp\Client([
'timeout' => 60,
'proxy' => 'http://localhost:8080',
]);
$client = new Client(
provider: 'openai',
apiKey: 'sk-...',
httpClient: new GuzzleHttpClient($guzzle),
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.