PHPackages                             ablancodev/simple-llm-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ablancodev/simple-llm-php

ActiveLibrary

ablancodev/simple-llm-php
=========================

Una librería PHP simple para interactuar con ChatGPT, Claude y Gemini

05PHP

Since Aug 16Pushed 9mo agoCompare

[ Source](https://github.com/ablancodev/simple-llm-php)[ Packagist](https://packagist.org/packages/ablancodev/simple-llm-php)[ RSS](/packages/ablancodev-simple-llm-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simple LLM PHP Client
=====================

[](#simple-llm-php-client)

A simple PHP library to interact with major LLM providers: OpenAI (ChatGPT), Anthropic (Claude), Google (Gemini), and xAI (Grok).

Features
--------

[](#features)

- ✅ Simple and clean API
- ✅ Support for multiple LLM providers
- ✅ Easy model switching
- ✅ Secure API key management
- ✅ Production-ready with multiple configuration options
- ✅ Zero dependencies besides HTTP client

Installation
------------

[](#installation)

```
composer require ablancodev/simple-llm-php
```

Configuration
-------------

[](#configuration)

The library offers three ways to configure API keys:

### Option 1: Using .env file (Development)

[](#option-1-using-env-file-development)

1. Copy the `.env.example` file to `.env`:

```
cp .env.example .env
```

2. Configure your API keys in the `.env` file:

```
# OpenAI/ChatGPT
OPENAI_API_KEY=your-openai-api-key-here
OPENAI_MODEL=gpt-4o-mini

# Anthropic/Claude
ANTHROPIC_API_KEY=your-anthropic-api-key-here
ANTHROPIC_MODEL=claude-3-5-sonnet-20241022

# Google Gemini
GEMINI_API_KEY=your-gemini-api-key-here
GEMINI_MODEL=gemini-1.5-flash

# xAI/Grok
XAI_API_KEY=your-xai-api-key-here
XAI_MODEL=grok-beta
```

⚠️ **SECURITY WARNING**: Never commit `.env` files to version control or upload them to public directories.

### Option 2: Environment Variables (Production)

[](#option-2-environment-variables-production)

Configure your API keys as environment variables in your server (Apache, Nginx, etc.) and access them using `getenv()`.

### Option 3: Direct Configuration

[](#option-3-direct-configuration)

Pass API keys directly when initializing providers (useful for dynamic configurations).

Basic Usage
-----------

[](#basic-usage)

### Option 1: Using .env file (Development)

[](#option-1-using-env-file-development-1)

```
