# Skill: Connect a local LLM server to an agent, editor, or script using base URL and a dummy API key > Apply this skill when wiring a locally running model (Ollama, LM Studio, or similar) into any OpenAI-compatible client: an editor extension, a custom script, or an AI agent framework. Source: sodigi-learn -- local-agents/podklyuchaem-k-agentu -- https://sodigi.io/learn/local-agents/podklyuchaem-k-agentu ## When to use - User has a local model running and wants to connect it to their code editor, a browser extension, or an agent. - User wants to replace a cloud OpenAI call in their script with a free local model call. - User is getting connection errors when pointing a tool at their local server and needs to debug the address. - User wants to confirm a local server is alive before writing client code. ## Core rules - A local server exposes an OpenAI-compatible HTTP endpoint on localhost; any program that speaks the OpenAI API can be pointed at it. - The connection requires exactly two fields: base URL (the server address with the `/v1` path) and api key (any non-empty dummy string). - `localhost` (or `127.0.0.1`) means the request stays inside the machine and never touches the internet. - The port number varies by tool: check what the server printed at startup; do not guess from memory. - The `/v1` path suffix signals OpenAI-compatible mode; it must appear in the base URL exactly once. - The api key field is required by client libraries but ignored by a local server; fill it with any string (e.g., "local"). - Cloud-based AI editors route requests through their own servers and cannot see your localhost; only locally installed tools and your own scripts connect directly. - The model name in the request must match exactly the name the server reports; copy it from the model list endpoint, do not invent it. ## Procedure 1. Start the local server (via `ollama serve`, the LM Studio server toggle, or equivalent) and note the port it prints. 2. Verify the server is alive: open `http://localhost:/v1/models` in a browser; a JSON list of model names should appear. 3. Copy the exact model name from that list. 4. In the client (script, editor extension, agent config), locate the base URL / endpoint field and enter: `http://localhost:/v1` 5. In the api key field, enter any non-empty dummy string (e.g., "local"). 6. Set the model field to the exact name copied in step 3. 7. Send a minimal test request (one short user message) and confirm a response arrives. 8. If the tool adds `/v1` automatically, remove it from the base URL to avoid doubling (e.g., use `http://localhost:` instead). ## Ready-to-use prompt ``` Help me connect my locally running model to [tool name / script language]. Local server details: - Tool running the server: [Ollama / LM Studio / other] - Port (from server startup output): [e.g., 11434 or 1234] - Model name (from /v1/models): [e.g., llama3 or mistral:7b] Please provide: 1. The exact base URL string to put in the client's endpoint field. 2. What to type in the api key field. 3. A minimal working code snippet (or config snippet) for [my language / tool]. 4. How to verify the connection is working without running the full agent. 5. A checklist of the three most common mistakes that cause a "connection refused" or 404 error here. ``` ## Pitfalls - Doubling the `/v1` suffix: the client appends it automatically and the base URL already contains it, resulting in `/v1/v1` and a 404 error. - Using the wrong port: two local servers run on different ports; always read the port from server startup output. - Leaving the api key field empty: client libraries treat an empty key as invalid and throw an auth error before the request is even sent. - Starting the client before starting the server: a server that has not been started looks identical to a broken connection. - Expecting a cloud-hosted editor (where requests go through the vendor's servers) to reach localhost: it cannot; use a locally installed extension or your own script instead. - Typing a model name from memory: the server's internal name may differ from the display name; always copy it from the `/v1/models` response.