Laravel
Laravel stats
- Downloads
- 0
- Stars
- 8
- Open Issues
- 0
- Forks
- 0
Seamlessly integrate Grok AI into Laravel applications with an elegant, developer-friendly package. Leverage powerful AI models for chat, automation, and NLP while maintaining Laravel's expressive simplicity.
๐ง Grok AI Laravel

Seamlessly integrate Grok AI into Laravel applications with an elegant, developer-friendly package.
Leverage powerful AI models for chat, automation, and NLP, while maintaining Laravel's expressive simplicity.
๐ Table of Contents
- โจ Features
- ๐ฆ Installation
- ๐ Quick Start
- ๐ Available Grok AI Models
- โก Streaming Responses
- ๐งช Testing
- ๐ Security
- ๐ค Contributing
- ๐ License
โจ Features
โ
Seamless Laravel Integration โ Works effortlessly with Laravel 10+
โ
Simple API Client โ Access Grok AI models with a fluent, clean syntax
โ
Supports All Grok AI Models โ Choose from multiple LLM & vision models
โ
Streaming Capable โ Enable real-time AI responses for interactive experiences
โ
Configurable Defaults โ Set your preferred model, temperature, and more
๐ฆ Installation
Install via Composer:
composer require grok-php/laravel
After installation, run the setup command:
php artisan grok:install
This command will:
- Publish the configuration file (
config/grok.php). - Add necessary environment variables to
.envand.env.example.
Add your API key in .env:
GROK_API_KEY=your-api-key
๐ Quick Start
Basic Usage
use GrokPHP\Laravel\Facades\GrokAI;use GrokPHP\Client\Config\ChatOptions;use GrokPHP\Client\Enums\Model; $response = GrokAI::chat( [['role' => 'user', 'content' => 'Hello Grok!']], new ChatOptions(model: Model::GROK_2)); echo $response['choices'][0]['message']['content'];
๐ Defaults Used:
Model: grok-2 Temperature: 0.7 Streaming: false
Advanced Configuration
Modify your config/grok.php file:
return [ 'api_key' => env('GROK_API_KEY'), 'base_uri' => env('GROK_BASE_URI', 'https://api.grok.com/v1'), 'default_model' => env('GROK_DEFAULT_MODEL', 'grok-2'), 'default_temperature' => env('GROK_DEFAULT_TEMPERATURE', 0.7), 'enable_streaming' => env('GROK_ENABLE_STREAMING', false), 'timeout' => env('GROK_API_TIMEOUT', 30),];
๐ You can override any setting dynamically:
$response = GrokAI::chat( [['role' => 'user', 'content' => 'Explain black holes']], new ChatOptions(model: Model::GROK_2_LATEST, temperature: 1.2, stream: true));
๐ Available Grok AI Models
Grok AI offers multiple models, each optimized for different use cases.
These models are available in the Model enum inside our package:
๐ src/Enums/Model.php
| Model Enum | API Model Name | Description |
|---|---|---|
Model::GROK_VISION_BETA |
grok-vision-beta | Experimental vision-enabled model |
Model::GROK_2_VISION |
grok-2-vision | Advanced multi-modal vision model |
Model::GROK_2_VISION_LATEST |
grok-2-vision-latest | Latest iteration of Grok vision models |
Model::GROK_2_VISION_1212 |
grok-2-vision-1212 | Enhanced vision model with performance improvements |
Model::GROK_2_1212 |
grok-2-1212 | Optimized chat model |
Model::GROK_2 |
grok-2 | Default general-purpose Grok model |
Model::GROK_2_LATEST |
grok-2-latest | Latest iteration of Grok-2 |
Model::GROK_BETA |
grok-beta | Experimental beta model |
๐ Default model used: Model::GROK_2
โก Streaming Responses
Enable real-time AI responses by setting stream: true:
$response = GrokAI::chat( [['role' => 'user', 'content' => 'Tell me a story']], new ChatOptions(model: Model::GROK_2, stream: true));
Streaming is useful for chatbots, assistants, and real-time applications.
๐งช Testing
Run tests using Pest PHP:
composer testorvendor/bin/phpunit
๐ Security
If you discover a security vulnerability, please report it via email: ๐ฉ thefeqy@gmail.com
๐ค Contributing
Want to improve this package? Check out CONTRIBUTE.md for contribution guidelines.
๐ License
This package is open-source software licensed under the MIT License.