PHPackages                             mahmoudnaggar/laravel-lmstudio - 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. mahmoudnaggar/laravel-lmstudio

ActiveLibrary[API Development](/categories/api)

mahmoudnaggar/laravel-lmstudio
==============================

Advanced LM Studio integration for Laravel - Run local LLMs with OpenAI-compatible API, model management, streaming, embeddings, and more

v1.0.0(6mo ago)4142MITPHPPHP ^8.1CI failing

Since Dec 24Pushed 6mo agoCompare

[ Source](https://github.com/mahmoudnaggar/laravel-lmstudio)[ Packagist](https://packagist.org/packages/mahmoudnaggar/laravel-lmstudio)[ RSS](/packages/mahmoudnaggar-laravel-lmstudio/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Laravel LM Studio
=================

[](#laravel-lm-studio)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4889fd6897533804b6dd900bf439a2162415e0f69ee2521b9fdbf9af66377968/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61686d6f75646e61676761722f6c61726176656c2d6c6d73747564696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mahmoudnaggar/laravel-lmstudio)[![Total Downloads](https://camo.githubusercontent.com/846f66a7c59a2b5b7d28e7ad9ecbbf11a02646f5e382a16cccf8d8a885aa9e58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61686d6f75646e61676761722f6c61726176656c2d6c6d73747564696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mahmoudnaggar/laravel-lmstudio)[![License](https://camo.githubusercontent.com/1c4c3ce03444a278c9c531c102b92b33799e49b0d036539639c4222227353354/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61686d6f75646e61676761722f6c61726176656c2d6c6d73747564696f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mahmoudnaggar/laravel-lmstudio)

**Advanced LM Studio integration for Laravel** - Run powerful local LLMs with a clean, Laravel-friendly API. Perfect for privacy-focused AI applications, offline development, and cost-effective AI solutions.

🚀 Features
----------

[](#-features)

- ✅ **OpenAI-Compatible API** - Drop-in replacement for OpenAI with local models
- ✅ **Model Management** - List, load, and switch between models programmatically
- ✅ **Streaming Support** - Real-time token streaming for chat responses
- ✅ **Embeddings** - Generate vector embeddings for semantic search
- ✅ **Conversation Management** - Maintain context across multiple messages
- ✅ **Health Monitoring** - Check LM Studio server status and loaded models
- ✅ **Token Counting** - Estimate and track token usage
- ✅ **Artisan Commands** - CLI tools for model management and testing
- ✅ **Comprehensive Testing** - Full test suite included
- ✅ **Laravel 10 &amp; 11** - Full support for latest Laravel versions

📋 Requirements
--------------

[](#-requirements)

- PHP 8.1 or higher
- Laravel 10.x or 11.x
- [LM Studio](https://lmstudio.ai/) installed and running
- LM Studio local server enabled (default: `http://localhost:1234`)

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require mahmoudnaggar/laravel-lmstudio
```

Publish the configuration file:

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

⚙️ Configuration
----------------

[](#️-configuration)

Update your `.env` file:

```
LMSTUDIO_BASE_URL=http://localhost:1234/v1
LMSTUDIO_TIMEOUT=120
LMSTUDIO_DEFAULT_MODEL=llama-3.2-3b-instruct
LMSTUDIO_MAX_TOKENS=2048
LMSTUDIO_TEMPERATURE=0.7
```

The configuration file (`config/lmstudio.php`) provides extensive customization options.

🎯 Quick Start
-------------

[](#-quick-start)

### Basic Chat

[](#basic-chat)

```
use MahmoudNaggar\LaravelLMStudio\Facades\LMStudio;

// Simple chat
$response = LMStudio::chat('What is Laravel?');
echo $response->content();

// With options
$response = LMStudio::chat('Explain quantum computing', [
    'model' => 'llama-3.2-3b-instruct',
    'temperature' => 0.8,
    'max_tokens' => 500,
]);
```

### Streaming Responses

[](#streaming-responses)

```
LMStudio::stream('Write a story about AI', function ($chunk) {
    echo $chunk; // Output each token as it arrives
});
```

### Conversations

[](#conversations)

```
$conversation = LMStudio::conversation();

$conversation->addMessage('user', 'Hello! My name is John.');
$response1 = $conversation->send();

$conversation->addMessage('user', 'What is my name?');
$response2 = $conversation->send(); // Will remember "John"
```

### Embeddings

[](#embeddings)

```
$embedding = LMStudio::embedding('Laravel is a PHP framework');
$vector = $embedding->vector(); // Array of floats
$dimensions = $embedding->dimensions(); // 384, 768, etc.
```

### Model Management

[](#model-management)

```
// List available models
$models = LMStudio::models()->list();

// Get loaded model
$currentModel = LMStudio::models()->loaded();

// Load a specific model
LMStudio::models()->load('mistral-7b-instruct');

// Unload current model
LMStudio::models()->unload();
```

### Health Checks

[](#health-checks)

```
// Check if LM Studio is running
if (LMStudio::health()->isHealthy()) {
    echo "LM Studio is running!";
}

// Get detailed status
$status = LMStudio::health()->status();
echo "Server: " . $status['server'];
echo "Model: " . $status['model'];
```

🛠️ Artisan Commands
-------------------

[](#️-artisan-commands)

### List Models

[](#list-models)

```
php artisan lmstudio:models
```

### Test Connection

[](#test-connection)

```
php artisan lmstudio:test
```

### Chat from CLI

[](#chat-from-cli)

```
php artisan lmstudio:chat "What is the meaning of life?"
```

### Load Model

[](#load-model)

```
php artisan lmstudio:load mistral-7b-instruct
```

📚 Advanced Usage
----------------

[](#-advanced-usage)

### Custom System Prompts

[](#custom-system-prompts)

```
$response = LMStudio::chat('Hello', [
    'system' => 'You are a helpful coding assistant specializing in Laravel.',
]);
```

### Function Calling (Tool Use)

[](#function-calling-tool-use)

```
$response = LMStudio::chat('What is the weather in Paris?', [
    'tools' => [
        [
            'type' => 'function',
            'function' => [
                'name' => 'get_weather',
                'description' => 'Get current weather',
                'parameters' => [
                    'type' => 'object',
                    'properties' => [
                        'location' => ['type' => 'string'],
                    ],
                ],
            ],
        ],
    ],
]);

if ($response->hasToolCalls()) {
    $toolCalls = $response->toolCalls();
    // Process tool calls...
}
```

### Token Counting

[](#token-counting)

```
$text = "This is a sample text";
$tokens = LMStudio::countTokens($text);

if (LMStudio::withinTokenLimit($text, 1000)) {
    // Process the text
}
```

### Batch Processing

[](#batch-processing)

```
$prompts = ['Question 1', 'Question 2', 'Question 3'];

$responses = collect($prompts)->map(function ($prompt) {
    return LMStudio::chat($prompt);
});
```

### Error Handling

[](#error-handling)

```
use MahmoudNaggar\LaravelLMStudio\Exceptions\LMStudioException;

try {
    $response = LMStudio::chat('Hello');
} catch (LMStudioException $e) {
    Log::error('LM Studio error: ' . $e->getMessage());
    // Fallback logic
}
```

🧪 Testing
---------

[](#-testing)

Run the test suite:

```
composer test
```

Run code formatting:

```
composer format
```

📖 Documentation
---------------

[](#-documentation)

For detailed documentation, visit the [Wiki](https://github.com/mahmoudnaggar/laravel-lmstudio/wiki).

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

🔒 Security
----------

[](#-security)

If you discover any security-related issues, please email  instead of using the issue tracker.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

🙏 Credits
---------

[](#-credits)

- [Mahmoud Naggar](https://github.com/mahmoudnaggar)
- [All Contributors](../../contributors)

🌟 Show Your Support
-------------------

[](#-show-your-support)

If this package helps you, please consider giving it a ⭐️ on GitHub!

📞 Support
---------

[](#-support)

- **Issues**: [GitHub Issues](https://github.com/mahmoudnaggar/laravel-lmstudio/issues)
- **Discussions**: [GitHub Discussions](https://github.com/mahmoudnaggar/laravel-lmstudio/discussions)

---

Made with ❤️ for the Laravel community

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance68

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Unknown

Total

1

Last Release

184d ago

### Community

Maintainers

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

---

Top Contributors

[![mahmoudnaggar](https://avatars.githubusercontent.com/u/97238001?v=4)](https://github.com/mahmoudnaggar "mahmoudnaggar (6 commits)")

---

Tags

laravelaistreamingmachine learningllamamistrallmstudioembeddingslocal-llmphilm-studiolocal-aiopenai-compatible

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mahmoudnaggar-laravel-lmstudio/health.svg)

```
[![Health](https://phpackages.com/badges/mahmoudnaggar-laravel-lmstudio/health.svg)](https://phpackages.com/packages/mahmoudnaggar-laravel-lmstudio)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76518.2M120](/packages/laravel-mcp)[spatie/laravel-health

Monitor the health of a Laravel application

87411.3M153](/packages/spatie-laravel-health)[spatie/laravel-export

Create a static site bundle from a Laravel app

672139.5k6](/packages/spatie-laravel-export)[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

5019.3k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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