PHPackages                             idpromogroup/laravel-openai-responses - 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. idpromogroup/laravel-openai-responses

ActiveLibrary[API Development](/categories/api)

idpromogroup/laravel-openai-responses
=====================================

Laravel package for standardizing OpenAI API responses

055PHP

Since May 29Pushed 1mo agoCompare

[ Source](https://github.com/iljainc/laravel-openai-responses)[ Packagist](https://packagist.org/packages/idpromogroup/laravel-openai-responses)[ RSS](/packages/idpromogroup-laravel-openai-responses/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel OpenAI Responses
========================

[](#laravel-openai-responses)

A Laravel package for standardizing OpenAI API responses in your applications.

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

[](#installation)

```
composer require idpromogroup/laravel-openai-responses
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Idpromogroup\LaravelOpenaiResponses\Services\LorService;

$service = new LorService($externalKey, 'Your message here');
$result = $service->setModel('gpt-4o-mini')
    ->setInstructions('You are a helpful assistant')
    ->execute();

if ($result->success) {
    echo $result->data;
}
```

### Working with Files

[](#working-with-files)

The package supports file attachments for analysis, processing, and discussion:

**Supported file types:**

- Images: JPG, PNG, WEBP
- Documents: PDF only

**File type restrictions:**

- Only images (JPG/PNG/WEBP) and PDF files are accepted
- Unsupported formats will be rejected with error message

#### Upload and Attach Local Files

[](#upload-and-attach-local-files)

```
$service = new LorService($externalKey, 'Analyze this document')
    ->setModel('gpt-4o-mini')
    ->attachLocalFile(storage_path('app/documents/report.pdf'));

$result = $service->execute();
```

#### Attach Already Uploaded Files

[](#attach-already-uploaded-files)

```
// Upload file first
$apiService = app(LorApiService::class);
$uploadResult = $apiService->uploadFile('/path/to/file.pdf', 'assistants');
$fileId = $uploadResult['id'];

// Then attach to conversation
$service = new LorService($externalKey, 'Discuss this file')
    ->attachFile($fileId)
    ->execute();
```

#### Attach Multiple Files

[](#attach-multiple-files)

```
$service = new LorService($externalKey, 'Compare these documents')
    ->attachFileIds(['file_123', 'file_456'])
    ->attachLocalFile(storage_path('app/contract.docx'))
    ->execute();
```

#### Custom Tools for File Processing

[](#custom-tools-for-file-processing)

```
$service = new LorService($externalKey, 'Extract data from spreadsheet')
    ->attachFile($fileId)
    ->execute();
```

**Note**:

- Images are sent as `input_image` type to OpenAI
- PDF files are sent as `input_file` type to OpenAI
- Unsupported file formats will be rejected immediately

### Using Templates

[](#using-templates)

```
$service = new LorService($externalKey, 'Your message')
    ->useTemplate('analysis_template') // by name
    ->execute();

// Or by ID
$service->useTemplate(1);
```

### Conversation Mode

[](#conversation-mode)

```
$service = new LorService($externalKey, 'Hello')
    ->setConversation('user123')
    ->execute();

// Subsequent messages will continue the conversation
$service = new LorService($externalKey, 'Follow up question')
    ->setConversation('user123')
    ->execute();
```

### Function Calls

[](#function-calls)

Configure function handler in `config/openai-responses.php`:

```
'function_handler' => App\Services\MyFunctionHandler::class,
```

Your handler should implement the `execute` method:

```
class MyFunctionHandler
{
    public function execute(string $functionName, array $args)
    {
        switch ($functionName) {
            case 'get_weather':
                return $this->getWeather($args['location']);
            default:
                return ['error' => 'Unknown function'];
        }
    }
}
```

### Advanced Configuration

[](#advanced-configuration)

```
$service = new LorService($externalKey, 'Your message')
    ->setModel('gpt-4o-mini')
    ->setInstructions('Custom instructions')
    ->setTemperature(0.7)
    ->setTools([
        ['type' => 'function', 'function' => [...]]
    ])
    ->setJSONSchema([
        'type' => 'object',
        'properties' => [...]
    ])
    ->execute();
```

File Upload API
---------------

[](#file-upload-api)

Direct file upload to OpenAI:

```
use Idpromogroup\LaravelOpenaiResponses\Services\LorApiService;

$apiService = new LorApiService();
$result = $apiService->uploadFile('/path/to/file.pdf', 'assistants');

if ($result) {
    $fileId = $result['id'];
    // Use $fileId in subsequent requests
}
```

Supported file purposes:

- `assistants` (default) - for Assistant API
- `fine-tune` - for fine-tuning
- `batch` - for batch processing

Usage and cost tracking
-----------------------

[](#usage-and-cost-tracking)

After each successful `/v1/responses` call, token counts and estimated **USD** costs are written to `lor_request_logs`: `input_cost`, `cached_input_cost`, `output_cost`, `total_cost` (migrations `2026_05_19_*`, `2026_05_24_*`). Prices come from `config/openai-responses.php` under `prices` (per 1M tokens; keys are model prefixes so `gpt-4o-mini-2024-07-18` matches `gpt-4o-mini`).

- Disable with `OPENAI_RESPONSES_BILLING=false` or `billing.enabled` in config.
- If no price row matches the response model, tokens are still stored and cost columns stay `null`.

Billing context (optional, all nullable for backward compatibility):

```
$service->setBillingContext(billingSourceCode: 0, billingUser: 42) // codes defined by host app
    ->setApiKey($userOpenAiKey) // optional; default: template → config
    ->execute();
```

Stored on each log row: `billing_source_code`, `billing_user`, `api_key_hash` (sha256 of the key used, not the secret).

Query logs:

```
use Idpromogroup\LaravelOpenaiResponses\Facades\Lor;

$sum = Lor::usage()
    ->forExternalKey($externalKey)
    ->betweenDates(now()->startOfMonth(), now())
    ->whereNotNull('total_cost')
    ->sum('total_cost');
```

License
-------

[](#license)

MIT License

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance61

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1195810?v=4)[Ilya](/maintainers/iljainc)[@iljainc](https://github.com/iljainc)

---

Top Contributors

[![iljainc](https://avatars.githubusercontent.com/u/1195810?v=4)](https://github.com/iljainc "iljainc (40 commits)")

### Embed Badge

![Health badge](/badges/idpromogroup-laravel-openai-responses/health.svg)

```
[![Health](https://phpackages.com/badges/idpromogroup-laravel-openai-responses/health.svg)](https://phpackages.com/packages/idpromogroup-laravel-openai-responses)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k16](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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