1. Go to this page and download the library: Download cencori/cencori-php 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/ */
// General analysis with a custom prompt
$result = $cencori->vision->analyze([
'image_url' => 'https://example.com/photo.jpg',
'prompt' => 'What breed of dog is this?',
]);
echo $result['analysis'];
// OCR from a local file
$b64 = base64_encode(file_get_contents('receipt.png'));
$ocr = $cencori->vision->ocr(['image_base64' => $b64, 'mime_type' => 'image/png']);
echo $ocr['text'];
// Structured classification
$c = $cencori->vision->classify(['image_url' => 'https://example.com/product.jpg']);
// $c['classification'] is an array when the model returns valid JSON
// Extract text (native PDF parse — free)
$result = $cencori->documents->extract([
'document_url' => 'https://example.com/contract.pdf',
]);
echo $result['method']; // 'pdf_text' — no LLM cost
// Summarize
$summary = $cencori->documents->summarize([
'document_url' => 'https://example.com/report.pdf',
]);
echo $summary['summary'];
// Q&A — strict "Not found" if answer isn't present
$answer = $cencori->documents->query([
'document_url' => 'https://example.com/contract.pdf',
'question' => 'What is the termination clause?',
]);
echo $answer['answer'];
$result = $cencori->ai->generateImage(
prompt: 'A futuristic city at sunset',
model: 'dall-e-3',
size: '1024x1024',
);
echo $result['images'][0]['url'];
foreach ($cencori->ai->ragStream(
model: 'gpt-4o',
messages: [['role' => 'user', 'content' => 'What are our policies?']],
namespace: 'company-docs',
) as $chunk) {
if ($chunk['type'] === 'content') {
echo $chunk['delta'];
}
}
$response = $cencori->ai->responses(
model: 'gpt-4o',
input: 'What is the weather in San Francisco?',
tools: [['type' => 'web_search_preview']],
);
print_r($response);
foreach ($cencori->ai->responsesStream(
model: 'gpt-4o',
input: 'Tell me about AI',
) as $event) {
if ($event['type'] === 'response.output_text.delta') {
echo $event['data']['delta'];
}
}
// Create an agent
$agent = $cencori->agents->create([
'name' => 'my-agent',
'config' => [
'model' => 'gpt-4o',
'system_prompt' => 'You are a helpful assistant.',
],
]);
// List agents
$agents = $cencori->agents->list();
// Get a specific agent
$agent = $cencori->agents->get('agent_123');
// Update agent configuration
$agent = $cencori->agents->updateConfig('agent_123', [
'name' => 'updated-agent',
'config' => ['temperature' => 0.5],
]);
// Create an agent API key
$key = $cencori->agents->createKey('agent_123', [
'name' => 'prod-key',
'environment' => 'production',
]);
// Delete an agent
$cencori->agents->delete('agent_123');
// Create a namespace
$namespace = $cencori->memory->createNamespace([
'name' => 'conversations',
]);
// List namespaces
$namespaces = $cencori->memory->listNamespaces();
// Store a memory
$memory = $cencori->memory->store([
'namespace' => 'conversations',
'content' => 'User asked about pricing plans',
'metadata' => ['userId' => 'user_123'],
]);
// Semantic search
$results = $cencori->memory->search([
'namespace' => 'conversations',
'query' => 'what did we discuss about pricing?',
'limit' => 5,
]);
// Get a memory by ID
$memory = $cencori->memory->get('mem_123');
// Delete a memory
$result = $cencori->memory->delete('mem_123');
// Batch store
$memories = $cencori->memory->storeBatch('conversations', [
['content' => 'Memory 1', 'metadata' => ['key' => 'value1']],
['content' => 'Memory 2', 'metadata' => ['key' => 'value2']],
]);
// Delete by filter
$result = $cencori->memory->deleteByFilter('conversations', ['userId' => 'user_123']);
// Create a session
$session = $cencori->sessions->create([
'agent_id' => 'ag_...',
]);
// List sessions
$sessions = $cencori->sessions->list(['status' => 'active']);
// Get a session by ID
$session = $cencori->sessions->get('sess_123');
// Submit a turn (returns SSE stream)
$response = $cencori->sessions->submitTurn('sess_123', [
'input' => 'What is the weather in San Francisco?',
'pause_on_tool_calls' => true,
]);
$body = $response->getBody();
while (!$body->eof()) {
echo $body->read(1024);
}
// Get session events
$events = $cencori->sessions->getEvents('sess_123', [
'turn_number' => 1,
]);
// Approve a pending action (returns SSE stream)
$response = $cencori->sessions->approve('sess_123', [
'action_id' => 'act_...',
'tool_results' => [
['action_id' => 'act_...', 'output' => '{"temperature": 72}'],
],
]);
// Reject a pending action
$result = $cencori->sessions->reject('sess_123', [
'action_id' => 'act_...',
]);
echo $result['resolution']; // "rejected"
// Delete a session
$cencori->sessions->delete('sess_123');