Download the PHP package fholbrook/php-openrouter-client without Composer

On this page you can find all versions of the php package fholbrook/php-openrouter-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-openrouter-client

PHP OPENROUTER CLIENT


This package provides an easy-to-use interface for integrating OpenRouter into your PHP applications. OpenRouter is a unified interface for Large Language Models (LLMs) that allows you to interact with various AI models through a single API.

Table of Contents

Special thanks to Moe Mizrak for his work on laravel-openrouter. This package is a derivative of his work.

Installation

Install via Composer:

Requirements

This is a low dependency package, but you need to ensure that your environment meets the following requirements:

Configuration

First, construct your configuration class and pass it to the client class:

If you're using symfony, you can configure the OpenRouterConfig as a service in your services.yaml file:

Usage

This package facilitates several patterns, it's up to you to choose the one that best fits your application. The DTO objects provided the package are used to structure requests to OpenRouter and responses from OpenRouter.

Understanding ChatRequest DTO

The ChatRequest class is used to encapsulate the data required for making chat requests to the OpenRouter API. Here's a breakdown of the key properties:

Understanding the Chat DTO

The Chat class is used to model a chat conversation between the user and the AI. It contains the following properties:

Understanding Message DTO

The Message class is used to model a back-and-forth conversation between the user and the AI. It contains the following properties:

Creating a ChatRequest

This is a sample ChatRequest instance:

You can also create a ChatRequest instance using the Chat object:

Maintaining Conversation Continuity

If you want to maintain conversation continuity meaning that historical chat will be remembered and considered for your new chat request, you simply need to pass the Chat object on subsequent calls:

Serialization/Deserialization

At anytime you can store the chat object in whatever durable storage you prefer by serializing/deserializing it:

Structured Output

(Please also refer to OpenRouter Document Structured Output for models supporting structured output, also for more details)

If you want to receive the response in a structured format, you can specify the type property for response_format (ChatData object.

Additionally, it's recommended to set the require_parameters property for provider (ChatData object.

You can also specify the response_format as json_schema to receive the response in a specified schema format (Advisable to set 'strict' => true in json_schema array for strict schema):

[!TIP] You can also use prompt engineering to obtain structured output and control the format of responses.

Function Calling

You can also use the tool_choice and tools properties to allow the LLM to call tools. The tool_choice property can be set to auto or manual to automatically or manually select the tool to use. The tools property is an array of ToolCall objects that specify the tool to call and the parameters to pass to the tool

Here's how to define tools:

Contributing

We welcome contributions! If you'd like to improve this package, simply create a pull request with your changes. Your efforts help enhance its functionality and documentation.

License

PHP OpenRouter Client is an open-sourced software licensed under the MIT license.


All versions of php-openrouter-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-json Version *
ext-fileinfo Version *
guzzlehttp/guzzle Version ^7.9
caseyamcl/guzzle_retry_middleware Version ^2.12
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fholbrook/php-openrouter-client contains the following files

Loading the files please wait ...