adachsoft / ai-integration-xai-responses
xAI Responses API integration for AdachSoft AI Integration tool calling
Package info
gitlab.com/a.adach/ai-integration-xai-responses
pkg:composer/adachsoft/ai-integration-xai-responses
Requires
- php: ^8.3
- adachsoft/ai-integration: ^0.8
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- adachsoft/php-code-style: ^0.5
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ~2.1.46
- phpunit/phpunit: ^13.1
- rector/rector: ^2.4
- symplify/phpstan-rules: ~14.10.0
- vlucas/phpdotenv: ^5.6
README
PHP integration for the xAI Responses API using the tool-calling abstractions provided by adachsoft/ai-integration.
The package maps tool-calling chat requests to xAI Responses API payloads and maps API responses back to the shared SPI response model. It supports assistant messages, system and user messages, function calls, function call outputs, token usage, configurable models, and optional HTTP traffic logging.
Requirements
- PHP 8.3 or newer
- An xAI API key
Installation
composer require adachsoft/ai-integration-xai-responses
Usage
Create the xAI configuration and build the tool-calling chat SPI through the package factory:
use AdachSoft\AiIntegrationXaiResponses\Config\XaiResponsesConfig;
use AdachSoft\AiIntegrationXaiResponses\XaiResponsesToolCallingChatSpiFactory;
$config = new XaiResponsesConfig(
apiKey: getenv('XAI_API_KEY'),
defaultModelId: 'grok-4',
);
$chat = XaiResponsesToolCallingChatSpiFactory::create($config);
The resulting $chat implements ToolCallingChatSpiInterface from adachsoft/ai-integration and can be used wherever that shared SPI is expected. Use XaiResponsesToolCallingChatSpiFactory::createWithLogger() when HTTP request and response logging is required.
Configuration
XaiResponsesConfig supports the following settings:
apiKey— xAI API key.defaultModelId— model used when a request does not provide one; defaults togrok-4.baseUri— xAI API base URI; defaults tohttps://api.x.ai/v1.defaultTemperature— default sampling temperature; defaults to0.7.
Keep API keys in environment variables or another secure secret store. Do not commit credentials to source control.
License
This package is licensed under the MIT License. See the LICENSE file for details.