aisdk/xai
Composer 安装命令:
composer require aisdk/xai
包简介
Official xAI provider for the PHP AI SDK.
README 文档
README
Official xAI provider for the PHP AI SDK. Uses the shared OpenAI-compatible chat-completions adapter for v0.1 text support.
Installation
composer require aisdk/xai
Basic Usage
use AiSdk\Generate; use AiSdk\XAI; $result = Generate::text() ->model(XAI::model('grok-4.3')) ->instructions('Write short, clear answers.') ->prompt('Explain closures in PHP.') ->run(); echo $result->text;
Image Generation
use AiSdk\Generate; use AiSdk\XAI; $result = Generate::image() ->model(XAI::image('grok-imagine-image-quality')) ->prompt('A clean app icon for a PHP AI SDK') ->aspectRatio('1:1') ->run(); $result->output->save(__DIR__.'/icon.png');
Configuration
| Variable | Description | Default |
|---|---|---|
XAI_API_KEY |
API key for authentication | Required |
XAI_BASE_URL |
Base URL for API requests | https://api.x.ai/v1 |
XAI::create([ 'apiKey' => 'xai-...', 'baseUrl' => 'https://api.x.ai/v1', ]);
Reasoning
use AiSdk\Reasoning; $result = Generate::text('Explain the tradeoff.') ->model(XAI::model('grok-4.3')) ->reasoning(Reasoning::effort('low')) ->run();
Provider-Specific Options
$result = Generate::text('Hello') ->model(XAI::model('grok-4.3')) ->providerOptions('xai', [ 'raw' => ['search_parameters' => ['mode' => 'auto']], ]) ->run();
Testing
composer test
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-07