torounit / ai-provider-for-lm-studio
LM Studio AI Provider for the PHP AI Client SDK.
Package info
github.com/torounit/ai-provider-for-lm-studio
pkg:composer/torounit/ai-provider-for-lm-studio
Requires
- php: >=7.4
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- phpcompatibility/php-compatibility: dev-develop
- phpstan/phpstan: ~2.1
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.7 || ^4.0
- wordpress/php-ai-client: ^1.4
Suggests
- wordpress/php-ai-client: Required. The core PHP AI Client SDK that this provider extends.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-03 04:55:06 UTC
README
LM Studio AI Provider for the PHP AI Client SDK.
Requirements
- PHP 8.3+
- wordpress/php-ai-client ^1.4 (bundled with WordPress 7.2+)
- LM Studio running locally with the server enabled
Installation
As a Composer Package
composer require torounit/ai-provider-for-lm-studio
As a WordPress Plugin
- Upload the plugin files to
/wp-content/plugins/ai-provider-for-lm-studio/ - Activate the plugin through the Plugins menu in WordPress
- Start LM Studio and enable the local server (Developer tab → Start Server)
Configuration
| Variable | Default | Description |
|---|---|---|
LM_STUDIO_SERVER_URL |
http://localhost:1234 |
LM Studio server URL (scheme + host + port, no API path) |
Both environment variables and PHP constants (e.g. define('LM_STUDIO_SERVER_URL', '...') in wp-config.php) are supported.
Usage
Composer (standalone)
<?php require __DIR__ . '/vendor/autoload.php'; use WordPress\AiClient\AiClient; use ToroUnit\LmStudioAiProvider\Provider\LmStudioProvider; // putenv('LM_STUDIO_SERVER_URL=http://localhost:1234'); $registry = AiClient::defaultRegistry(); $registry->registerProvider(LmStudioProvider::class); // List available models $models = LmStudioProvider::modelMetadataDirectory()->listModelMetadata(); foreach ($models as $model) { echo $model->getId() . "\n"; } // Generate text $result = AiClient::prompt('Hello, who are you?') ->usingProvider('lm_studio') ->generateText(); echo $result . "\n"; // Generate embeddings (an embedding model must be loaded in LM Studio) $embeddings = AiClient::input(['Hello', 'World']) ->usingProviderModel('lm_studio', 'text-embedding-nomic-embed-text-v1.5') ->generateEmbeddings();
WordPress Plugin
After activating the plugin, the LM Studio provider is automatically registered with the AI Client. Use the AI Client API as usual:
use WordPress\AiClient\AiClient; $result = AiClient::prompt('Hello, who are you?') ->usingProvider('lm_studio') ->generateText();
Embeddings are generated through the WordPress 7.2 embedding API. A model must always be specified, since vectors are only comparable when produced by the same model:
$embedding = wp_ai_client_embedding('Hello, world') ->using_provider_model('lm_studio', 'text-embedding-nomic-embed-text-v1.5') ->generate_embedding(); if (is_wp_error($embedding)) { // Handle the error. }
Only text inputs are supported. The dimensions option is not supported: LM Studio's embeddings API does not accept it and always returns the model's native vector size, so requests that set using_dimensions() are rejected instead of silently returning vectors of a different size.
License
GPL-2.0-or-later