Search by

papi-ai / grok

md

Grok (xAI) provider for PapiAI

Package info

github.com/papi-ai/grok

Type:papi-provider

pkg:composer/papi-ai/grok

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.17.2 2026-11-16 20:38 UTC

README

CI Latest Version Total Downloads PHP Version License

Grok (xAI) provider for PapiAI - A simple but powerful PHP library for building AI agents.

Installation

composer require papi-ai/grok

Usage

use PapiAI\Core\Agent;
use PapiAI\Grok\GrokProvider;

$provider = new GrokProvider(
    apiKey: $_ENV['XAI_API_KEY'],
);

$agent = new Agent(
    provider: $provider,
    instructions: 'You are a helpful assistant.',
);

$response = $agent->run('Hello!');
echo $response->text;

Available Models

GrokProvider::MODEL_GROK_4_7  // 'grok-4.7' (default, flagship)
GrokProvider::MODEL_GROK_4_6  // 'grok-4.6'
GrokProvider::MODEL_GROK_4_5  // 'grok-4.5'
GrokProvider::MODEL_GROK_4_3  // 'grok-4.3'

The MODEL_GROK_2, MODEL_GROK_3 and MODEL_GROK_3_MINI constants are still shipped but deprecated. Grok 2 is retired, and the Grok 3 pair was retired on 15 May 2026: requests silently redirect to grok-4.3 and bill at its rates, so pin a live model explicitly.

Endpoint

Chat, streaming and tool calling go through xAI's Responses API (POST /v1/responses), which xAI recommends; Chat Completions is legacy there. Each request carries the full conversation (store: false).

Features

  • Tool/function calling
  • Vision/multimodal support
  • Structured output (JSON mode)
  • Streaming support

Creating It by Name

An application that picks its provider from configuration can build this one without naming its class:

use PapiAI\Core\Factory\ComposerDiscovery;
use PapiAI\Core\Factory\ProviderRegistry;

$registry = new ProviderRegistry(new ComposerDiscovery());

$provider = $registry->create('grok', [
    'api_key' => $_ENV['XAI_API_KEY'],
]);

It takes api_key (required), model, max_tokens and effort. Anything it is not given falls back to the constructor's defaults, and a missing or unknown setting throws ConfigurationException before any request is made.

License

MIT