datacircle / gemini-php-tools
Find the best GTM APIs. Four function tools for the Gemini PHP client. The tools call Datacircle's public API. You need no API key.
Requires
- php: ^8.1
- ext-json: *
- google-gemini-php/client: ^2.0
- php-http/discovery: ^1
- psr/http-client: ^1
- psr/http-factory: ^1
- psr/http-message: ^1 || ^2
Requires (Dev)
- guzzlehttp/guzzle: ^7.9 || ^8.0
- phpunit/phpunit: ^10.5 || ^11.5 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Find the best GTM APIs. We benchmark all the GTM APIs and we put the results on our website.
Our website: https://datacircle.dev
This package gives the Gemini PHP client four function tools that call Datacircle's open API, https://api.datacircle.dev/v1. You pass the tools to generativeModel()->withTool(). The Gemini PHP client does not run function calls. This package runs each call the model makes to a Datacircle tool. You get the answer to send back to the model. You need no key and no account.
| Tool | What the tool gives | Call |
|---|---|---|
datacircle_list_apis |
Every GTM API on Datacircle, with the API's slug, number of plans, number of providers and best plan | GET /apis |
datacircle_best_plans |
One API's plans, sorted by score out of 100, best first. Each plan comes with a rank and a price per 1,000 calls | GET /apis/{slug}/best |
datacircle_search_plans |
Plans that match a provider or plan name, on all APIs or on one API. You can sort them by score, provider or price | GET /plans |
datacircle_provider |
The APIs a provider sells, and the provider's rank on each API | GET /providers/{slug} |
Install
composer require datacircle/gemini-php-tools
The package needs PHP 8.1 or later and google-gemini-php/client 2.0.0 or later. The tools send their calls through your app's PSR-18 HTTP client, such as Guzzle. google-gemini-php/client needs a PSR-18 HTTP client too. Gemini 3 models need google-gemini-php/client 2.5.0 or later. Version 2.5.0 sends the model's thought signatures back to Gemini.
Use the tools in a chat
Pass Datacircle::tool() to withTool(). Each time the model calls functions, send what Datacircle::responses() returns to the chat:
use Datacircle\Gemini\Datacircle; $client = Gemini::client(getenv('GEMINI_API_KEY')); $chat = $client->generativeModel(model: 'gemini-3.8-flash') ->withTool(Datacircle::tool()) ->startChat(); $response = $chat->sendMessage('Who are the 3 best providers for the email-finder API?'); while (($answers = Datacircle::responses($response)) !== null) { $response = $chat->sendMessage($answers); } echo $response->text(), "\n";
Datacircle::responses() gives one Content that answers each function call the model made, in order. You get null when the model called no function. The chat keeps the model's turns and the thought signatures for you.
Use the tools with generateContent
If you call generateContent() without a chat, add the model's turn and the tool's answers to $contents. Then send $contents to the model again:
use Datacircle\Gemini\Datacircle; use Gemini\Data\Content; $client = Gemini::client(getenv('GEMINI_API_KEY')); $model = $client->generativeModel(model: 'gemini-3.8-flash')->withTool(Datacircle::tool()); $contents = [Content::parse('Which provider ranks first for the SERP API?')]; while (true) { $response = $model->generateContent(...$contents); $answers = Datacircle::responses($response); if ($answers === null) { break; } $contents[] = $response->candidates[0]->content; $contents[] = $answers; } echo $response->text(), "\n";
Send the model's turn back unchanged, with the thought signatures. To stream with streamGenerateContent(), save each chunk in a list. Pass the list to Datacircle::responses() when the stream ends. Build the model's turn from the parts of each chunk: new Content(parts: array_merge(...array_map(fn ($chunk) => $chunk->parts(), $chunks)), role: Role::MODEL). A chat's streamSendMessage() keeps the model's turn for you. The Gemini client has streamSendMessage() from version 2.7.1 on.
Your own functions
Gemini needs an answer to every function call in a turn. If you add functions of your own, pass a callable as the second argument of Datacircle::responses(). The callable gets each call to one of your functions as a FunctionCall. The callable returns the answer as an array or a FunctionResponse:
$answers = Datacircle::responses($response, fn (FunctionCall $call) => ['time' => date('H:i')]);
Leave out the callable and Datacircle::responses() throws an InvalidArgumentException when the model calls one of your functions. Datacircle::handles($name) tells you which calls are Datacircle's. Datacircle::functionResponse($call) answers one call. Datacircle::functionDeclarations() gives the declarations of Datacircle's four functions, to put in a Tool of your own.
Make each call yourself
You can make each call without a model. You get the tool's answer as an array:
use Datacircle\Gemini\Datacircle; $answer = Datacircle::bestPlans(['slug' => 'email-finder', 'limit' => 3]); print_r($answer['plans']);
The other calls are Datacircle::listApis(), Datacircle::searchPlans() and Datacircle::provider(). Datacircle::run($name, $args) runs any call. Give run() the tool's name, such as datacircle_best_plans, and the arguments.
What the model reads
Each tool gives the model a JSON object as the function's response. Each plan comes with a rank, provider, plan, score, price per 1,000 (perThousand, in dollars) and a page on datacircle.dev. That page lists every field.
For an unknown slug, the model reads {"error": "..."} with the API's message. If the arguments do not fit the schema, the error names each wrong argument. If the network fails, the error gives the network's message. The model can then call the tool again and keep going. A call without a model gives the API's message as ['error' => '...'].
To send the calls through another PSR-18 client, pass new \Datacircle\Gemini\Client(http: $httpClient) as the last argument of responses() or any other call. Use this to add a proxy or a timeout.
Network
Each tool call sends HTTPS GET requests to https://api.datacircle.dev/v1 and nowhere else. Most calls send one request. datacircle_search_plans sends up to three when the first search finds nothing. The requests hold only the tool's own arguments: no key and nothing from your chats. The API takes up to 60 calls a minute from one IP address. The tool waits once, for a minute at most, when the API says to wait. The package stores nothing.
Links
- Datacircle: https://datacircle.dev
- The API: https://datacircle.dev/api
- The API's spec: https://api.datacircle.dev/v1/openapi.json
- What each key means: https://datacircle.dev/fields
MIT license.