Tool calling lets a language model invoke PHP functions during a generation. You define a tool with a name, a description, and an input schema; the SDK sends your tools to the Groq API, detects when the model requests a call, executes your handler, and feeds the result back — all inside a singleDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/groq/llms.txt
Use this file to discover all available pages before exploring further.
->run() call. The final TextModelResponse contains the model’s natural-language answer after the loop completes.
How Tool Calling Works
Tool::make() takes a name and a short description. Chain ->input() to describe the arguments the model should supply, and ->run() to provide the PHP callable that handles the invocation.use AiSdk\Schema;
use AiSdk\Tool;
$weather = Tool::make('weather', 'Get the current weather for a city')
->input(Schema::string(name: 'city')->required())
->run(fn (string $city): string => "Sunny in {$city}");
The
->run() closure receives named arguments that match the schema properties you declared, so parameter names must align with your schema field names.Pass the tool to the generate builder with
->tool($weather). The SDK includes it in the API request and automatically handles any tool-call rounds before returning the final response.use AiSdk\Generate;
use AiSdk\Groq;
$result = Generate::text()
->model(Groq::model('llama-3.3-70b-versatile'))
->prompt('What is the weather in Lahore?')
->tool($weather)
->run();
The result is an ordinary
TextModelResponse. Access the model’s final answer through $result->text.Complete Weather Tool Example
Weather tool — complete example
Using Multiple Tools
Register as many tools as you need by chaining additional->tool() calls. The model will pick whichever tool (or sequence of tools) best answers the prompt.
Multiple tools
Supported Models
All Groq models in the catalog support tool calling natively. The following table lists the available models and their context window sizes:| Model ID | Context Tokens |
|---|---|
llama-3.1-8b-instant | 131 072 |
llama-3.3-70b-versatile | 131 072 |
meta-llama/llama-4-scout* | — |
meta-llama/llama-4-maverick* | — |
moonshotai/kimi* | — |
openai/gpt-oss-20b | 131 072 |
openai/gpt-oss-120b | 131 072 |
Check tool calling capability
Real-World Tool Pattern
For production use, replace the inline closure with a service call or a database lookup:Production tool with a service call
The SDK executes your
->run() closure synchronously in the same PHP process. If your tool performs I/O (HTTP requests, database queries), that latency is added to the total generation time. Consider caching aggressively for frequently called tools.