PHPackages                             aisdk/groq - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aisdk/groq

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aisdk/groq
==========

Official Groq provider for the PHP AI SDK.

v0.1.0-alpha1(yesterday)02↑2900%MITPHPPHP ^8.3

Since Jun 30Pushed yesterdayCompare

[ Source](https://github.com/phpaisdk/groq)[ Packagist](https://packagist.org/packages/aisdk/groq)[ Docs](https://github.com/phpaisdk/groq)[ RSS](/packages/aisdk-groq/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

aisdk/groq
==========

[](#aisdkgroq)

Official Groq provider for the PHP AI SDK. Uses the shared OpenAI-compatible wire adapter.

Installation
------------

[](#installation)

```
composer require aisdk/groq
```

Basic Usage
-----------

[](#basic-usage)

```
use AiSdk\Generate;
use AiSdk\Groq;

$result = Generate::text()
    ->model(Groq::model('llama-3.3-70b-versatile'))
    ->instructions('Write short, clear answers.')
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
```

Default model shorthand:

```
Generate::model(Groq::model('llama-3.3-70b-versatile'));

$result = Generate::text('Explain closures in PHP.')->run();
```

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

VariableDescriptionDefault`GROQ_API_KEY`API key for authenticationRequired`GROQ_BASE_URL`Base URL for API requests`https://api.groq.com/openai/v1`### Programmatic Configuration

[](#programmatic-configuration)

```
$provider = Groq::create([
    'apiKey' => 'gsk-...',
    'baseUrl' => 'https://api.groq.com/openai/v1',
    'headers' => ['X-Custom-Header' => 'value'],
]);
```

Supported Capabilities
----------------------

[](#supported-capabilities)

CapabilitySupportText generationNativeStreamingNativeTool callingNativeStructured outputAdapted on most models (`json_object` + instruction); native on `gpt-oss-*` and `kimi*`Text inputNativeImage inputNative (Llama 4 models)Streaming
---------

[](#streaming)

```
use AiSdk\Generate;
use AiSdk\Groq;

$stream = Generate::text('Tell me a story.')
    ->model(Groq::model('llama-3.3-70b-versatile'))
    ->stream();

foreach ($stream->chunks() as $chunk) {
    echo $chunk;
}

$result = $stream->run();
```

Structured Output
-----------------

[](#structured-output)

Most Groq models do not support native `json_schema`. The provider automatically degrades to `json_object` with an injected JSON instruction:

```
use AiSdk\Generate;
use AiSdk\Groq;
use AiSdk\Schema;

$result = Generate::text()
    ->model(Groq::model('llama-3.3-70b-versatile'))
    ->prompt('Extract the city and country from: Lahore, Pakistan.')
    ->output(Schema::object(
        name: 'address',
        properties: [
            Schema::string(name: 'city')->required(),
            Schema::string(name: 'country')->required(),
        ],
    ))
    ->run();
```

Models with native `json_schema` support (`openai/gpt-oss-20b`, `openai/gpt-oss-120b`, `moonshotai/kimi*`) use the native format directly.

Tools
-----

[](#tools)

```
use AiSdk\Generate;
use AiSdk\Groq;
use AiSdk\Schema;
use AiSdk\Tool;

$weather = Tool::make('weather', 'Get current weather')
    ->input(Schema::string(name: 'city')->required())
    ->run(fn (string $city): string => "Sunny in {$city}");

$result = Generate::text()
    ->model(Groq::model('llama-3.3-70b-versatile'))
    ->prompt('What is the weather in Lahore?')
    ->tool($weather)
    ->run();
```

Custom Model Registration
-------------------------

[](#custom-model-registration)

Register new Groq models without waiting for a package release:

```
use AiSdk\Capability;
use AiSdk\Groq;

Groq::registerModel('llama-5-70b', capabilities: [
    Capability::TextGeneration,
    Capability::Streaming,
    Capability::ToolCalling,
    Capability::StructuredOutput,
    Capability::TextInput,
]);

$result = Generate::text('Hello')
    ->model(Groq::model('llama-5-70b'))
    ->run();
```

Use `ModelDefinition` only when you need metadata or adapted-capability details.

Provider-Specific Options
-------------------------

[](#provider-specific-options)

Raw provider options can be passed as an escape hatch:

```
$result = Generate::text('Hello')
    ->model(Groq::model('llama-3.3-70b-versatile'))
    ->providerOptions('groq', [
        'raw' => ['top_k' => 40],
    ])
    ->run();
```

Testing
-------

[](#testing)

```
composer test
```

Links
-----

[](#links)

- [Core Package](https://github.com/phpaisdk/core)
- [OpenAI-Compatible Package](https://github.com/phpaisdk/openai-compatible)
- [Project Documentation](https://github.com/phpaisdk)

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef29d1962da41e7526023f215cf844494e209b2fd163742084cb919a3b508021?d=identicon)[aisdk](/maintainers/aisdk)

---

Top Contributors

[![RanaMoizHaider](https://avatars.githubusercontent.com/u/58527494?v=4)](https://github.com/RanaMoizHaider "RanaMoizHaider (2 commits)")

---

Tags

aillmgroqopenai-compatibleaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aisdk-groq/health.svg)

```
[![Health](https://phpackages.com/badges/aisdk-groq/health.svg)](https://phpackages.com/packages/aisdk-groq)
```

###  Alternatives

[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

318117.1k1](/packages/cognesy-instructor-php)[ardagnsrn/ollama-php

This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.

21074.5k](/packages/ardagnsrn-ollama-php)[symfony/ai-agent

PHP library for building agentic applications.

31746.8k83](/packages/symfony-ai-agent)[soukicz/llm

LLM client with support for cache, tools and async requests

4411.4k](/packages/soukicz-llm)[anilcancakir/laravel-ai-sdk-skills

A skill system for Laravel AI SDK agents. Define reusable AI capabilities with SKILL.md files.

215.2k](/packages/anilcancakir-laravel-ai-sdk-skills)[stimmt/craft-mcp

MCP (Model Context Protocol) server for Craft CMS

261.3k](/packages/stimmt-craft-mcp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
