Search by

hemrajpal / php-ai-connect

hemrajstack

A simple PHP client for connecting to AI services.

Package info

github.com/hemrajpal/php-ai-connect

pkg:composer/hemrajpal/php-ai-connect

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-08-15 06:30 UTC

This package is auto-updated.

Last update: 2026-09-15 07:10:04 UTC


README

A simple PHP client for connecting to AI services.

Currently, Google Gemini is supported. More AI providers, such as Ollama, can be added in the future.

Features

  • Simple PHP implementation
  • Google Gemini support
  • cURL based API requests
  • Composer support
  • Laravel compatible
  • No unnecessary dependencies

Requirements

  • PHP 8.1+
  • PHP cURL extension
  • Composer
  • Gemini API key

Installation

Install the package using Composer:

composer require hemrajpal/php-ai-connect

API key

You need a Google Gemini API key to use this package.

Create a .env file in your application:

GEMINI_API_KEY=your_gemini_api_key_here

Plain PHP does not automatically load .env files. If your application already loads environment variables, use getenv() as shown below. Laravel users can use env().

Basic usage

<?php

require 'vendor/autoload.php';

use PhpAiConnect\GeminiClient;
use PhpAiConnect\Exception;

try {
    $gemini = new GeminiClient(
        getenv('GEMINI_API_KEY')
    );

    $response = $gemini->generate(
        'Explain Laravel dependency injection in simple words.'
    );

    echo $response->text();

} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Laravel

composer require hemrajpal/php-ai-connect
use PhpAiConnect\GeminiClient;

$gemini = new GeminiClient(
    env('GEMINI_API_KEY')
);

$response = $gemini->generate('Hello Gemini');

return $response->text();

Supported PHP Version

This package currently requires PHP >= 8.1.

Gemini API

This package communicates with Google's Gemini API using HTTP requests through PHP cURL.

The implementation intentionally stays simple so the code is easy to understand and extend.

Future Plans

  • Ollama support
  • Additional AI providers
  • PHPUnit tests
  • Improved response handling
  • More Gemini features

Project Structure

php-ai-connect/
│
├── src/
│   ├── GeminiClient.php
│   ├── Response.php
│   └── Exception.php
│
├── examples/
│   └── gemini.php
│
├── .env.example
├── .gitignore
├── composer.json
├── LICENSE
└── README.md

The package intentionally keeps the code small and easy to understand.

License

This project is licensed under the MIT License.

You are free to use, modify, distribute, and use the package in commercial projects.

See the LICENSE file for details.

Author

Hemraj Pal

GitHub: https://github.com/hemrajpal

Repository

https://github.com/hemrajpal/php-ai-connect

Made with PHP and cURL.