adachsoft / ai-integration-gemini-via-openai
Gemini provider for adachsoft/ai-integration using the official OpenAI-compatible endpoint.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/adachsoft/ai-integration-gemini-via-openai
Requires
- php: >=8.3
- adachsoft/ai-integration: 0.6.1
- guzzlehttp/guzzle: ^7.0 || ^8.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
This package is not auto-updated.
Last update: 2026-01-21 02:16:23 UTC
README
Gemini provider for adachsoft/ai-integration using the official OpenAI-compatible chat completions endpoint exposed by Google.
This package exposes a ready-to-use SPI provider that can be registered under the id gemini-via-openai in the core ToolCallingChatFacadeBuilder and used for tool-calling chat scenarios.
Installation
composer require adachsoft/ai-integration adachsoft/ai-integration-gemini-via-openai
Configuration
Set the following environment variable (for example in your .env file at the project root):
GOOGLE_GEMINI_API_KEY– API key for the Gemini OpenAI-compatible endpoint.
Usage
use AdachSoft\AiIntegration\PublicApi\Builder\ToolCallingChatFacadeBuilder;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\ChatMessageDto;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\Collection\ChatMessageDtoCollection;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\Collection\ToolDefinitionDtoCollection;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\ToolCallingChatRequestDto;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\ToolDefinitionDto;
use AdachSoft\AiIntegrationGeminiViaOpenAi\GeminiViaOpenAiToolCallingChatSpiFactory;
$apiKey = getenv('GOOGLE_GEMINI_API_KEY');
$spi = GeminiViaOpenAiToolCallingChatSpiFactory::create($apiKey);
$facade = ToolCallingChatFacadeBuilder::create()
->withSpiProvider('gemini-via-openai', $spi)
->build();
$tools = new ToolDefinitionDtoCollection([
new ToolDefinitionDto(
name: 'echo_tool',
description: 'Echoes back the provided input string.',
parametersSchema: [
'type' => 'object',
'properties' => [
'text' => [
'type' => 'string',
'description' => 'Text to echo back',
],
],
'required' => ['text'],
],
),
]);
$messages = new ChatMessageDtoCollection([
ChatMessageDto::createUserMessage('Call echo_tool with some example text.'),
]);
$request = new ToolCallingChatRequestDto(
providerId: 'gemini-via-openai',
modelId: 'gemini-2.0-flash',
messages: $messages,
tools: $tools,
);
$response = $facade->chat($request);
Smoke test
A simple smoke script is provided for manual end-to-end verification:
echo "GOOGLE_GEMINI_API_KEY=your_api_key_here" >> .env
php bin/smoke-gemini-via-openai-tool-chat
The script will perform a single tool-calling chat request using the gemini-2.0-flash model and print the response in JSON form.