Search by

datacircle / openai-php-tools

datacircle

Find the best GTM APIs. Four function tools for the OpenAI PHP client, for chat and responses. The tools call Datacircle's public API. You need no API key.

v0.1.0 2026-11-22 08:25 UTC

This package is auto-updated.

Last update: 2026-11-22 08:26:47 UTC


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 OpenAI PHP client four function tools that call Datacircle's open API, https://api.datacircle.dev/v1. You pass the tools to chat()->create() or responses()->create(). The OpenAI PHP client does not run tool calls. This package runs each of Datacircle's tool calls and gives you 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/openai-php-tools

The package needs PHP 8.2 or later and openai-php/client 0.14.0 or later. The tools send their calls through your app's PSR-18 HTTP client, such as Guzzle. The OpenAI client needs a PSR-18 HTTP client too.

Use the tools with chat

Pass Datacircle::chatTools() as tools. Each time the model calls tools, add the model's message and the tool answers to $messages. Then send $messages to the model again:

use Datacircle\OpenAI\Datacircle;

$client = OpenAI::client(getenv('OPENAI_API_KEY'));

$messages = [['role' => 'user', 'content' => 'Who are the 3 best providers for the email-finder API?']];
do {
    $response = $client->chat()->create([
        'model' => 'gpt-5.6-luna',
        'messages' => $messages,
        'tools' => Datacircle::chatTools(),
    ]);
    $message = $response->choices[0]->message;
    $messages[] = $message->toArray();
    array_push($messages, ...Datacircle::toolMessages($message));
} while ($message->toolCalls !== []);

echo $message->content, "\n";

Datacircle::toolMessages() answers Datacircle's calls and skips calls to other tools. If you add tools of your own, answer their calls yourself. Datacircle::handles($name) tells you which calls are Datacircle's. Datacircle::toolMessage($toolCall) answers one call. To stream with createStreamed(), build each tool call from the deltas as an array with an id and a function. Pass each tool call array to Datacircle::toolMessage().

Use the tools with responses

Pass Datacircle::responsesTools() as tools. Each time the model calls tools, add the model's output items and the tool outputs to $input. Then send $input to the model again:

use Datacircle\OpenAI\Datacircle;

$client = OpenAI::client(getenv('OPENAI_API_KEY'));

$input = [['role' => 'user', 'content' => 'Who are the 3 best providers for the email-finder API?']];
do {
    $response = $client->responses()->create([
        'model' => 'gpt-5.6-luna',
        'input' => $input,
        'tools' => Datacircle::responsesTools(),
    ]);
    $outputs = Datacircle::functionCallOutputs($response);
    foreach ($response->output as $item) {
        $input[] = $item->toArray();
    }
    array_push($input, ...$outputs);
} while ($outputs !== []);

echo $response->outputText, "\n";

OpenAI's API stores each response. On the next call, you can send only the tool outputs and add 'previous_response_id' => $response->id. If you stream with createStreamed(), pass the response of the response.completed event to Datacircle::functionCallOutputs().

Make each call yourself

You can make each call without a model. You get the tool's answer as an array:

use Datacircle\OpenAI\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, $arguments) runs one tool call by name. Datacircle::run() returns the answer as JSON text, ready to pass to your model.

What the model reads

Each tool gives the model a JSON object as text. 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\OpenAI\Client(http: $httpClient) as the last argument of toolMessages(), functionCallOutputs() 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

MIT license.