Download the PHP package alexpago/grok-php without Composer
On this page you can find all versions of the php package alexpago/grok-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexpago/grok-php
More information about alexpago/grok-php
Files in alexpago/grok-php
Package grok-php
Short Description PHP library for interacting with the Grok API. Supports: grok-3, grok-3-mini, grok-4, grok-2-image (and other models).
License MIT
Homepage https://github.com/alexpago/grok-php
Informations about the package grok-php
GrokChat PHP Library
GrokChat is a PHP library for interacting with the Grok API.
It provides a simple, object-oriented interface for sending chat messages, managing multi-turn conversations, handling responses, and streaming results.
✨ Features
- Supports: grok-3, grok-3-mini, grok-4, grok-2-image (and other models)
-
Simple API for sending chat messages:
-
Multi-turn conversations:
-
Supports image understanding
-
Supports image generation
-
Streaming responses with custom handlers:
- Supports roles (
Role::USER
,Role::SYSTEM
) - Configurable (temperature, model, roles, etc.)
- PSR-4 autoloading via Composer
📦 Installation
Install via Composer:
🚀 Quick Start
Tip:
- Use
send()
when you only need the message text (string ornull
).- Use
run()
when you need the full response object (ChatResponse
orChatErrorResponse
).
1. Start a Simple Chat
send()
returns the text response (string|null
).
2. Chat with Multiple Messages
Available roles:
Role::USER
(default) andRole::SYSTEM
.
3. Get the Full Response
4. Chat with Options
Temperature: Lower = focused & reliable Higher = creative & diverse (Regular ChatGPT default ≈
1.3
)
5. Image understanding
You can use the queryImage
method to use "Grok Understanding". First argument accepts an external image URL or a base64-encoded string.
Support only JPEG and PNG formats are supported. Maximum size is 20 MB.
6. Image generation
To generate an image, use GrokImageGeneration
class instead of GrokChat.
7. Streaming Results
Use a custom callback to process streaming chunks:
⚙️ Requirements
- PHP 8.1+
- Composer
📜 License
MIT License.