Self-Hosted AI Assistant on Windows 11: Setup and LLM Integration

    This guide walks through building a self-hosted AI assistant on Windows 11 and connecting it to a general-purpose large language model. It covers why self-hosting keeps interaction entry points and stored data local, the hardware and software baseline, common setup blockers such as long paths, proxy certificates, and antivirus interference, and how to obtain and manage model API keys. It also explains how to audit a one-click installation script before running it, how to verify the installation, how to configure the assistant with environment variable references and a loopback-only listener, and how to call an OpenAI-compatible /v1/chat/completions endpoint. The final sections cover production hardening, including HTTPS enforcement, authentication, log redaction, key rotation, cost monitoring, and skill sandboxing, plus a troubleshooting table.

    1. Why Choose a Self-Hosted AI Assistant

    Public cloud LLM services iterate quickly, and more developers are revisiting a basic question: do conversation data, document contents, and business context have to leave your own machine? The core value of a self-hosted AI assistant is exactly this — bringing the “interaction entry point” and the “location where data is written to disk” back to local, while sending only the necessary inference requests to the model provider as API calls.

    This architecture delivers three direct benefits. First, a clear privacy boundary: session history, attachment parsing results, and skill caches all live on the local disk, which makes auditing and cleanup straightforward. Second, replaceable models: the assistant layer and the model layer are decoupled through a standard HTTP interface, so switching providers or switching to a local inference engine requires only a configuration change. Third, extensible capabilities: file processing, web retrieval, scheduled tasks, and similar features can be built as plugin-style skills and layered on gradually without rewriting the main program.

    Note that self-hosting does not mean “fully offline.” If you use a cloud LLM API, request content still leaves the machine, so real privacy design focuses on minimizing outbound fields, disabling unnecessary context回传, and establishing governance rules for keys and logs.

    2. Environment Preparation and Prerequisites

    2.1 Hardware and Software Baseline

    • OS: Windows 11 64-bit (Windows 10 64-bit usually works as well).
    • Memory: 8GB or more recommended; 16GB is safer if you also run local vector retrieval or browser automation skills.
    • Disk: reserve at least 2GB for the runtime and dependencies, and more if you plan to cache parsed document artifacts.
    • Network: installation requires access to code hosting sites and package repositories; on corporate networks, confirm proxy and TLS interception policies in advance.

    2.2 Three Common Blockers to Handle Up Front

    1. Long path limits: the default Windows path length limit can cause dependency installation to fail, so enable long path support as needed.
    2. Proxy and certificates: under a corporate proxy, package managers and script downloads often break because the certificate chain is incomplete. Configure the proxy and trusted root certificates centrally rather than bypassing verification tool by tool.
    3. Antivirus interference: some security software blocks script execution and child process creation, so whitelist the installation directory before retrying.

    2.3 Obtaining Model Service Keys

    Register an account on any compatible model platform, go to the key management page, and create an access credential — a string with an sk- prefix. Three points matter: the key is shown in full only once at creation, so store it in a credential manager immediately; create separate keys for different environments so they can be revoked per environment; and prefer a general-purpose chat model with a free tier or pay-as-you-go billing for the validation phase, so integration testing does not immediately incur cost.

    3. Installation: Security Assessment of Scripted Setup

    The official one-click script is the most efficient route; it automatically downloads and configures the runtime (usually Node.js 22 or later) and the core files. But “piping a remote script into execution” essentially hands execution rights to remote content, so a prior assessment is mandatory:

    1. # Step 1: download only, do not execute, save to disk for review
    2. Invoke-WebRequest -UseBasicParsing -Uri "<official install script URL>" -OutFile "$env:TEMP\install.ps1"
    3. # Step 2: inspect key actions locally (download sources, write paths, environment variable changes)
    4. Get-Content "$env:TEMP\install.ps1" | Select-Object -First 80
    5. # Step 3: run it only after confirming everything looks correct
    6. powershell -ExecutionPolicy Bypass -File "$env:TEMP\install.ps1"

    For the execution policy, allow locally signed scripts at user scope instead of opening things up globally:

    1. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

    This setting means locally created scripts can run, while scripts from the network must carry a trusted signature. Compared with the global openness of Unrestricted or Bypass, it compresses the risk surface to the minimum. If your corporate environment is managed by group policy, go through the change process rather than forcing a local change.

    Installation usually takes a few minutes, during which the runtime and dependencies are downloaded, so do not close the window. If the official source is unreachable, you can switch to a mirror, but a mirror is also third-party content and should be evaluated by the same standard as the official source.

    4. Verifying the Installation and Initial Configuration

    After installation, confirm three things in order: the runtime version, whether the command is available, and whether the service starts.

    1. node -v # expect v22 or later
    2. npm -v
    3. openclaw --version
    4. openclaw doctor # if a self-check subcommand is provided, run it first to quickly locate environment gaps

    For initialization, write the configuration non-interactively so it is easy to version and share across a team:

    1. {
    2. "model": {
    3. "provider": "openai-compatible",
    4. "baseUrl": "https://<model service URL>/v1",
    5. "apiKeyEnv": "MODEL_API_KEY",
    6. "model": "<general-purpose chat model name>"
    7. },
    8. "server": { "host": "127.0.0.1", "port": 7860 },
    9. "logging": { "level": "info", "redact": ["authorization", "api-key"] }
    10. }

    Two key design choices: first, the configuration stores only the environment variable name rather than the plaintext key, and the key is injected through a user-level environment variable or a credential manager; second, the service listens on the loopback address 127.0.0.1 by default, avoiding unauthorized access.

    1. # Inject the key via a user-level environment variable (takes effect after restarting the terminal)
    2. [Environment]::SetEnvironmentVariable("MODEL_API_KEY", "sk-xxxx", "User")

    5. Connecting a General-Purpose LLM Service

    Almost all model providers offer an OpenAI-style /v1/chat/completions interface, which makes the integration layer provider-agnostic. A minimal working call:

    1. $body = @{
    2. model = "<general-purpose chat model name>"
    3. messages = @(
    4. @{ role = "system"; content = "You are an assistant running in a local self-hosted environment." },
    5. @{ role = "user"; content = "Explain the advantages of a locally deployed assistant in three sentences." }
    6. )
    7. stream = $false
    8. } | ConvertTo-Json -Depth 5
    9. Invoke-RestMethod -Method Post `
    10. -Uri "https://<model service URL>/v1/chat/completions" `
    11. -Headers @{ Authorization = "Bearer $env:MODEL_API_KEY" } `
    12. -ContentType "application/json" -Body $body

    During integration testing, fix temperature and max_tokens first to keep the pipeline stable, then tune the output style. A 401 means the key or the environment variable has not taken effect; a 429 means rate limiting was triggered, so add exponential backoff retries; for connection timeouts, check the proxy and DNS first.

    6. Web Console and Production Hardening

    After starting the service, open the local console to validate conversation, skill toggles, and model switching. If LAN access is required, make sure three protections are in place: enforce HTTPS at the reverse proxy, enable login authentication and rate limiting, and place the console behind an intranet or zero-trust gateway — never expose it directly to the public internet.

    Further governance recommendations:

    • Key rotation: establish periodic rotation and revocation, and keep only references in the configuration.
    • Log redaction: redact fields in request headers and bodies so keys and user privacy never reach the logging system.
    • Cost visibility: record token usage per session and wire it into a general monitoring and alerting category for threshold notifications.
    • Skill sandboxing: restrict the working directory and outbound domains for file processing and web retrieval skills to reduce the privilege escalation risk from prompt injection.

    7. Troubleshooting Quick Reference

    Symptom Common Cause Direction
    Script execution blocked Execution policy restriction Allow signed scripts at user scope
    Runtime version too low Leftover old version Upgrade to 22 or later and clear the cache
    Invalid key Environment variable not refreshed Reopen the terminal or restart the service process
    Requests rate limited Concurrency too high Exponential backoff plus serialized queue
    Console unreachable Listening on loopback only, or port in use Adjust the listen address and port

    8. Summary

    The hard part of deploying a self-hosted AI assistant is not “getting it installed” but “keeping it secure, replaceable, and extensible.” While gaining efficiency from scripted installation, insist on auditing before executing; decouple the model layer with a standard interface so providers stay replaceable; and build a security foundation from key references, log redaction, and a minimal exposure surface. Complete the four steps in this article — environment check, installation verification, model integration, and hardening — and you have a long-term, viable base with data ownership and pluggable capabilities. To move closer to a cloud deployment, you can use object storage for attachment persistence, a message queue for peak shaving, and a container platform for elastic scaling, together with logging and monitoring categories to form a complete loop.