adachsoft / ai-integration-openrouter
OpenRouter integration for adachsoft/ai-integration.
Package info
gitlab.com/a.adach/ai-integration-openrouter
pkg:composer/adachsoft/ai-integration-openrouter
Requires
- php: ^8.4
- adachsoft/ai-integration: ^0.8
Requires (Dev)
- adachsoft/php-code-style: ^0.5.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^13.0
- rector/rector: ^2.6
- symplify/phpstan-rules: ^14.12
- vlucas/phpdotenv: ^5.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-08-29 01:49:49 UTC
README
This package integrates OpenRouter with the ToolCallingChatSpiInterface from adachsoft/ai-integration through OpenRouter's OpenAI-compatible API.
Requirements
- PHP 8.4 or newer
adachsoft/ai-integration0.8 or newer
Installation
composer require adachsoft/ai-integration-openrouter
Usage
Create an OpenRouterConfigVo and pass it to OpenRouterToolCallingChatSpiFactory:
use AdachSoft\AiIntegrationOpenRouter\Config\OpenRouterConfigVo;
use AdachSoft\AiIntegrationOpenRouter\OpenRouterToolCallingChatSpiFactory;
$config = new OpenRouterConfigVo(apiKey: 'your-openrouter-api-key');
$spi = new OpenRouterToolCallingChatSpiFactory($config)->create();
The factory returns a ToolCallingChatSpiInterface implementation. The default endpoint is:
https://openrouter.ai/api/v1/chat/completions
The model is supplied on each SPI request. It is not stored in the provider configuration.
HTTP status 402 is classified as exhausted provider resources and is exposed by the core integration as ResourceExhaustedSpiException.
Configuration
Copy .env.example to .env for production tests and set the API key:
OPENROUTER_API_KEY=...
The package does not read or configure a model from the environment.
Tests
Run unit tests without external network requests:
composer test
Run the production tool-calling test against OpenRouter:
composer test:production
The production test performs real, potentially billable requests using the openai/gpt-4.1-mini model.