◉ANTIGRAVITY LABJP
Articles/AI Tools
⚙ AI Tools/2026-04-24Intermediate

Using LM Studio Daily with Antigravity — Connect Through the SDK and Know Where It Stops

How to run LM Studio models with Antigravity every day: the connection path the docs actually describe (the SDK's LocalOpenAIAgentConfig), pinning the server and model load with lms, choosing a Gemma 4 size, and a triage table for when things stop.

antigravity476lm-studio6local-llm17workflow57gemma

import ArticleFAQ from "@/components/blog/ArticleFAQ";

There was a night I stopped an agent run halfway through because I had become afraid of opening the cloud billing page. I was prototyping the search flow for my wallpaper app, and the last thing I wanted was to stop — but it felt like the only option. That was the night I decided a local model should be part of my everyday setup.

What ate most of my time afterwards wasn't picking a model. It was opening Antigravity's settings again and again, looking for a field where I could paste a local base URL. So here is the thing I'd most like you to take away first: as of November 2026, the connection path to LM Studio that the official documentation actually walks through is the Antigravity SDK's LocalOpenAIAgentConfig. What follows is how I've turned that path into something I can rely on every morning, and where I look when it stops.

Three things, really: where to connect, how to pin the model load so it doesn't shift under you, and which order to suspect things in when a run stalls. Once those are settled, a local model stops being an occasional experiment and becomes something that's simply running when you sit down.

Where to connect — the SDK path is the one the docs describe

The Antigravity SDK page "Run agents with local models" lists two ways to run locally. LiteRTAgentConfig runs .litertlm checkpoints directly on-device with LiteRT. LocalOpenAIAgentConfig connects to an external server with an OpenAI-compatible API, naming Ollama, LM Studio and vLLM — and it gives http://localhost:1234/v1 as the LM Studio base_url example (checked against the docs, November 2026).

What I could not find in the official documentation was a procedure for registering an arbitrary endpoint in the IDE's or the desktop app's model picker. There's a thread on the Google AI Developers Forum from someone who wrote OpenAI-compatible keys into settings.json and saw no effect. An earlier version of this article described adding LM Studio through an IDE settings screen; I've removed that, because I couldn't back it up against the docs.

PathWhen it fitsStatus in the official docs (Nov 2026)
SDK LocalOpenAIAgentConfig + LM StudioYou want the models you already manage in LM Studio to drive an agentDocumented, with an LM Studio base_url example
SDK LiteRTAgentConfigYou're happy running Gemma 4 26B A4B on LiteRT and letting the SDK manage the serverDocumented (24 GB+ of VRAM or unified memory recommended)
Base URL in the IDE/app model pickerYou want everything inside the editorI couldn't find a documented procedure

The decision fits in one line: if you want to keep LM Studio in the loop, use LocalOpenAIAgentConfig; if you have no particular reason to, LiteRTAgentConfig is less to manage. I tend to try a prompt in LM Studio's own chat before handing it to an agent, so I stay with the first.

On the LM Studio side — keep the server on localhost and load the model yourself

You can do all of this with buttons in the GUI, but because it's daily, I pin it down with lms, LM Studio's CLI. Having the commands in my shell history means the morning check is a few keystrokes.

# 1. Start the server (without --bind it listens on 127.0.0.1 only)
lms server start --port 1234
 
# 2. See which model keys you have locally
lms ls
 
# 3. Estimate memory before loading (nothing is actually loaded)
lms load --estimate-only <model_key> --context-length 32768
 
# 4. If the estimate fits, load with a fixed context length and a name you choose
lms load <model_key> --context-length 32768 --identifier gemma4-daily
 
# 5. Check what is actually in memory right now
lms ps

Replace <model_key> with a key from lms ls. There are three reasons I bother with this instead of letting things load on demand.

  • --estimate-only prints a memory estimate that accounts for context length, without loading anything. It beats guessing from your RAM size
  • --identifier lets you choose the model name used over the API. You can swap the underlying model without touching your SDK code
  • Loading with lms load at all. Per the docs, models loaded via lms load have no TTL by default, while models loaded just-in-time (JIT) by an API request get a default idle TTL of 60 minutes

I leave CORS off. CORS matters when a browser calls the server; a Python process using the SDK doesn't need it. The lms server start docs also warn that enabling CORS, or binding to anything other than 127.0.0.1, carries security risk, and recommend turning on authentication if you do.

A model in /v1/models isn't necessarily loaded

I used to treat a model name coming back from curl http://localhost:1234/v1/models as "ready." But with JIT loading on, that endpoint returns every downloaded model, not just the ones in memory — LM Studio's headless docs say so plainly. The name can be there and the first request can still sit for a long time while the model loads.

lms ps is what tells you what's actually loaded, and the check script below is built around that.

Calling it from the Antigravity SDK — a complete example that checks first

The problem I wanted to solve: finding out after launching an agent that the server was down, or that some other model was answering. So the script checks two things before it starts, and if either fails it stops with a reason.

Before (the docs example, pointed at LM Studio)

import asyncio
from google.antigravity import Agent, LocalOpenAIAgentConfig
 
async def main():
    config = LocalOpenAIAgentConfig(
        model="gemma4-daily",
        base_url="http://localhost:1234/v1",
    ).lightweight()
    async with Agent(config) as agent:
        response = await agent.chat("What files are in this directory?")
        async for token in response:
            print(token, end="", flush=True)
        print()
 
if __name__ == "__main__":
    asyncio.run(main())

This works, but when the server is down or the model has been unloaded, the failure surfaces from deep inside the SDK, and it's not obvious what to fix.

After (daily_local.py, with a preflight in front)

# daily_local.py — check LM Studio's state, then hand the task to an Antigravity agent
import asyncio
import subprocess
import sys
import urllib.error
import urllib.request
 
from google.antigravity import Agent, LocalOpenAIAgentConfig
 
BASE_URL = "http://localhost:1234/v1"
MODEL_ID = "gemma4-daily"  # the name given with lms load --identifier
 
 
def preflight() -> None:
    # 1. Does the server answer at all?
    try:
        with urllib.request.urlopen(f"{BASE_URL}/models", timeout=5) as r:
            r.read()
    except (urllib.error.URLError, TimeoutError) as e:
        sys.exit(f"[stop] Can't reach the LM Studio server: {e}  -> lms server start --port 1234")
 
    # 2. Is the model we want actually in memory? (use lms ps, not /v1/models)
    ps = subprocess.run(["lms", "ps"], capture_output=True, text=True)
    if MODEL_ID not in ps.stdout:
        sys.exit(f"[stop] {MODEL_ID} is not loaded  -> lms load <model_key> --identifier {MODEL_ID}")
 
 
async def main(prompt: str) -> None:
    preflight()
    config = LocalOpenAIAgentConfig(model=MODEL_ID, base_url=BASE_URL).lightweight()
    async with Agent(config) as agent:
        response = await agent.chat(prompt)
        async for token in response:
            print(token, end="", flush=True)
        print()
 
 
if __name__ == "__main__":
    asyncio.run(main(" ".join(sys.argv[1:]) or "What files are in this directory?"))

Run it as python daily_local.py "Check whether the README setup steps are missing anything". The SDK installs with pip install google-antigravity. If the server is unreachable or the model isn't loaded, it prints a single [stop] line with the next command to run, and exits without starting an agent.

A word on why it's written this way. .lightweight() is described in the docs as applying tool and prompt optimizations designed for local models — it keeps the instructions sent to a smaller-context model lean. Searching lms ps output as plain text avoids depending on its exact formatting. I haven't included sample output, because the model's reply depends on your machine and versions, and I'd rather not show output I haven't verified for you.

Choosing a model and context length — decide by the estimate, keep nights short

The Gemma 4 model card lists five sizes: E2B, E4B, 12B, 26B A4B and 31B. E2B and E4B are positioned for phones and edge devices; 12B, 26B A4B and 31B for consumer GPUs and workstations (checked against the model card, November 2026). Where an earlier version of this article said "Gemma 4 4B," the correct name is E4B.

SizeOfficial positioningWhen I reach for it
E2B / E4BMobile and edgeQuick jobs where I don't want to wait — tidying file names, short summaries
12BConsumer GPUs and workstationsReading code during the day, drafting small fixes
26B A4BSame tier (MoE); the SDK docs recommend 24 GB+Planning tasks, on a machine with memory to spare
31BSame tier (dense)Not part of my daily setup

My rule for choosing: the largest option whose lms load --estimate-only figure still fits with room left for the other apps you keep open. Quantization variants work the same way — line up the estimates and the choice usually makes itself.

Longer context isn't free. It costs memory and adds latency to every step. I load at 32768 during the day, and when an agent task looks like it will run long, my first move is to split the task rather than stretch the window.

The night it cut off and I didn't notice

Once I left an agent working overnight without checking the context length. In the morning the output had simply stopped partway through the plan, with nothing resembling an error. I spent half a day doubting the model's ability before I realized the problem was the context length it had been loaded with. I'd let JIT load it, so I didn't actually know what settings it had been loaded with.

I've drawn a line since then: a model I leave running overnight is one I load myself, never one JIT picks up. With the lms load command — context length and identifier spelled out — saved in my history, I can reconstruct the next morning exactly what happened.

A triage table for when it stops

These are the cases I've actually hit, arranged so you can work back from the symptom. The checks and fixes only use features documented by LM Studio and the Antigravity SDK.

SymptomLikely causeHow to checkFix
Preflight says it can't reach the serverLM Studio's server is stopped, or the app was closedlms server statuslms server start --port 1234; to keep it resident, enable starting the LLM server on login in app settings
The model is listed, but the first reply is slowJIT is on and the model isn't in memory yetIs it missing from lms ps?Load it first with lms load <model_key> --identifier gemma4-daily
Slow only after you've been away for about an hourA JIT-loaded model hit the default 60-minute idle TTLCompare lms ps before and afterLoad with lms load (no TTL by default) or set a longer --ttl
Calling a second model makes the first disappearAuto-Evict (unloads previous JIT models before loading a new one; on by default)Server settings in the Developer tabTurn Auto-Evict off, or load both with lms load
Output cuts off partway through a long taskContext length at load time is too smallReproduce while watching lms log streamRe-estimate and reload, or split the task
Another machine can't connectBy default the server listens on 127.0.0.1 onlyThe --bind value at startupChange --bind only when you need to, and enable authentication

Three common misconceptions

  • "You can switch to LM Studio by entering a base URL in the IDE settings." As of November 2026, the documented procedure I could confirm is the SDK's LocalOpenAIAgentConfig. I couldn't verify an IDE route
  • "If it shows up in /v1/models, it's loaded." With JIT on, that list includes every downloaded model. lms ps tells you what's in memory
  • "When it won't connect, turn on CORS." CORS is for browser callers; it doesn't affect a Python SDK connection. LM Studio's own docs flag enabling it as a security risk

The morning check, and where you'll likely get stuck next

In the morning I check three things: lms server status for the server, lms ps for the model, and one short prompt through daily_local.py. It's an unglamorous routine, but most of the reasons a run would stop surface before lunch.

The next wall people tend to hit is LM Studio itself not starting or failing to load a model — How to fix LM Studio when it won't start or won't load a model is the quickest place to start. If you're torn between staying with LM Studio and moving to Ollama, Ollama, LM Studio or Gemma 4 — what to keep as an indie developer lays out how I decided, and for a fully offline setup on the Ollama side, see Antigravity × Ollama — implementation patterns for running Gemma 4 offline.

If you do one thing today, run lms load --estimate-only once and look at the number for your own machine. That was the point where I stopped guessing.

<ArticleFAQ title="FAQ" items={[ { question: "LM Studio or Ollama — which is better with the Antigravity SDK?", answer: "LocalOpenAIAgentConfig connects to either (the docs use port 11434 on localhost for Ollama and port 1234 for LM Studio). I find LM Studio easier when I want to manage models and memory estimates through the GUI and lms, and Ollama easier when I need the same setup reproduced on a server." }, { question: "Is there any advantage to going through LM Studio instead of LiteRTAgentConfig?", answer: "You keep the models and quantizations you already manage in LM Studio, and you can try prompts in its chat first. On the other hand, LiteRTAgentConfig has the SDK start and stop the server for you, and the docs say prefix caching across turns works automatically. If Gemma 4 26B A4B alone covers your needs, LiteRT may well be less work." } ]} />

Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⚙ AI Tools2026-06-17
LM Studio Not Starting or Model Won't Load? Fixes for Mac & Windows (2026)
Fix LM Studio when it will not start, a model will not load, or the local API stays silent: find the stuck stage first, then check requirements, memory estimates, port conflicts and logs on Mac and Windows.
⚙ AI Tools2026-06-12
Cutting Down 'Plausible but Wrong' RAG Answers — A Retrieval Evaluation Harness for Gemma 4 and Antigravity
Replace gut feeling with recall@5, MRR and faithfulness scores — a 30-question golden dataset and a small Python harness for evaluating a local Gemma 4 RAG stack.
◉ Antigravity2026-05-23
Which Local-LLM Path to Keep with Antigravity: Ollama, LM Studio, or Raw Gemma 4 (Indie Judgment Notes)
After running three local-LLM paths from Antigravity in parallel, here is what I kept and what I cut, written from a one-Mac-mini indie operation.