openeuropa / gpt-at-ec-php-client
PHP API client to interact with European Commission GPT@EC.
Package info
github.com/openeuropa/gpt-at-ec-php-client
pkg:composer/openeuropa/gpt-at-ec-php-client
Requires
- php: ^8.3
- openai-php/client: ^0.15.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.9
- guzzlehttp/psr7: ^2.7
- phpunit/phpunit: ^12.3
This package is auto-updated.
Last update: 2026-07-23 09:26:26 UTC
README
This is an API client written in PHP to interact with the GPT@EC API.
Important notes
The GPT@EC API is very similar to the Open AI API.
Therefore, in order to ease the development, this library reuses the openai-client/php where possible,
or extends it if needed.
Since some parts of the openai-client/php are marked as internal, this library might become incompatible
with future versions of it. Consider locking the openai-client/php version, and update it to the latest
version reported as compatible in the test builds.
Install
Use Composer to require the library:
composer require openeuropa/gpt-at-ec-php-client
Make sure you have a PSR-18 client installed, or install one manually, e.g.:
composer require guzzlehttp/guzzle
The php-http/discovery plugin can also help installing and discovering a compatible PSR-18 client.
Usage
You can create a new API client using the factory class. All you need is a GPT@EC API key:
$api_key = getenv('KEY_AI_GPT_AT_EC'); $factory = new \Openeuropa\GptAtEcPhpClient\Factory(); $client = $factory->withApiKey($key)->make();
Now the client can be used to interact with the 3 available endpoints.
Chat
The Chat Completions API endpoint will generate a model response from a list of messages comprising a conversation.
create method
Create a chat completion. The full model response will be returned at once by the API.
$response = $client->chat()->create([ 'model' => 'gpt-4o', 'messages' => [ [ 'role' => 'system', 'content' => 'You are a helpful assistant.', ], [ 'role' => 'user', 'content' => 'Hello!', ], ]); echo $response->id; // "chatcmpl-0123456789abcdef0123456789ab" echo $result->object; // "chat.completion" echo $result->created; // 1755523764 echo $result->model; // "gpt-4o-2000-01-01" echo $response->choices[0]->message->role; // "assistant" echo $response->choices[0]->message->content; // "Hello! How can I assist you today?" echo $response->choices[0]->index; // 0 echo $response->choices[0]->finishReason; // "stop" echo $response->usage->promptTokens; // 9 echo $response->usage->completionTokens; // 10 echo $response->usage->totalTokens; // 19
createStreamed method
Create a chat completion. The response will be streamed back in parts as the model generates it.
$stream = $client->chat()->createStreamed([ 'model' => 'gpt-4o', 'messages' => [ [ 'role' => 'system', 'content' => 'You are a helpful assistant.', ], [ 'role' => 'user', 'content' => 'Hello!', ], ]); foreach ($stream as $chunk) { echo $chunk->id; // "chatcmpl-0123456789abcdef0123456789ab" echo $chunk->object; // "chat.completion.chunk" echo $chunk->created; // 1755530359 echo $chunk->model; // "meta-llama/Llama-3.3-70B-Instruct" echo $response->choices[0]->message->role; // "assistant" echo $response->choices[0]->message->content; // "Hello!", "How", "can", "I", "help", "you", "?" }
Models
Lists the various models available in the API.
A single method is available, list.
$response = $client->models()->list(); foreach ($response->data as $model) { echo $model->id; // "llama-3.3-70b-instruct" echo $model->name; // "LLama 3.3 70b instruct" echo $model->description; // "Very powerful open-weights model on par with the capabilities of GPT-4o for many types of tasks." print_r($model->sensitivityLevel); // ["PA", "SNC", "CU"] print_r($model->defaultFor); // ["SNC"] echo $model->created; // 1744201138356 echo $model->ownedBy; // "meta" echo $model->object; // "model" }
Quota consumption
Provides the quota consumption details for a specific AI model.
A single method is available, retrieve.
$response = $client->quotaConsumption()->retrieve('gpt-4o'); echo $response->consumedPromptTokens; // 1234 echo $response->consumedCompletionTokens; // 5678 echo $response->consumedTotalTokens; // 6912 echo $response->quota; // 100000
Tests
The library is full covered by unit tests using the PHPUnit framework. To run the tests, execute:
./vendor/bin/phpunit --coverage-html folder-for-coverage-results
Versioning
We use SemVer for versioning.