1. Go to this page and download the library: Download sungithubid/coze-php-sdk 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/ */
sungithubid / coze-php-sdk example snippets
use Coze\CozeClient;
use Coze\Auth\TokenAuth;
$client = new CozeClient(
new TokenAuth('your_access_token'),
CozeClient::BASE_URL_CN // or CozeClient::BASE_URL_COM for global
);
$client = new CozeClient(
AuthInterface $auth, // Authentication handler
string $baseUrl = 'https://api.coze.cn', // API base URL
array $options = [] // Additional HTTP client options
);
use Coze\Models\DocumentBase;
// Build from local file content
$doc = DocumentBase::buildLocalFile('name', 'content', 'txt');
// Build from web page URL
$doc = DocumentBase::buildWebPage('name', 'https://example.com', 24); // 24h update interval
// Build from image file ID
$doc = DocumentBase::buildImage('name', $fileId);
use Coze\Models\Message;
// Build a user text question
$message = Message::buildUserQuestionText('Hello!');
// Build an assistant answer
$message = Message::buildAssistantAnswer('Hi there!');
// Build multimodal message with text and image
$message = Message::buildUserQuestionObjects([
Message::textObject('What is in this image?'),
Message::imageObjectByUrl('https://example.com/image.jpg'),
]);