PHPackages                             leandroferreirama/openai-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. [API Development](/categories/api)
4. /
5. leandroferreirama/openai-php

ActiveLibrary[API Development](/categories/api)

leandroferreirama/openai-php
============================

OpenAI PHP Assistant API

v1.0.5(1y ago)07MITPHPPHP ^8.1

Since Oct 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/leandroferreirama/openai-php)[ Packagist](https://packagist.org/packages/leandroferreirama/openai-php)[ RSS](/packages/leandroferreirama-openai-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

OpenAI PHP Client
=================

[](#openai-php-client)

This is a simple PHP client for interacting with the OpenAI API, allowing you to create assistants, manage threads, and send messages.

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

[](#installation)

You can install the package via Composer. Run the following command in your terminal:

```
composer require leandroferreirama/openai-php
```

### Environment Configuration

[](#environment-configuration)

Before you start using the package, create a copy of the `.env.example` file and rename it to `.env`. Then, paste your OpenAI API key into the `.env` file.

Usage
-----

[](#usage)

### Creating an Assistant

[](#creating-an-assistant)

You can create an assistant using the following code:

```
$client = new OpenAIClient();
$assistant = $client->getAssistant()->create(Model::GPT_4, 'Answer as if you were a tour guide.');
```

### Creating a Thread

[](#creating-a-thread)

To create a thread, use the following:

```
$thread = $client->getThread()->create();
```

### Sending Messages

[](#sending-messages)

Send messages to the assistant like this:

```
$response = $client->askAssistant($assistantId, $threadId, 'What are the best places to visit in Argentina?');
```

### Getting Responses

[](#getting-responses)

The assistant's response will be returned as a string:

```
echo $response;
```

Example
-------

[](#example)

You can find an example of usage in the `example/index.php` file.

License
-------

[](#license)

This project is licensed under the MIT License. See the LICENSE file for details.

---

Cliente PHP para OpenAI
=======================

[](#cliente-php-para-openai)

Este é um cliente PHP simples para interagir com a API da OpenAI, permitindo que você crie assistentes, gerencie threads e envie mensagens.

Instalação
----------

[](#instalação)

Você pode instalar o pacote via Composer. Execute o seguinte comando no seu terminal:

```
composer require leandroferreirama/openai-php
```

### Configuração do Ambiente

[](#configuração-do-ambiente)

Antes de começar a usar o pacote, crie uma cópia do arquivo `.env.example` e renomeie para `.env`. Em seguida, cole sua chave da API da OpenAI no arquivo `.env`.

Uso
---

[](#uso)

### Criando um Assistente

[](#criando-um-assistente)

Você pode criar um assistente usando o seguinte código:

```
$client = new OpenAIClient();
$assistant = $client->getAssistant()->create(Model::GPT_4, 'Responda como se você fosse um guia turístico.');
```

### Criando uma Thread

[](#criando-uma-thread)

Para criar uma thread, use o seguinte:

```
$thread = $client->getThread()->create();
```

### Enviando Mensagens

[](#enviando-mensagens)

Envie mensagens ao assistente assim:

```
$response = $client->askAssistant($assistantId, $threadId, 'Quais são os melhores lugares para visitar na Argentina?');
```

### Obtendo Respostas

[](#obtendo-respostas)

A resposta do assistente será retornada como uma string:

```
echo $response;
```

Exemplo
-------

[](#exemplo)

Você pode encontrar um exemplo de uso no arquivo `example/index.php`.

Licença
-------

[](#licença)

Este projeto é licenciado sob a Licença MIT. Veja o arquivo LICENSE para detalhes.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

567d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9093927f001f01d3538998e18e47b47c4c01ddc466103811b05e02964085067?d=identicon)[leandroferreirama](/maintainers/leandroferreirama)

---

Top Contributors

[![leandroferreirama](https://avatars.githubusercontent.com/u/88864424?v=4)](https://github.com/leandroferreirama "leandroferreirama (5 commits)")

### Embed Badge

![Health badge](/badges/leandroferreirama-openai-php/health.svg)

```
[![Health](https://phpackages.com/badges/leandroferreirama-openai-php/health.svg)](https://phpackages.com/packages/leandroferreirama-openai-php)
```

###  Alternatives

[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

640431.7k4](/packages/netflie-whatsapp-cloud-api)[showdoc/showdoc

ShowDoc is a tool greatly applicable for an IT team to share documents online

12.8k7.0k](/packages/showdoc-showdoc)[wrav/oembed

A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.

36205.0k3](/packages/wrav-oembed)[lucianotonet/groq-php

A powerful PHP library for seamless integration with the GroqCloud API

83124.5k6](/packages/lucianotonet-groq-php)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[unicodeveloper/jusibe-php-lib

Jusibe PHP Library

3417.4k1](/packages/unicodeveloper-jusibe-php-lib)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
