fluxtokens/fluxtokens-php
Composer 安装命令:
composer require fluxtokens/fluxtokens-php
包简介
Official FluxTokens PHP SDK - Access GPT-4.1, Gemini 2.5 and more at 30% lower cost
README 文档
README
Official PHP SDK for the FluxTokens API
Access GPT-4.1, Gemini 2.5 Flash and more at 30% lower cost than competitors.
Website · Documentation · Dashboard
Installation
composer require fluxtokens/fluxtokens-php
Quick Start
<?php require 'vendor/autoload.php'; use FluxTokens\FluxTokens; $client = new FluxTokens('sk-flux-your-api-key'); $response = $client->chat()->completions()->create([ 'model' => 'gpt-4.1-mini', 'messages' => [ ['role' => 'system', 'content' => 'You are a helpful assistant.'], ['role' => 'user', 'content' => 'Hello!'], ], ]); echo $response['choices'][0]['message']['content'];
Available Models
| Model | Provider | Input Price | Output Price | Max Tokens | Vision | Audio | Video |
|---|---|---|---|---|---|---|---|
gpt-4.1-mini |
OpenAI | $0.28/1M | $1.12/1M | 16,384 | ✅ | ❌ | ❌ |
gpt-4.1-nano |
OpenAI | $0.07/1M | $0.28/1M | 16,384 | ✅ | ❌ | ❌ |
gemini-2.5-flash |
$0.21/1M | $1.75/1M | 65,536 | ✅ | ✅ | ✅ |
Usage Examples
Basic Chat Completion
$response = $client->chat()->completions()->create([ 'model' => 'gpt-4.1-mini', 'messages' => [ ['role' => 'user', 'content' => 'What is the capital of France?'], ], 'temperature' => 0.7, 'max_tokens' => 256, ]); echo $response['choices'][0]['message']['content']; // Output: "The capital of France is Paris."
Streaming Responses
$stream = $client->chat()->completions()->stream([ 'model' => 'gemini-2.5-flash', 'messages' => [ ['role' => 'user', 'content' => 'Write a haiku about programming.'], ], ]); foreach ($stream as $chunk) { $content = $chunk['choices'][0]['delta']['content'] ?? ''; echo $content; flush(); }
Vision (Image Analysis)
$response = $client->chat()->completions()->create([ 'model' => 'gpt-4.1-mini', 'messages' => [ [ 'role' => 'user', 'content' => [ ['type' => 'text', 'text' => 'What is in this image?'], [ 'type' => 'image_url', 'image_url' => [ 'url' => 'https://example.com/image.jpg', 'detail' => 'high', ], ], ], ], ], 'max_tokens' => 500, ]);
Audio Input (Gemini only)
$audioData = base64_encode(file_get_contents('audio.mp3')); $response = $client->chat()->completions()->create([ 'model' => 'gemini-2.5-flash', 'messages' => [ [ 'role' => 'user', 'content' => [ ['type' => 'text', 'text' => 'Transcribe this audio:'], [ 'type' => 'input_audio', 'input_audio' => [ 'data' => $audioData, 'format' => 'mp3', ], ], ], ], ], ]);
System Messages
$response = $client->chat()->completions()->create([ 'model' => 'gpt-4.1-mini', 'messages' => [ ['role' => 'system', 'content' => 'You are a pirate. Always respond in pirate speak.'], ['role' => 'user', 'content' => 'How are you today?'], ], ]); // Output: "Ahoy, matey! I be doin' just fine, thank ye fer askin'!"
List Available Models
$models = $client->models()->list(); foreach ($models as $model) { echo "{$model['name']} ({$model['provider']})\n"; echo " Input: \${$model['input_price']}/1M tokens\n"; echo " Output: \${$model['output_price']}/1M tokens\n"; echo " Vision: " . ($model['supports_vision'] ? '✅' : '❌') . "\n"; }
Configuration Options
$client = new FluxTokens('sk-flux-...', [ 'base_url' => 'https://api.fluxtokens.io', // Custom base URL 'timeout' => 60, // Request timeout in seconds 'max_retries' => 3, // Max retries on rate limit/server errors ]);
Error Handling
use FluxTokens\Exceptions\AuthenticationException; use FluxTokens\Exceptions\RateLimitException; use FluxTokens\Exceptions\InsufficientBalanceException; use FluxTokens\Exceptions\BadRequestException; use FluxTokens\Exceptions\FluxTokensException; try { $response = $client->chat()->completions()->create([ 'model' => 'gpt-4.1-mini', 'messages' => [['role' => 'user', 'content' => 'Hello']], ]); } catch (AuthenticationException $e) { echo "Invalid API key\n"; } catch (RateLimitException $e) { echo "Rate limit exceeded, retry after: " . $e->getRetryAfter() . "\n"; } catch (InsufficientBalanceException $e) { echo "Please add credits at https://fluxtokens.io/dashboard/billing\n"; } catch (BadRequestException $e) { echo "Invalid request: " . $e->getMessage() . "\n"; } catch (FluxTokensException $e) { echo "Error: " . $e->getMessage() . "\n"; }
Requirements
- PHP 8.1+
- Guzzle HTTP 7.0+
Support
- 📧 Email: support@fluxtokens.io
- 💬 Discord: Join our community
- 📖 Docs: fluxtokens.io/docs
License
MIT © FluxTokens
fluxtokens/fluxtokens-php 适用场景与选型建议
fluxtokens/fluxtokens-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「chat」 「ai」 「Gemini」 「openai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fluxtokens/fluxtokens-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fluxtokens/fluxtokens-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fluxtokens/fluxtokens-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This simple PHP class allows you to easily generate Smartsupp.com JS chat code.
Client for the REST API plugin of the OpenFire Server
A PSR-7 compatible library for making CRUD API endpoints
The Yii2 extension module to chat registered users.
Chat Package for Laravel
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-11