~9 min

Connecting a local model to an agent: base URL and key

One address, any key - and your editor starts thinking right there on your machine

A local model serves an OpenAI-compatible address on localhost. Here's how to wire it into your editor, an extension, and your own script using a base URL and a dummy key.

What it means to connect a local model to an agent

Your model is already up and running. So far it’s useless. On its own it’s like a phone with no SIM card: smart, but silent and talking to nobody. For your code editor, an extension, or your own script to start calling it, you need a number. That phone number is the address of your local server.

Now for the nice part. Almost every local server pretends to be the OpenAI cloud. They speak the same request language as the big paid API. So any program that “speaks OpenAI” can be politely fooled: feed it your home address instead of the cloud one. And it won’t even notice the swap.

An old rotary phone dials localhost; on the other end of the line sits a little box-shaped model
A local server is your model's phone number. Dial the address and it answers.

Why connect a model locally

You can stay in the cloud and pay for every token. That’s the familiar way. But the moment you want privacy, zero cost, and offline work - it turns out all of that is already sitting in your house. You just have to plug it in.

  • Your code and your conversations don’t leave for someone else’s servers. Everything runs locally, on your machine.
  • You pay zero for tokens: the model eats electricity, not money off your card.
  • No more “you’ve hit your quota” in the middle of the workday.
  • Catch the “address plus key” pattern once, and you can plug your model in anywhere: into an editor, an extension, your own script.

Nine out of ten connection problems aren’t “the model broke.” They’re a typo in the address or a forgotten little tail at the end. Understand the structure of the address, and these problems become transparent.

How the local server address and key work

When you start a local server, it begins listening on a single address on your computer. That address is built from three pieces. Let’s take them one at a time.

localhost means “this very computer”

localhost means “call yourself.” A request to this address doesn’t go outside. It runs inside your machine, not a single byte to the internet. That’s why it’s fast. That’s why it’s private.

The port is the door number on the computer

A computer has many doors, and the server takes one. The port is that door number. Different servers default to different doors. So two tools run side by side at the same time without getting in each other’s way.

The “v1” tail means “talk to me like I’m OpenAI”

The “v1” tail at the end of the address is a polite way of saying “let’s use the OpenAI protocol.” It’s exactly what flips on OpenAI-compatible mode . Most servers hand you such an address out of the box - nothing to tweak.

Why you can just make up the key

In the cloud, the API key is your pass - it’s how they charge you. A local server has no one to charge, so the key is basically irrelevant to it. But the key field in programs is usually required; you can’t leave it empty. The fix is childishly simple: type in any dummy string. “local” works, “salmon” works. The server ignores it, and the program is happy.

What connects easily
  • Your own scripts in any language - you change the address and the key, the rest of the code stays the same.
  • Editor extensions that have a “custom OpenAI address” field.
  • Local agents and CLI tools built around the OpenAI protocol.
Where you'll have to fiddle
  • Cloud editors that reach the model through their own server - they can't see localhost on your machine.
  • Tools with no field for a custom address - there's simply no way to swap it in.
  • Cases where you need outside access - then you'll need a tunnel to the outside world, and that's a separate story.

Example: connecting a model to a script in three steps

Let’s take the most common scenario - your own little script. It’s the easiest place to see the whole mechanism at once, with no extra layers.

Connect a model to your script in 3 steps
  1. Start your model’s local server and look at its address. It’s usually localhost, a colon, the port number, and a v1 tail. The server will print the exact port numbers itself when it starts.
  2. Grab the official OpenAI library for your language - the same one you’d use for the cloud. No need to change it; it’s universal.
  3. When you create the client, fill in two fields: base URL - your server’s address with the v1 tail, and api key - any dummy string like local. After that, write your request as usual: the name of your model and the text of your question.

In an editor with an extension, it’s exactly the same. You find a field in the settings like “Base URL” or “custom OpenAI address,” paste in the server address, put a dummy in the key field, and pick the name of your local model from the model list. The logic is the same everywhere: where to call and with which key.

Diagram: a base URL field with a localhost address and a key field with a dummy word, an arrow pointing to a box-shaped model
Same two fields everywhere: the server address and a dummy key.

Common mistakes when connecting a local model

  • Forgetting or doubling the “v1” tail. The number one classic. The program adds the tail itself, and you typed it in again - the address breaks and everything falls over. Not working? First thing, look at the very end of the address.
  • Mixing up the port. You set up two servers and typed in the wrong door - and you get silence in return. Check against what the server printed at startup. Not against your memory.
  • Leaving the key field empty. The server doesn’t need a key, but the field is often required. Empty - and the program complains. Type in any dummy, and you’re good.
  • Not starting the server itself. The connection is set up perfectly, yet the model is silent - simply because the server is off. Start it first, then check the model list.
  • Expecting miracles from a cloud editor. It reaches the model through its own servers - it won’t see localhost. That’s not a mistake in your settings, it’s just how that kind of tool is built.
  • Typing a model name from guesswork. The program needs exactly the name the server knows the model by. Open the model list and copy it from there. Don’t make it up.

TL;DR - если коротко

  • A local server pretends to be the cloud: it serves an address on localhost that speaks the same request language as OpenAI.
  • The wiring is almost always the same: base URL plus any dummy key. No real key required.
  • The address usually ends in “v1”. That’s the signal that says “talk to me like I’m OpenAI”.
  • Your own script connects with the same official OpenAI library: change two fields, and off you go.
  • The big trap is a missing or doubled “v1” and cloud editors that can’t reach localhost.
  • Free, private, no limits. The one catch: it thinks on your hardware - you get out what you put in.

Search Wiki

Press Esc to close

Enter a search term to query all course pages and lessons.