How to run a language model locally with Ollama

Run a small text model on your computer, check where it is loaded, and try a structured response through Ollama’s local API.

Start with one task you can judge, such as sorting sample support messages. Run it on your machine before deciding whether local inference is a good fit. Use sample data while you check where requests go and what your workflow records.

Run a local model

Install Ollama for your operating system and start the application. In a terminal, run the 1B version of Llama 3.2. The first run downloads the model. Once it is ready, enter a short prompt to check that the model responds.

ollama run llama3.2:1b

In a second terminal, run ollama ps while the model is loaded. The PROCESSOR column shows whether Ollama loaded the model on the CPU, GPU, or across both. If the sample is too slow, record that result before trying a larger model or increasing the input length. For server settings and troubleshooting, see the Ollama local FAQ.

If you want to try a larger model, check the Inkling 2 Mini routes for Apple silicon and Windows before choosing a download.

Call the local API

Save this example as local-classify.mjs and run node local-classify.mjs in a current Node.js installation while Ollama is running. It sends a sample message to the local chat endpoint and asks for one field using Ollama’s structured output format.

const response = await fetch("http://localhost:11434/api/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "llama3.2:1b",
    messages: [{
      role: "user",
      content: 'Classify "I was charged twice" as billing or other. Return JSON with a category field.',
    }],
    stream: false,
    format: {
      type: "object",
      properties: { category: { enum: ["billing", "other"] } },
      required: ["category"],
    },
  }),
  signal: AbortSignal.timeout(60_000),
});

if (!response.ok) throw new Error("Ollama request failed: " + response.status);
const { message } = await response.json();
const result = JSON.parse(message.content);
if (!["billing", "other"].includes(result?.category)) {
  throw new Error("Unexpected category");
}
console.log(result.category);

billing is the expected label for this example. A valid JSON response can still carry the wrong label. Before routing real requests, try examples with known answers, include ambiguous messages, and send failed or uncertain cases for manual review.

Decide where to run it

Compare response time and labeling errors on the same sample inputs. For a local setup, account for hardware, electricity, and maintenance. For an API, estimate usage with the stack cost calculator. Check the data path for the whole workflow, including any hosted logging or downstream services, before using sensitive inputs.