NAME

Langertha::Engine::LMStudioOpenAI - LM Studio via OpenAI-compatible API

VERSION

version 0.503

SYNOPSIS

use Langertha::Engine::LMStudioOpenAI;

# 1. Simple chat
my $lm_oai = Langertha::Engine::LMStudioOpenAI->new(
    url   => 'http://localhost:1234/v1',
    model => 'qwen2.5-7b-instruct-1m',
);

print $lm_oai->simple_chat('Hello from OpenAI-compatible endpoint');

# 2. Streaming
$lm_oai->simple_chat_stream(sub {
    print shift->content;
}, 'Write a haiku about Perl');

# 3. Embeddings (LM Studio serves /v1/embeddings when an embedding
#    model is loaded)
my $vector = $lm_oai->simple_embedding('Some text to embed');

# 4. MCP tool calling (LM Studio supports native tool calling via the
#    OpenAI-compatible /v1 endpoint for compatible models)
use Future::AsyncAwait;

my $lm_oai = Langertha::Engine::LMStudioOpenAI->new(
    url         => 'http://localhost:1234/v1',
    model       => 'qwen2.5-7b-instruct-1m',
    mcp_servers => [$mcp],
);

my $response = await $lm_oai->chat_with_tools_f('Add 7 and 15');

DESCRIPTION

Adapter for LM Studio's OpenAI-compatible local endpoint (/v1/chat/completions, /v1/models, /v1/embeddings).

Extends Langertha::Engine::OpenAIBase (which composes Langertha::Role::OpenAICompatible, Langertha::Role::OpenAPI, Langertha::Role::Models, Langertha::Role::Temperature, Langertha::Role::ResponseSize, Langertha::Role::SystemPrompt, Langertha::Role::ResponseFormat, Langertha::Role::Streaming, Langertha::Role::Chat, Langertha::Role::ReasoningEffort, and Langertha::Role::PromptCache); LMStudioOpenAI itself additionally composes Langertha::Role::Embedding (/v1/embeddings) and Langertha::Role::Tools (MCP tool calling).

"embedding_dimensions" in Langertha::Role::Embedding is not sent (it carps once): LM Studio does not document a dimensions field for /v1/embeddings, so whether it is honored is unknown.

Authentication is optional. If api_key (or LANGERTHA_LMSTUDIO_API_KEY) is set, it is sent as a bearer token.

Runtime metrics: LM Studio does not expose a Prometheus /metrics endpoint, so Langertha::Role::Runtime::MetricsPoll is intentionally not composed here. Sister engines that do (vLLM, SGLang, llama.cpp) expose Prometheus text-format metrics at the server root.

api_key

Optional bearer token for LM Studio's OpenAI-compatible endpoint. If not provided, reads from LANGERTHA_LMSTUDIO_API_KEY and otherwise defaults to lmstudio.

model

Chat model name. Defaults to default. For real requests, set this to an actually loaded LM Studio model key (for example qwen2.5-7b-instruct-1m).

CAPABILITIES

Advertised flags (derived from composed roles via Langertha::Role::Capabilities):

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.