lmstrix
Manage, test, and run local language models through LM Studio from the command line. Its centrepiece is a binary-search algorithm that finds the true maximum context window of any model — so you stop guessing and stop crashing.
Background: what a context window is
A language model can only "see" a fixed number of tokens at once. This is its context window. Feed it more tokens than it can handle and it either crashes, silently truncates your input, or runs out of GPU memory mid-inference.
Every model has a theoretical maximum stated in its documentation. That number is often optimistic. The real limit depends on your hardware, quantisation level, and the LM Studio version. The only way to know for certain is to test it.
What lmstrix does
- Scans your LM Studio models directory and builds a registry of available models
- Tests models using binary search to find their actual maximum context window
- Persists the results to a JSON registry so you never re-test a model you already know
- Records capabilities such as vision input, native tool-use training, and public reasoning options
- Runs inference via LM Studio's local API with configurable prompts and context sizes
- Reports test results and model metadata in formatted terminal tables
Install
pip install lmstrix
# or
uv pip install lmstrix
Requires LM Studio installed and running on localhost:1234 (the default).
Quick start
# Discover all models in your LM Studio directory
lmstrix scan
# List discovered models and their tested context limits
lmstrix list
# Retrieve full model metadata, including capabilities, as JSON
lmstrix list --show json
# Find the true context limit for a specific model
lmstrix test "llama-3.2-3b-instruct"
# Run inference at a specific context size
lmstrix infer "llama-3.2-3b-instruct" --prompt "Explain quantum entanglement" --context 8192
How the context test works
Testing all possible context sizes would take hours. Binary search cuts that down to logarithmic time.
- Start with the model's stated maximum (e.g. 131072 tokens).
- Try loading the model at that size and running two simple inference checks: "Write 'ninety-six' as a number" and "2+3=".
- If it succeeds, record that size as the working maximum.
- If it fails (OOM, crash, timeout, zero tokens returned), halve the search space.
- Repeat until the boundary is found within a small tolerance.
The test uses dual prompts because a single "say hello" prompt can succeed even when the model is misconfigured — it is too short to stress the context allocation. The two prompts require the model to produce specific, verifiable output.
Results include time-to-first-token (TTFT) and tokens-per-second (TPS) from the successful test run.
The model registry
Scan results and test results are persisted to a JSON file (default: ~/.local/share/lmstrix/models.json on Linux, similar paths on macOS/Windows). Subsequent scan runs update the registry without discarding test results. list reads from the registry without touching LM Studio.
Each model record includes compatibility booleans (has_vision, has_tools) and a structured capabilities object when LM Studio exposes it:
{
"has_vision": true,
"has_tools": true,
"capabilities": {
"vision": true,
"trained_for_tool_use": true,
"reasoning": {
"allowed_options": ["off", "on"],
"default": "on"
}
}
}
lmstrix scan reads these details from LM Studio's native GET /api/v1/models endpoint when the local server is reachable, using LM_API_TOKEN if your LM Studio server requires authentication. It falls back to the Python SDK's downloaded-model metadata for vision and tool-use flags.
CLI reference
lmstrix scan Scan LM Studio models directory and update registry
lmstrix list List all models with context limits, capabilities, and test status
lmstrix test <model-id> Binary-search for true maximum context window
lmstrix infer <model-id> Run inference; options: --prompt, --context, --max-tokens
Python API
from lmstrix.api import LMStudioClient
from lmstrix.core.context_tester import ContextTester
from lmstrix.core.scanner import ModelScanner
client = LMStudioClient()
scanner = ModelScanner()
registry = scanner.scan()
tester = ContextTester(client=client, verbose=True)
model = registry.get_model("llama-3.2-3b-instruct")
updated_model = tester.test_model(model, max_context=32768, registry=registry)
print(f"Max working context: {updated_model.tested_max_context}")
print(f"TTFT: {updated_model.ttft_seconds:.2f}s")
print(f"TPS: {updated_model.tps:.1f}")
print(f"Capabilities: {updated_model.capabilities}")
LM Studio setup
LM Studio must be running with its local API server enabled (Settings → Local Server → Start Server). The default address is http://localhost:1234. Set LMSTUDIO_BASE_URL to override. If you enabled LM Studio API authentication, set LM_API_TOKEN so lmstrix scan can read /api/v1/models.
License
MIT
Metadata
Release files for lmstrix 1.0.85
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lmstrix-1.0.85.tar.gz | 120.5 kB | With provenance | Details for lmstrix-1.0.85.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lmstrix-1.0.85-py3-none-any.whl | Python 3 | none | any | Details for lmstrix-1.0.85-py3-none-any.whl |
Total release size: 240.0 kB
Release files / lmstrix-1.0.85.tar.gz
| Download URL | lmstrix-1.0.85.tar.gz |
|---|---|
| Size | 120.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f0ebb03860de0fd6913e634bb3de4bb67c704b41fd4e4a20e1bc9dae9bc458d2
|
|
BLAKE2b-256 checksum How to use checksums |
4a0d225d592eef23eba329e761d3978f3450c2ebcf3688c568e3a87ad43b2d8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / lmstrix-1.0.85-py3-none-any.whl
| Download URL | lmstrix-1.0.85-py3-none-any.whl |
|---|---|
| Size | 119.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
afe4f0cc04e19fb6f3cbcda02e0ab4527fdfaa03fb41ecef655d2da09134ae6a
|
|
BLAKE2b-256 checksum How to use checksums |
1eb27bcbb56df776bdab89b02ddde6684e895962afc8c2fdb03afed597aacb3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for lmstrix 1.0.85
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for lmstrix-1.0.85.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.