Releases: cheinisch/OpenRouter-php-Client
Releases · cheinisch/OpenRouter-php-Client
Update README and CHANGELOG for v0.3
What's Changed
Breaking Changes
chat()now accepts an optional 4th parameter$options []— existing calls with 1–3 arguments are fully backwards compatiblechatEx()returns anarrayinstead ofstring— usechat()if you need a plain string response
New Features
chatEx()— extended chat completion returning a full result array:
id,content,finish_reason,tool_calls,reasoning,usagestream()— SSE streaming support via callbackfn(string $delta, bool $done): voidstructuredChat()— JSON Schema validated responses, returns decoded PHP array directlygetGenerationStats()— fetch token counts and cost asynchronously via/api/v1/generation- Tool Calling —
tools,tool_choice,parallel_tool_calls - Structured Outputs —
response_formatwithjson_objectandjson_schemamodes - Plugins —
web,file-parser,response-healing,context-compression - Provider Routing —
providerobject withsort,data_collection,allow,ignore - Reasoning Models —
reasoningparameter with effort levels for Claude 3.7+, o1/o3 - Observability —
session_idtracking viax-session-idheader - Output Modalities —
modalitiesparameter (text,audio,image)
Improvements
chat()is now a thin wrapper aroundchatEx()— no duplicated logic- Replaced deprecated
max_tokenswithmax_completion_tokensthroughout - Error handling now parses structured API error body (
error.message,error.code) - All runtime exception messages translated to English
Installation
composer require cheinisch/openrouter-php-clientQuick Example
// Simple – unchanged from previous versions
$client = new OpenRouterClient($apiKey);
$text = $client->chat([['role' => 'user', 'content' => 'Hello!']], 'openai/gpt-4o-mini');
// Extended – new in v0.3
$result = $client->chatEx(
[['role' => 'user', 'content' => 'Hello!']],
'openai/gpt-4o-mini',
['plugins' => [['id' => 'web']]]
);
echo $result['content'];
echo $result['usage']['total_tokens'];Full Changelog: v0.2.2...v0.3
v0.2.2
v0.2.1
v0.2
v0.1.1
Full Changelog: v0.1.0...v0.1.1
v0.1.0
Full Changelog: v0.0.0.5...v0.1.0
v0.0.0.5
v0.0.0.4
v0.0.0.3
v0.0.0.2: Add OpenRouterChat convenience method and README example
Introduces the OpenRouterChat static method to simplify chat API usage by requiring only API key, model, and prompt. Updates README with usage instructions and an example.