mmorand/laravel-apertus

Laravel package for the Swiss made Apertus LLM

Installs: 180

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/mmorand/laravel-apertus

0.1.1 2025-09-22 09:22 UTC

This package is auto-updated.

Last update: 2025-12-22 10:02:37 UTC


README

Apertus Logo

Laravel Client for Apertus LLM

Latest Version on Packagist Total Downloads

The Apertus AI PHP Client enables seamless integration with the Apertus AI API, providing straightforward access to Swiss AI models for chat completions and model management.

More informations about Apertus AI can be found on their website and API Reference.

Features

  • Chat Completions - Full conversation support with streaming
  • Model Management - List available models
  • Laravel Integration - Native Laravel support with Facades
  • Type Safety - Fully typed DTOs using Spatie Laravel Data
  • Modern PHP - Built with PHP 8.3+ and Saloon HTTP client

Installation

You can install the package via Composer:

composer require mmorand/laravel-apertus

You can publish the config file with:

php artisan vendor:publish --tag="apertus-config"

This is the contents of the published config file:

return [
    'api_key' => env('APERTUS_API_KEY'),
    'base_url' => env('APERTUS_BASE_URL', 'https://api.publicai.co'),
    'user_agent' => env('APERTUS_USER_AGENT', 'Apertus-Laravel-Client/1.0.0'),
    'timeout' => env('APERTUS_TIMEOUT', 60),
];

Add your Apertus API key to your .env file:

APERTUS_API_KEY=your_api_key_here
APERTUS_BASE_URL=https://api.publicai.co
APERTUS_USER_AGENT=MyApp/1.0
APERTUS_TIMEOUT=30

Get your API key from the Apertus AI Console.

Usage

Basic Setup

Create an instance of the Apertus client to start interacting with the API:

use Mmorand\Apertus\Apertus;
use Mmorand\Apertus\Enums\Model;

// Instantiate the client
$apertus = new Apertus(
    apiKey: config('apertus.api_key'),
    baseUrl: 'https://api.publicai.co',
    userAgent: 'MyApp/1.0'
);

// Or use the Facade (Laravel)
use Mmorand\Apertus\Facades\Apertus;

Apertus::chat();
Apertus::models();

Chat Completions

Create a chat completion:

use Mmorand\Apertus\Facades\Apertus;
use Mmorand\Apertus\Enums\Model;

$response = Apertus::chat()->create(
    model: Model::apertus8b,
    messages: [
        [
            'role' => 'user',
            'content' => 'Hello! Can you help me understand Swiss AI?',
        ]
    ],
    temperature: 0.7,
    maxTokens: 1000
);

/** @var \Mmorand\Apertus\Dto\Chat\ChatCompletionResponse $dto */
$dto = $response->dto();

Model Management

List available models:

$response = Apertus::models()->list();

/** @var \Mmorand\Apertus\Dto\Models\ModelsResponse $dto */
$dto = $response->dto();

Artisan Commands

List available models using Artisan:

php artisan apertus:models

Available Models

The following models are available in the Apertus API. You can use the Model enum in this package to refer to them.

Enum Case Model Name Documentation Link
Model::apertus8b 'swiss-ai/apertus-8b-instruct' Apertus 8b Docs
Model::apertus70b 'swiss-ai/apertus-70b-instruct' Apertus 70b Docs
use Mmorand\Apertus\Enums\Model;

Model::apertus8b  // swiss-ai/apertus-8b-instruct - Small Apertus model
Model::apertus70b // swiss-ai/apertus-70b-instruct - Complete Apertus model

Testing

Run the tests with:

composer test

Static Analysis

Analyze code with PHPStan:

composer analyse

Code Style

Fix code style with Laravel Pint:

composer format

Inspired by the excellent work of HelgeSverre with his Mistral package.

License

The MIT License (MIT). Please see License File for more information.

Disclaimer

Apertus AI and the Apertus logo are trademarks of their respective owners. This package is not affiliated with, endorsed by, or sponsored by Apertus AI. All trademarks and registered trademarks are the property of their respective owners.

See the Terms and Conditions for more information.