#How to run it with a local llm using a local lmstudio api

1 messages · Page 1 of 1 (latest)

torpid seal
#

I am trying to run it with a local llm on my server via lmstudio api to prevent the costs and prvicy issues with a online api, could someone please tell me how to do it?, and how to setup discord chat with the bot?

brave canyonBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

glad marlinBOT
#

To do both (LM Studio local LLM + Discord), you mainly need: (1) point OpenClaw’s model provider at LM Studio’s /v1 endpoint, and (2) configure the Discord bot token + pairing.

1) Use LM Studio as a local “OpenAI-compatible” provider

Docs: https://docs.openclaw.ai/gateway/local-models

  1. In LM Studio: start the local server and confirm it exposes an OpenAI-style endpoint.
    • Default is usually http://127.0.0.1:1234/v1
    • Check it lists your model: http://127.0.0.1:1234/v1/models
  2. In ~/.openclaw/openclaw.json (JSON5 is fine), add a provider like:
{
  agents: {
    defaults: {
      model: { primary: "lmstudio/YOUR_MODEL_ID" },
    },
#
  },

  models: {
    mode: "merge",
    providers: {
      lmstudio: {
        baseUrl: "http://127.0.0.1:1234/v1",
        apiKey: "lmstudio",
        api: "openai-responses",
        models: [
          {
            id: "YOUR_MODEL_ID",
            name: "My local model",
            reasoning: false,
            input: ["text"],
#
            cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
            contextWindow: 120000,
            maxTokens: 8192,
          },
        ],
      },
    },
  },
}

Notes:

  • Replace YOUR_MODEL_ID with the exact id shown by /v1/models.
  • If LM Studio is on a different machine than the OpenClaw Gateway, you must use that machine’s IP in baseUrl (and ensure firewall/network allows it). Also don’t expose it to the public internet.

2) Set up Discord

#

Docs: https://docs.openclaw.ai/channels/discord

High level flow:

  1. Create a Discord app + bot in the Discord Developer Portal
  2. Enable Message Content Intent
  3. Invite the bot to your server
  4. Set the bot token in OpenClaw config (don’t paste tokens into Discord chat)
  5. Start/restart the Gateway
  6. DM the bot → you’ll get a pairing code → approve it

CLI-style config (from the docs):

openclaw config set channels.discord.token '"YOUR_BOT_TOKEN"' --json
openclaw config set channels.discord.enabled true --json
openclaw gateway restart   # or: openclaw gateway
#

Pairing approval (after you DM the bot and it gives you a code):

openclaw pairing list discord
openclaw pairing approve discord <CODE>

If you want the bot to reply inside server channels (not just DMs), you’ll also configure a guild allowlist in channels.discord.guilds (the Discord doc has the exact snippet).

Quick questions so I can point you to the right exact config

  1. What does openclaw --version print?
  2. Is LM Studio running on the same machine as your OpenClaw Gateway, or a different server?
  3. Can you paste the output of hitting .../v1/models (just the model ids — no secrets)?
torpid seal
#

and can we make it have a permanent context so it will not randomly delete stuff when it cycles the user instructions out of the active memory

glad marlinBOT
#

What you’re seeing usually isn’t the bot “deleting” things — it’s one of these two mechanisms:

1) Context window + auto-compaction (most common)

Every model can only “see” a fixed amount of tokens. When the chat gets long, OpenClaw compacts old history (summarizes it) to stay within the model’s context window. That summary persists, but fine details can get lost.

Docs: https://docs.openclaw.ai/concepts/compaction
Memory flush before compaction: https://docs.openclaw.ai/concepts/memory

What to do if you want instructions to stick:

  • Put stable, always-on rules in config via systemPrompt (per guild/channel), or in the workspace’s always-injected files (AGENTS/USER/SOUL in a normal OpenClaw workspace).
  • Put durable facts/preferences in MEMORY.md (long-term memory) and tell the bot to write them there (“remember X”). OpenClaw can also do a pre-compaction memory flush via agents.defaults.compaction.memoryFlush.

Important Discord nuance: MEMORY.md is designed to load only in the main/private session (DMs), not in group/channel contexts, for safety. So if you want “permanent memory” to apply reliably, do it via:

  • Discord DM with the bot for anything that relies on MEMORY.md, or
  • Put the key rules into your channel/guild systemPrompt so they’re always present.

2) Session reset / retention policy (also possible)

#

Separately from compaction, sessions can be reset based on time/idle, and old sessions can be pruned by maintenance.

Docs: https://docs.openclaw.ai/concepts/session

Things to check/tune:

  • session.reset / session.resetByChannel.discord (avoid aggressive idle/daily resets if you want long-running continuity)
  • session.maintenance.* (don’t prune too aggressively if you want old sessions to remain available)

If you tell me this, I can point to the exact knobs to change

  1. Are you chatting with the bot in Discord DMs or in a server channel/thread?
  2. What model are you running in LM Studio, and what’s its context size? (smaller context = compacts sooner)
  3. Do you want “permanent context” for one channel only, or shared across all Discord channels?
torpid seal
#

I want to use dm, and I have made the app, but I can’t find it in the add apps in my server, and I do not know how to add bots to dm

glad marlinBOT
#

You won’t see your own bot under Discord’s “Add Apps” / App Directory search — that directory is for published apps. To add your bot to a server you must use the OAuth2 invite link from the Developer Portal.

1) Invite your bot to your server (the correct way)

Follow the docs steps here: https://docs.openclaw.ai/channels/discord

In Discord Developer Portal → your Application:

  1. Bot page → make sure you actually clicked “Add Bot” (so the app has a bot user).
  2. OAuth2 → URL Generator
    • Scopes: âś… bot and âś… applications.commands
    • Bot permissions (minimum): View Channels, Send Messages, Read Message History (plus whatever else you want)
  3. Copy the generated URL, open it in your browser, pick your server, authorize.

If the server doesn’t appear in the dropdown when you open the invite URL:

  • you must be logged into the right Discord account, and
  • you need Manage Server permission on that server.
#

2) “Add bots to DM” (how DMs actually work)

You can’t “add a bot to DMs” like adding a friend. DMs work like this:

  1. First, the bot must be in at least one server that you’re also in.
  2. In that server, enable DMs:
    • Right-click the server icon → Privacy Settings → turn on Direct Messages
  3. Then DM the bot by clicking its name in the member list (or right-click the bot → Message).

Important: bots typically cannot DM you first. You DM it first.

3) Once you can DM it, OpenClaw pairing will work

After you’ve set channels.discord.token in OpenClaw and restarted the gateway, when you DM the bot it should reply with a pairing code. Then approve it (CLI or via another already-working channel).

If you tell me which part fails (invite URL doesn’t show server vs bot joins but won’t DM vs no pairing code), I’ll narrow it down fast.

torpid seal
#

where to confirm the pairing code?

glad marlinBOT
#

Nice — glad you got it working.

For anyone landing on this thread later, the official docs for both parts are here:

1) Local model via LM Studio (server API)

High level:

  1. In LM Studio: download a model, start the local server (default is http://127.0.0.1:1234/v1)
  2. In OpenClaw config: add an lmstudio model provider and set your agent’s primary model to lmstudio/<model-id>

Docs recommend LM Studio + MiniMax M2.5 using Responses API (api: "openai-responses"). Example config (from the docs):

{
#
  agents: {
    defaults: {
      model: { primary: "lmstudio/minimax-m2.5-gs32" },
    },
  },
  models: {
    mode: "merge",
    providers: {
      lmstudio: {
        baseUrl: "http://127.0.0.1:1234/v1",
        apiKey: "lmstudio",
        api: "openai-responses",
        models: [
          {
            id: "minimax-m2.5-gs32",
#
            name: "MiniMax M2.5 GS32",
            contextWindow: 196608,
            maxTokens: 8192,
            cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
          },
        ],
      },
    },
  },
}

Tip: keep models.mode: "merge" so you can still have a hosted model as fallback if the local model struggles with tool-calling.

2) Discord chat with the bot

High level:

#
  1. Create Discord application + bot (Developer Portal)
  2. Enable Message Content Intent
  3. Invite bot to your server (bot + applications.commands)
  4. Put the bot token into OpenClaw config and restart the gateway
  5. DM the bot → get pairing code → approve it

Minimal config:

{
  channels: {
    discord: {
      enabled: true,
      token: "YOUR_BOT_TOKEN",
    },
  },
#
}

Then pairing (CLI path):

  • openclaw pairing list discord
  • openclaw pairing approve discord <CODE>

If you want it to respond in server channels (not just DMs), the Discord doc has the “guild workspace” section (groupPolicy, guilds, requireMention, etc.).

If you reply with what you changed to make it work (LM Studio API mode: openai-responses vs openai-completions, plus the model id LM Studio shows under /v1/models), I can help turn it into a clean “solution” message for the thread.

#

You don’t “confirm” the pairing code inside Discord.

Discord will DM you a code, then you approve it on the machine running the OpenClaw Gateway (or from another already-working channel).

If Discord is your first/only channel (most common)

Run this on the gateway host:

openclaw pairing list discord
openclaw pairing approve discord <CODE>

Then DM the bot again in Discord — it should start responding normally.

If you already have another channel working (Telegram/Signal/etc.)

You can message your agent there with something like: