Skip to main content
Cursor can use a model running on your own machine, such as one served by Ollama or LM Studio. It can’t reach it at localhost, though. Cursor sends every model request through its own servers to build the prompt, so the base URL you give it has to be reachable from the internet. This guide gives your local model a stable public HTTPS URL with ngrok, requires a token so only Cursor can call it, and connects it to Cursor. It works on every ngrok plan, including free.

Why localhost doesn’t work

When you set Override OpenAI Base URL to http://localhost:11434/v1, Cursor’s servers try to call localhost on their own machines, not yours. The request never arrives, and chat hangs or shows a connection error. A LAN address such as 192.168.1.20 fails for the same reason. ngrok gives your model a public URL that Cursor’s servers can reach, and forwards each request to localhost on your machine.

What you’ll need

1. Create a Traffic Policy that requires a token

Your URL is public, so anyone who finds it could use your GPU. Cursor sends its API key as a bearer token, so require one. Generate a token:
Save this as policy.yaml, replacing YOUR_TOKEN with the value you generated:
The first rule rejects requests without your token before they reach your machine. The second rewrites the Host header, because Ollama rejects requests addressed to other hostnames.

2. Put your model online

ngrok prints your public URL, such as https://your-assigned-name.ngrok-free.dev. This is your account’s dev domain, and it stays the same every time you restart, so you only configure Cursor once. Check it from another terminal:
You should see your models. Note the exact model ID, such as qwen2.5-coder:latest; you need it in the next step.

3. Add the model to Cursor

  1. Open Cursor Settings > Models.
  2. Under API Keys, turn on OpenAI API Key and paste YOUR_TOKEN as the key.
  3. Turn on Override OpenAI Base URL and enter your ngrok URL plus /v1:
  4. Click Add model and enter the model ID exactly as /v1/models returned it.
  5. Turn off other models while you test, so Cursor doesn’t fall back to a hosted one.
  6. Click Verify.
Open a chat, pick your model, and send a prompt.

4. Watch the traffic

Open http://localhost:4040 while you chat. The ngrok inspector shows each request Cursor sends and each response your model returns. If chat hangs, check here first: you see whether the request arrived, whether ngrok rejected it, and what your model sent back.

What works with a local model

Cursor still sends your prompts through its servers, so a local model keeps inference on your hardware but doesn’t keep your code off the network.

Troubleshooting

Frequently asked questions

Yes, for Chat, Agent, and inline edit. Cursor needs a public HTTPS URL for the model, because its servers make the request. Run ngrok http 11434 in front of Ollama and set that URL, plus /v1, as Cursor’s OpenAI base URL.
Cursor routes model requests through its own servers, which can’t see your machine’s localhost or local network.
No. Every ngrok account, including free, gets a dev domain that ngrok http reuses on every run.
Yes. Run Ollama and ngrok on the machine with the GPU, and use its ngrok URL in Cursor on any other machine.
Inference runs on your hardware, but Cursor still routes prompts through its servers. If your code can’t leave your network, a local model in Cursor doesn’t solve that by itself.

What’s next