Laravel
Laravel and PHP with an OpenAI-compatible uncensored API
Use Abliterator from Laravel with openai-php/laravel: point config/openai.php at Abliterator, call the OpenAI facade, stream with eventStream and fake calls in tests.
Install openai-php/laravel, then in config/openai.php set 'api_key' => env('ABL_API_KEY') and 'base_uri' => 'https://abliterator.ai/v1'. The OpenAI facade's chat()->create and chat()->createStreamed then call Abliterator.
openai-php/laravel wraps the community openai-php/client in a facade and reads its base URL from config, so Abliterator needs only a config change. Laravel's event stream responses handle SSE. PHP was not installed on the machine used to check this page, so the code was reviewed against the package source and Laravel docs rather than executed.
Install and configure
composer require openai-php/laravel
php artisan openai:install
echo 'ABL_API_KEY=sk-abl-v1-...' >> .env
Edit the published config/openai.php:
<?php
return [
'api_key' => env('ABL_API_KEY'),
'organization' => null,
'project' => null,
'base_uri' => env('ABL_BASE_URL', 'https://abliterator.ai/v1'),
'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 120),
];
The client keeps a full https:// URL as given; the /v1 must be part of it. Run php artisan config:clear after editing if config is cached.
Call Abliterator from a route
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use OpenAI\Laravel\Facades\OpenAI;
Route::post('/explain', function (Request $request) {
$validated = $request->validate(['snippet' => 'required|string|max:20000']);
$response = OpenAI::chat()->create([
'model' => 'kimi-k3.1-pro-abliterated',
'max_tokens' => 800,
'messages' => [
['role' => 'system', 'content' => 'You review PHP for security bugs. Name the CWE and show the fix.'],
['role' => 'user', 'content' => $validated['snippet']],
],
]);
return response()->json([
'review' => $response->choices[0]->message->content,
'tokens' => $response->usage->totalTokens,
]);
});
Stream with response()->eventStream
eventStream sends each yielded value as an SSE update event, stops when the client disconnects, and ends with </stream>:
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use OpenAI\Laravel\Facades\OpenAI;
Route::get('/brief', function (Request $request) {
$topic = $request->query('topic', 'business email compromise');
return response()->eventStream(function () use ($topic) {
$stream = OpenAI::chat()->createStreamed([
'model' => 'deepseek-v4.1-flash-abliterated',
'messages' => [
['role' => 'user', 'content' => "Write a fraud-awareness brief for finance staff about {$topic}."],
],
]);
foreach ($stream as $chunk) {
$text = $chunk->choices[0]->delta->content ?? null;
if ($text !== null) {
yield ['text' => $text];
}
}
});
});
Yield arrays, not raw strings: Laravel writes strings into the data: line as-is, so a delta containing a newline would break the event, while arrays are JSON-encoded onto one line. In the browser, new EventSource('/brief') with an update listener that parses each event and closes on </stream> renders it. Abliterator adds a final usage chunk with no choices, which the ?? null guard skips.
Fake Abliterator in tests
The facade can be swapped for a fake, so feature tests never call the network:
<?php
use OpenAI\Laravel\Facades\OpenAI;
use OpenAI\Resources\Chat;
use OpenAI\Responses\Chat\CreateResponse;
test('explain returns the model review', function () {
OpenAI::fake([
CreateResponse::fake([
'choices' => [['message' => ['content' => 'CWE-89: use a prepared statement.']]],
]),
]);
$this->postJson('/explain', ['snippet' => '$db->query("SELECT * FROM users WHERE id=" . $_GET["id"]);'])
->assertOk()
->assertJsonPath('review', 'CWE-89: use a prepared statement.');
OpenAI::assertSent(Chat::class, function (string $method, array $parameters): bool {
return $method === 'create' && $parameters['model'] === 'kimi-k3.1-pro-abliterated';
});
});
Troubleshooting
- 401 that mentions an OpenAI account.
base_uriis empty, so the client usedapi.openai.com/v1. Checkconfig/openai.phpand clear the config cache. - 404 from Abliterator.
base_urilacks/v1, or you calledOpenAI::responses(). Usehttps://abliterator.ai/v1andchat(). cURL error 28: Operation timed out.request_timeoutis too low for the answer length. Raise it, or stream.- The event stream arrives at the end. Something between PHP and the browser is buffering: PHP's
output_buffering, FastCGI buffering in nginx, or a CDN. SendX-Accel-Buffering: no(pass it ineventStream's headers if your setup needs it) and exclude the route from response compression. - Queue workers and long jobs. For batch work, call the facade from a queued job and set the job's
$timeoutaboverequest_timeout.
Frequently asked questions
Can I use OpenAI::responses() from the Laravel package with Abliterator?
No. The package README leads with the Responses API, but Abliterator serves Chat Completions only. Use OpenAI::chat()->create and chat()->createStreamed.
Do I have to edit config/openai.php?
Only to use ABL_API_KEY as the variable name. You can instead set OPENAI_API_KEY to your Abliterator key and OPENAI_BASE_URL to https://abliterator.ai/v1 in .env and leave the config untouched.
Why does Laravel time out after 30 seconds?
The package's request_timeout defaults to 30 seconds, which a long answer can exceed. Raise it in config/openai.php or with OPENAI_REQUEST_TIMEOUT, and stream long outputs.