Download the PHP package ez-php/ai without Composer

On this page you can find all versions of the php package ez-php/ai. 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 ai

ez-php/ai

Multi-provider AI client for ez-php. Supports chat completions, streaming, tool calling, and embeddings across OpenAI, Anthropic, Gemini, and Mistral.


Installation

Requires PHP 8.5 and ez-php/http-client.


Configuration

Register AiServiceProvider in your application and add config/ai.php:

Driver options

AI_DRIVER value Description
openai OpenAI chat completions API
anthropic Anthropic Messages API
gemini Google Gemini generateContent API
mistral Mistral AI (OpenAI-compatible)
log Decorates another driver with error_log output
null Returns empty responses; useful in tests

Environment variables

Variable Default Description
AI_DRIVER null Active driver
OPENAI_API_KEY OpenAI API key
OPENAI_MODEL gpt-4o-mini Default OpenAI model
OPENAI_BASE_URL https://api.openai.com Base URL (Azure / proxy support)
ANTHROPIC_API_KEY Anthropic API key
ANTHROPIC_MODEL claude-sonnet-4-6 Default Anthropic model
ANTHROPIC_API_VERSION 2023-06-01 anthropic-version header value
GEMINI_API_KEY Google AI API key
GEMINI_MODEL gemini-2.0-flash Default Gemini model
MISTRAL_API_KEY Mistral API key
MISTRAL_MODEL mistral-small-latest Default Mistral model
MISTRAL_BASE_URL https://api.mistral.ai Mistral base URL
AI_LOG_INNER_DRIVER openai Driver wrapped by the log driver

Basic usage

Static facade

Direct driver injection


Building requests

AiRequest is immutable. All wither methods return new instances.


Messages


Streaming

Drivers that implement StreamingAiClientInterface support streaming responses.

All four production drivers (OpenAI, Anthropic, Gemini, Mistral) implement StreamingAiClientInterface.

Note: Streaming uses SSE post-hoc parsing — the full response body is buffered, then parsed line-by-line. True chunked transfer is not supported.


Tool calling

Define tools, attach them to the request, and handle tool calls in a loop.

Gemini note: Gemini does not assign separate IDs to tool calls. The function name is used as the call ID. Use the function name as toolCallId in tool result messages for Gemini conversations.

Streaming + tool calling: Tool calls are only parsed in complete(). The stream() path yields text chunks only.


Embeddings

Use OpenAiEmbeddingDriver or GeminiEmbeddingDriver directly — embeddings are not wired through AiServiceProvider or the Ai facade.

Driver Default model Endpoint
OpenAiEmbeddingDriver text-embedding-3-small POST /v1/embeddings
GeminiEmbeddingDriver text-embedding-004 POST /v1beta/models/{model}:embedContent

Response object


Logging decorator

Wrap any driver to log every request and response via error_log:

Or construct LogDriver manually with a custom logger closure:


OpenAI-compatible proxies and Azure

OpenAiDriver and MistralDriver accept a base_url config key, making them compatible with Azure OpenAI and any OpenAI-compatible proxy:


Testing

In unit tests, inject NullDriver or use FakeTransport from ez-php/http-client:

Use Ai::resetClient() in tearDown() when tests touch the static facade to prevent state leaking between test cases.


Quality suite

Start the development shell:


All versions of ai with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
ez-php/http-client Version ^1.0
ez-php/contracts Version ^1.0
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 ez-php/ai contains the following files

Loading the files please wait ...