Download the PHP package sungithubid/coze-php-sdk without Composer
On this page you can find all versions of the php package sungithubid/coze-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sungithubid/coze-php-sdk
More information about sungithubid/coze-php-sdk
Files in sungithubid/coze-php-sdk
Package coze-php-sdk
Short Description The PHP SDK for the Coze API
License MIT
Homepage https://github.com/sungithubid/coze-php-sdk
Informations about the package coze-php-sdk
Coze PHP SDK
⚠️ Note: This is an unofficial third-party PHP SDK. Currently, only the commonly used Chat and Datasets APIs are implemented. Other APIs will be added gradually.
A PHP SDK for the Coze API. This SDK provides a convenient way to integrate Coze's AI capabilities into your PHP applications.
Features
- 🚀 PHP SDK for the Coze API
- 🔐 Personal Access Token (PAT) authentication
- 📡 Both streaming and non-streaming chat support
- 🔄 Automatic polling for chat completion
- ⚡ Built on GuzzleHttp for reliable HTTP requests
- 📦 PSR-4 autoloading, ready for Packagist
- 🎯 PHP Generator pattern (
yield $event) for memory-efficient streaming
Requirements
- PHP 7.4 or higher
- Composer
- GuzzleHttp 7.0+
Installation
Or add to your composer.json:
Quick Start
Initialize the Client
Chat Examples
| Example | Method | Description |
|---|---|---|
| chat_stream.php | $client->chat->stream() |
Streaming chat using PHP Generator (yield), memory-efficient for large responses |
| chat_no_stream.php | $client->chat->create() |
Non-streaming chat, returns complete response |
| chat_poll.php | $client->chat->createAndPoll() |
Auto-polling until chat completion |
| chat_with_conversation.php | $client->chat->create() |
Chat with conversation context |
Conversation & Message Examples
| Example | Description |
|---|---|
| conversation_crud.php | Create, retrieve, list, and clear conversations |
| message_crud.php | Create, retrieve, list, update, and delete messages |
Dataset Examples
| Example | Description |
|---|---|
| dataset_crud.php | Create, list, update, and delete datasets (knowledge bases) |
| document_crud.php | Create, list, update, and delete documents in datasets |
Workflow Examples
| Example | Description |
|---|---|
| workflow_run.php | Execute a workflow with non-streaming output |
| workflow_stream.php | Execute a workflow with streaming output (SSE) |
API Reference
CozeClient
The main entry point for the SDK.
Chat API
$client->chat->create(array $request): array
Create a non-streaming chat.
Parameters:
bot_id(string, required): The ID of the botuser_id(string, required): The ID of the useradditional_messages(array, required): List of messagesconversation_id(string, optional): Conversation ID for contextauto_save_history(bool, optional): Whether to save history (default: true)meta_data(array, optional): Additional metadataparameters(array, optional): Custom parameters
$client->chat->stream(array $request): Generator
Create a streaming chat that yields ChatEvent objects.
$client->chat->createAndPoll(array $request, int $pollInterval = 1, int $timeout = 300): Chat
Create a chat and poll until completion.
$client->chat->retrieve(string $conversationId, string $chatId): array
Retrieve chat status.
$client->chat->cancel(string $conversationId, string $chatId): array
Cancel a chat.
Conversations API
$client->conversations->create(array $request): array
Create a new conversation.
Parameters:
messages(array, optional): Initial messages in the conversationmeta_data(array, optional): Additional metadatabot_id(string, optional): Bot ID to bind the conversationconnector_id(string, optional): Connector ID (999: Chat SDK, 1024: API)
$client->conversations->retrieve(string $conversationId): array
Retrieve conversation details.
$client->conversations->list(array $request): array
List conversations for a bot.
Parameters:
bot_id(string, required): Bot IDpage_num(int, optional): Page number (default: 1)page_size(int, optional): Page size (default: 20)
$client->conversations->clear(string $conversationId): array
Clear conversation context/history.
Messages API
$client->conversations->messages->create(array $request): array
Create a message in a conversation.
Parameters:
conversation_id(string, required): Conversation IDrole(string, required): Message role ('user' or 'assistant')content(string, required): Message contentcontent_type(string, required): Content type ('text' or 'object_string')meta_data(array, optional): Additional metadata
$client->conversations->messages->list(array $request): array
List messages in a conversation.
Parameters:
conversation_id(string, required): Conversation IDorder(string, optional): Sorting order ('asc' or 'desc')chat_id(string, optional): Filter by chat IDbefore_id(string, optional): Get messages before this IDafter_id(string, optional): Get messages after this IDlimit(int, optional): Number of messages (default: 50, max: 50)
$client->conversations->messages->retrieve(string $conversationId, string $messageId): array
Retrieve a specific message.
$client->conversations->messages->update(array $request): array
Update a message.
Parameters:
conversation_id(string, required): Conversation IDmessage_id(string, required): Message IDcontent(string, optional): New message contentcontent_type(string, optional): New content typemeta_data(array, optional): New metadata
$client->conversations->messages->delete(string $conversationId, string $messageId): array
Delete a message.
Datasets API (Knowledge Base)
$client->datasets->create(array $request): array
Create a new dataset (knowledge base).
Parameters:
name(string, required): Dataset namespace_id(string, required): Space IDformat_type(int, required): 0 = Document, 1 = Spreadsheet, 2 = Imagedescription(string, optional): Dataset description
$client->datasets->list(array $request): array
List datasets in a space.
Parameters:
space_id(string, required): Space IDpage_num(int, optional): Page number (default: 1)page_size(int, optional): Page size (default: 10)
$client->datasets->update(string $datasetId, array $request): array
Update a dataset.
$client->datasets->delete(string $datasetId): array
Delete a dataset.
Documents API (Knowledge Base Files)
$client->datasets->documents->create(array $request): array
Create documents in a dataset.
$client->datasets->documents->list(array $request): array
List documents in a dataset.
Parameters:
dataset_id(int, required): Dataset IDpage(int, optional): Page number (default: 1)size(int, optional): Page size (default: 20)
$client->datasets->documents->update(array $request): array
Update a document.
Parameters:
document_id(int, required): Document IDdocument_name(string, optional): New document name
$client->datasets->documents->delete(array $documentIds): array
Delete documents.
DocumentBase Helper Methods
Message Helper Methods
Event Types
Error Handling
Environment Variables
You can configure the SDK using environment variables:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
TODO
- [x] Conversations
- [x] Workflows
- [ ] Bots
- [ ] Workspaces
- [ ] Files
- [ ] Apps
- [ ] Folders