cheinisch/openrouter-php-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cheinisch/openrouter-php-client

最新稳定版本:v0.2.2

Composer 安装命令:

composer require cheinisch/openrouter-php-client

包简介

Modern, lightweight PHP client for the OpenRouter.ai API. Provides a simple interface for chat completions, text generation, and custom LLM endpoints.

README 文档

README

It’s a lightweight PHP client for the OpenRouter.ai API that lets you call chat models with a single static method or a simple client, returning the plain text answer. It supports optional attribution headers (Referer/Title), works with many models (e.g., GPT-4o-mini, Claude 3.5, Gemini 2.5, Mistral), and installs via Composer.

Requirements

  • PHP >= 8.1
  • Composer
  • guzzlehttp/guzzle (installed automatically)

Installation

composer require cheinisch/openrouter-php-client

Usage

  1. Minimal (static convenience method)
<?php
require __DIR__.'/vendor/autoload.php';

use cheinisch\OpenRouterClient;

$apiKey = getenv('OPENROUTER_API_KEY') ?: 'sk-or-...';
echo Client::OpenRouterChat($apiKey, 'openai/gpt-4o-mini', 'Say only: OK');
  1. With optional attribution headers (Referer / Title)
<?php
require __DIR__.'/vendor/autoload.php';

use cheinisch\OpenRouterClient;

$apiKey  = getenv('OPENROUTER_API_KEY');
$model   = 'mistralai/mistral-small';
$prompt  = 'Give me one short fun fact about PHP.';
$referer = 'https://example.com'; // optional
$title   = 'My PHP App';               // optional

echo OpenRouterClient::OpenRouterChat($apiKey, $model, $prompt, $referer, $title);

Note: The static method OpenRouterChat($apiKey, $model, $prompt, ?$referer = null, ?$title = null) is a wrapper for chat(...) and returns only the plain answer string.

Available Language Models

  • anthropic/claude-3.5-sonnet
  • google/gemini-2.5-flash
  • mistralai/mistral-small
  • openai/gpt-4o-mini
  • x-ai/grok-3-mini
  • ... and a lot more

统计信息

  • 总下载量: 211
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-04