Download the PHP package alvincoded/grok-php-client without Composer
On this page you can find all versions of the php package alvincoded/grok-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alvincoded/grok-php-client
More information about alvincoded/grok-php-client
Files in alvincoded/grok-php-client
Package grok-php-client
Short Description A 2-in-1 PHP SDK to interact with the Grok AI API for both framework-agnostic PHP and Laravel applications
License MIT
Informations about the package grok-php-client
Grok PHP: The 2-in-1 PHP SDK for Grok AI
Grok PHP is a 2-in-1 PHP SDK offering seamless integration with Grok AI API for both framework-agnostic PHP and Laravel 11+ applications.
Features
- Dual Architecture: Use as framework-agnostic PHP library or first-class Laravel package with extensive error handling
- Full API Coverage: Chat, completions, images, embeddings, and structured outputs
- Modern PHP: Strict types, enums, and attributes for schema definition
- Laravel Integration: Auto-discovery, config publishing, and facade support
- Advanced Chat Capabilities: Full support for multi-turn conversations and real-time streaming
- Model Flexibility: Support for multiple Grok models (Grok-2, Grok-2-Vision, etc.)
- Enterprise Ready: Secure API handling with proper authentication
- Easy Configuration: Simple setup with minimal dependencies
Requirements
- PHP 8.2 or higher
- Laravel 11+ (For Laravel applications)
- Composer
- Grok AI API key
Installation
Install Grok PHP via Composer:
Do the following with Laravel applications only:
Note: This command publishes the configuration file and adds the relevant environment variables to your
.env
file.
Quick Start
Framework-agnostic PHP Usage :
Chat Completion
Text Completions
Image Understanding
Embeddings
Model-specific executions
Structured Output
Structured Output (alt. option with PHP class)
Laravel Usage :
The coolest part about using Laravel with Grok PHP? You don't have to learn any new tricks! Just use it the same way you would with the framework-agnostic PHP and you're good to go. It's like magic, but better! ✨
Response Handling
Chat/Completion Response Methods
Image Analysis Response Methods
Embedding Response Methods
Error Handling
Supported Models
Model | Supports Streaming | Supports Functions |
---|---|---|
grok-beta | Yes | Yes |
grok-2-vision-1212 | No | No |
grok-2-1212 | Yes | Yes |
Supported Parameters
temperature(float $value)
: Sets the temperature for sampling the next token.maxTokens(int $value)
: Sets the maximum number of tokens to generate in the completion.topP(float $value)
: Sets the top P value for nucleus sampling.stream(bool $value)
: Sets the presence of streaming responses.systemMessage(string $message)
: Sets the system message for the AI model.n(int $value)
: Sets the number of completions to generate.presencePenalty(float $value)
: Sets the presence penalty.frequencyPenalty(float $value)
: Sets the frequency penalty.logitBias(array $values)
: Sets the logit bias for the completion.stop(array $values)
: Sets the stop sequence for the completion.logprobs(int $value)
: Sets the logprobs parameter.dimensions(int $value)
: Sets the dimensions parameter for embedding.echo(bool $value)
: Sets the echo parameter.user(string $value)
: Sets the user parameter.suffix(string $value)
: Sets the suffix that is appended to the completion.
Environment Variables
Add the following to your .env
file:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are highly aappreciated! Please see the Contributing Guide for details.
Security
Please review the security policy on how to report security vulnerabilities.
License
Grok PHP is an open-sourced software licensed under the MIT license.
Support
If you encounter any issues or have questions, please open an issue on the GitHub repository.
Built with ❤️ for the AI community.
All versions of grok-php-client with dependencies
guzzlehttp/guzzle Version ^7.9
psr/http-message Version ^2.0
psr/http-client Version ^1.0