Package

Grok Php 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.

Package

grok-php/laravel

View on GitHub →

🧠 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

βœ… 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 .env and .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 test
or
vendor/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.

Grok Php Laravel Related Articles

Integrate Grok AI in Laravel image

Integrate Grok AI in Laravel

Read article
VMPal: Give Your AI Agent a Whole Computer image

VMPal: Give Your AI Agent a Whole Computer

Read article
Modern PHP features explained - PHP 8.0 and 8.1 image

Modern PHP features explained - PHP 8.0 and 8.1

Read article
PHP-PM Is a Process Manager, Supercharger, and Load Balancer for PHP Applications image

PHP-PM Is a Process Manager, Supercharger, and Load Balancer for PHP Applications

Read article
PHP Fatal Error Backtraces in PHP 8.5 image

PHP Fatal Error Backtraces in PHP 8.5

Read article
PHP News: A New Site for PHP Releases, RFCs, and Packages image

PHP News: A New Site for PHP Releases, RFCs, and Packages

Read article

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift