PHPackages                             encurio/openai-service - 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. encurio/openai-service

ActiveLibrary[API Development](/categories/api)

encurio/openai-service
======================

A flexible OpenAI integration for Laravel

v1.18(4mo ago)055MITPHPPHP &gt;=8.0CI failing

Since Mar 14Pushed 3w ago2 watchersCompare

[ Source](https://github.com/encurio/openai-service)[ Packagist](https://packagist.org/packages/encurio/openai-service)[ RSS](/packages/encurio-openai-service/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

OpenAI Service for Laravel (`encurio/openai-service`)
=====================================================

[](#openai-service-for-laravel-encurioopenai-service)

A Laravel package for working with OpenAI from application services.

The **Responses API** is now the recommended default for new implementations. Legacy **Chat Completions** and **Assistants v2 Threads/Runs** remain available for backward compatibility, but new projects should not build around Assistants/Threads.

Features
--------

[](#features)

- Responses API support for text, structured output, tools, conversation references, and model calls.
- Conversation helper methods for the current OpenAI conversation model.
- Legacy Chat Completions support.
- Legacy Assistants v2 Threads/Runs support, marked as deprecated in code.
- Embeddings, Moderations, Images, and Files helpers.
- Per-request API key override through `setProjectApiKey()` or request options.

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

[](#installation)

```
composer require encurio/openai-service
```

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

[](#configuration)

Publish the config file when you want to customize defaults:

```
php artisan vendor:publish --tag=openai-config
```

Recommended `.env` configuration:

```
OPENAI_API_KEY=your_openai_project_key
OPENAI_DEFAULT_MODEL=gpt-4.1-mini
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
OPENAI_IMAGE_MODEL=gpt-image-1
OPENAI_RETRIES=3
OPENAI_TIMEOUT=60
```

Backward-compatible keys still work, but should not be used for new projects:

```
OPENAI_API_KEY_COMPLETIONS=legacy_key
OPENAI_API_KEY_ASSISTANTS=legacy_key
```

Current recommended usage: Responses API
----------------------------------------

[](#current-recommended-usage-responses-api)

```
use Encurio\OpenAIService\Facades\OpenAI;

$response = OpenAI::response([
    'model' => 'gpt-4.1-mini',
    'input' => 'Write a short SEO-friendly product description for a reusable coffee filter.',
    'instructions' => 'Write concise, factual ecommerce copy.',
    'max_output_tokens' => 300,
]);

print_r($response);
```

Structured output
-----------------

[](#structured-output)

```
use Encurio\OpenAIService\Facades\OpenAI;

$response = OpenAI::response([
    'model' => 'gpt-4.1-mini',
    'input' => 'Extract the product name, material, and key benefit from: Stainless steel reusable coffee filter, dishwasher-safe, reduces paper waste.',
    'text' => [
        'format' => [
            'type' => 'json_schema',
            'name' => 'product_summary',
            'schema' => [
                'type' => 'object',
                'additionalProperties' => false,
                'properties' => [
                    'product_name' => ['type' => 'string'],
                    'material' => ['type' => 'string'],
                    'key_benefit' => ['type' => 'string'],
                ],
                'required' => ['product_name', 'material', 'key_benefit'],
            ],
        ],
    ],
]);

print_r($response);
```

Conversations
-------------

[](#conversations)

```
use Encurio\OpenAIService\Facades\OpenAI;

$conversationId = OpenAI::createConversation();

OpenAI::addConversationItem($conversationId, [
    'type' => 'message',
    'role' => 'user',
    'content' => [
        ['type' => 'input_text', 'text' => 'Remember that this customer prefers German invoices.'],
    ],
]);

$response = OpenAI::response([
    'model' => 'gpt-4.1-mini',
    'conversation' => $conversationId,
    'input' => 'Create the next customer support reply.',
]);
```

Images
------

[](#images)

```
use Encurio\OpenAIService\Facades\OpenAI;

$response = OpenAI::image([
    'prompt' => 'A clean ecommerce product photo of a reusable stainless steel coffee filter on a white background.',
    'model' => 'gpt-image-1',
    'size' => '1024x1024',
    'quality' => 'high',
    'output_format' => 'png',
]);

print_r($response);
```

For GPT image models, the package no longer sends `response_format=url` by default. Pass `response_format` only when you intentionally use an older image model that supports it.

Embeddings
----------

[](#embeddings)

```
use Encurio\OpenAIService\Facades\OpenAI;

$response = OpenAI::requestOpenAI([
    'type' => 'embedding',
    'model' => 'text-embedding-3-small',
    'input' => ['Your text to embed here'],
]);

print_r($response['data']);
```

Moderations
-----------

[](#moderations)

```
use Encurio\OpenAIService\Facades\OpenAI;

$response = OpenAI::requestOpenAI([
    'type' => 'moderation',
    'input' => 'Text to classify for policy violations',
]);

print_r($response['results']);
```

Legacy Chat Completions
-----------------------

[](#legacy-chat-completions)

`completion()` and `requestOpenAI(['type' => 'completion', ...])` remain available for existing projects.

```
use Encurio\OpenAIService\Facades\OpenAI;

$response = OpenAI::completion([
    'model' => 'gpt-4.1-mini',
    'messages' => [
        ['role' => 'user', 'content' => 'Tell me a joke.'],
    ],
    'temperature' => 0.9,
    'max_tokens' => 200,
]);

print_r($response);
```

Legacy Assistants v2 Threads/Runs
---------------------------------

[](#legacy-assistants-v2-threadsruns)

These methods remain in the package for backward compatibility, but are deprecated in code:

- `createThread()`
- `appendMessageToThread()`
- `startRun()`
- `pollUntilRunComplete()`
- `pollAndSubmitToolCalls()`
- `getThreadMessages()`
- `runThread()`

Use `response()`, `createConversation()`, `addConversationItem()`, and `listConversationItems()` for new implementations.

Error handling
--------------

[](#error-handling)

New Responses API methods throw `OpenAIRequestException` on HTTP or API failure. The exception exposes:

```
$exception->context();
$exception->status();
$exception->responseBody();
$exception->requestId();
```

Legacy `requestOpenAI()` keeps nullable failure behavior for backward compatibility.

License
-------

[](#license)

This package is licensed under the MIT License.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance87

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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 ~23 days

Recently: every ~72 days

Total

16

Last Release

129d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.0.1PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16121126?v=4)[encurio GmbH](/maintainers/encurio)[@encurio](https://github.com/encurio)

---

Top Contributors

[![srahmel](https://avatars.githubusercontent.com/u/14318776?v=4)](https://github.com/srahmel "srahmel (17 commits)")

### Embed Badge

![Health badge](/badges/encurio-openai-service/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[jasara/php-amzn-selling-partner-api

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

1348.7k1](/packages/jasara-php-amzn-selling-partner-api)

PHPackages © 2026

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