goed/cerebras-php
Composer 安装命令:
composer require goed/cerebras-php
包简介
A PHP adapter for the Cerebras AI API
README 文档
README
Made with ❤️ by Goed.email
Cerebras PHP Client
A PHP client library for interacting with the Cerebras AI API, providing easy access to chat completions and other endpoints.
Installation
Install the package via Composer:
composer require goed/cerebras-php
Usage
Setup
Set your API key as an environment variable:
export CEREBRAS_API_KEY=your_api_key_here
Basic Chat Completion
Create a non-streaming chat completion:
<?php require 'vendor/autoload.php'; use Goed\Cerebras\Client; $client = new Client(); $response = $client->chat()->create([ 'model' => 'llama3.1-8b', 'messages' => [ ['role' => 'user', 'content' => 'Hello, how are you?'] ] ]); echo $response['choices'][0]['message']['content'];
Streaming Chat Completion
For real-time responses, use streaming:
<?php require 'vendor/autoload.php'; use Goed\Cerebras\Client; $client = new Client(); $stream = $client->chat()->create([ 'model' => 'llama3.1-8b', 'messages' => [ ['role' => 'user', 'content' => 'Tell me a story.'] ], 'stream' => true ]); foreach ($stream as $chunk) { echo $chunk['choices'][0]['delta']['content'] ?? ''; }
For more examples, see the examples/ directory, including basic.php, chat_page.php, and chat_page_non_streaming.php.
Browser Chat Demo
Serve the example files with PHP's built-in server for quick browser chat UIs:
php -S localhost:8080 -t examples
Then open:
http://localhost:8080/chat_page.phpfor streaming responseshttp://localhost:8080/chat_page_non_streaming.phpfor non-streaming responses
Features
- API Compatibility: Endpoints and payloads match the official Cerebras AI API. Adjust model IDs and fields as needed.
- Retry Mechanism: Automatic retry with backoff for 429 (rate limit) and 5xx errors.
- Streaming Support: Server-Sent Events (SSE) for real-time chat completions.
- Helpers: Basic utility functions for common tasks.
Notes
Ensure your API key is valid and has the necessary permissions. Refer to the Cerebras AI documentation for detailed API specifications.
goed/cerebras-php 适用场景与选型建议
goed/cerebras-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 157 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 goed/cerebras-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 goed/cerebras-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 157
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-15