level7up/openrouter-client
Composer 安装命令:
composer require level7up/openrouter-client
包简介
OpenRouter API client for Laravel
README 文档
README
A simple Laravel wrapper for the OpenRouter API to easily perform chat completions using models like openai/gpt-4o.
🧰 Features
- Easy integration with Laravel via Service Provider
- Customizable via
.envorconfig/openrouter.php - Uses Guzzle for HTTP requests
- Supports
max_tokensfor response control
🚀 Installation
Require the package via Composer:
composer require level7up/openrouter-client
🛠 Configuration
Publish the configuration file:
php artisan vendor:publish --tag=config
Add your credentials to .env:
OPENROUTER_API_KEY=your_openrouter_api_key OPENROUTER_BASE_URL=https://openrouter.ai/api/v1 OPENROUTER_REFERER=https://your-site.com # optional OPENROUTER_SITE_TITLE=Your Site Name # optional
🧪 Usage
Inject the client into your controller or service:
use Level7up\OpenRouter\OpenRouterClient; class ChatController extends Controller { public function ask(OpenRouterClient $client) { $response = $client->getCompletion('Tell me a joke.', 50); return response()->json(['reply' => $response]); } }
⚙️ Configuration File
After publishing, you can modify config/openrouter.php:
return [ 'api_key' => env('OPENROUTER_API_KEY'), 'base_url' => env('OPENROUTER_BASE_URL', 'https://openrouter.ai/api/v1'), 'referer' => env('OPENROUTER_REFERER'), 'site_title' => env('OPENROUTER_SITE_TITLE'), ];
📚 API Reference
getCompletion(string $prompt, int $maxTokens = 100): ?string
Sends a prompt to the OpenRouter API and returns the response string.
✅ Requirements
- PHP 8.0+
- Laravel 8+
- Guzzle 7+
📄 License
This package is open-sourced software licensed under the MIT license.
🧠 About
Maintained by Level7up. Contributions and issues are welcome!
level7up/openrouter-client 适用场景与选型建议
level7up/openrouter-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 289 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 level7up/openrouter-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 level7up/openrouter-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 289
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-15