EN ▾
Get API key

How to Use Llama Locally, and When an API Fits Better

You can run a Llama model on a laptop or desktop in about ten minutes with free tools. This page shows the steps, the hardware limits, and the point where a hosted API becomes the easier choice.

Updated

A desktop computer connected by a glowing cable to a cloud server, illustrating local versus hosted Llama use.

Key points

  • Ollama is the fastest route: install it, pull a model, run one command.
  • Memory decides what runs: a 4-bit 8B model needs roughly 5 GB before context.
  • Local runs are private and free per token, but you carry the hardware, heat and tuning.
  • A hosted OpenAI-compatible endpoint takes three lines to switch to and bills per token.

The short version

If you want to know how to use Llama locally, the quickest path is Ollama. It is a free runtime that downloads a model, handles quantization for you, and serves it on your own computer. The steps are the same on macOS, Windows and Linux.

  1. Install Ollama from its official site.
  2. Open a terminal and pull a model: ollama pull llama3.2.
  3. Chat with it: ollama run llama3.2.
  4. For code, call the local server at http://localhost:11434, which also exposes an OpenAI-style /v1 path.

That is the whole setup for a first test. The rest of this page covers what to do when the model is too slow, too small, or too cautious for your project, and how a hosted endpoint compares.

Everything in this list is free to try. If a download or a command fails, the cause is nearly always memory: the model is larger than the space you have, so start with the smallest version and move up.

What your machine needs

A language model is mostly a very large table of numbers, and the whole table has to sit in memory while it runs. Model size is counted in parameters. A rough rule: at 4-bit quantization, an 8B model takes around 5 GB, a 70B model takes around 40 GB, and you need extra room for the context cache that grows as the conversation gets longer.

That gives you a practical decision table.

Your hardwareWhat is realistic
Laptop, 8 GB RAM, no GPUSmall models (1B to 3B). Usable, but answers are short and simple.
Laptop or desktop, 16 GB RAMAn 8B model, 4-bit. Fine for chat and light scripting.
Apple Silicon with 32 GB or more unified memoryMid-size models, with room for longer context.
One GPU with 24 GB VRAMModels up to roughly 30B at 4-bit, fast generation.
Multiple GPUs or a 64 GB machine70B-class models, with more setup work.

These figures are approximate. Real memory use depends on the quantization format, the runtime, and how much context you ask for. If a model does not fit in fast memory, the runtime spills to system RAM or disk and speed collapses, so check the numbers before you download a 40 GB file.

Three ways to run it

Ollama

Command-line first, with a background server. It manages downloads, and a single command starts a chat. Most tutorials assume it, which makes problems easy to search for.

llama.cpp

The C++ project that many other tools are built on. You get the most control over quantization, GPU offload and context size, at the cost of reading its flags. Its llama-server binary also exposes an OpenAI-compatible HTTP interface.

LM Studio

A desktop app with a model browser and a chat window. It is the friendliest option if you do not want a terminal, and it can start a local server for other programs to call.

All three load files in the GGUF format for most setups. If one tool is slow on your machine, trying another with the same model file is a cheap experiment.

Calling the local model from code

Because Ollama serves an OpenAI-style path, the standard openai Python package works against it. The same code can point at a hosted endpoint by changing two values, which is useful if you want to develop locally and deploy against an API.

import os
from openai import OpenAI

# Local: http://localhost:11434/v1  (the key can be any non-empty string)
# Hosted: https://api.uncensoredllama.com/v1 with your real key
client = OpenAI(
    base_url=os.environ.get("LLM_BASE_URL", "https://api.uncensoredllama.com/v1"),
    api_key=os.environ["LLM_API_KEY"],
)

reply = client.chat.completions.create(
    model=os.environ.get("LLM_MODEL", "uncensored"),
    messages=[{"role": "user", "content": "Explain quantization in two sentences."}],
)
print(reply.choices[0].message.content)

For a local run, set LLM_BASE_URL=http://localhost:11434/v1, LLM_MODEL=llama3.2 and any text as the key. For the hosted API, leave the defaults and use the key from your account. Nothing else in the program changes.

Where local setups get painful

The first hour is easy. The problems appear when the project grows.

  • Context length. The cache for a long prompt takes memory on top of the weights. A model that runs fine with a 4,000-token chat can run out of memory when you feed it a long document.
  • Concurrency. One GPU serves one stream quickly. Several users or a batch job at once will queue or slow each other down unless you set up a serving stack and tune it.
  • Heat and noise. A laptop running a 7B or 8B model flat out gets hot and drains its battery fast.
  • Updates. New model versions, new quantization formats and runtime changes arrive often. Someone has to keep your setup working.
  • Refusals. Many stock instruct models are tuned to decline a wide range of requests. For fiction, roleplay or other lawful adult use, you may find yourself searching for community-modified weights and checking their licenses.

None of these is a reason to avoid local models. They are the costs to weigh before you build something on top of one.

When a hosted API is the better fit

Our comparison of Llama API options goes through the choices in more detail. In short, a hosted endpoint makes sense when you want the model without owning the machine: a web app with several users, a script that must run from a server, or a laptop that cannot hold the model you want.

This site offers an OpenAI-compatible endpoint with one open-weight model, run by an independent provider and tuned to answer without content refusals for lawful adult use. The model ID is uncensored. This is not Meta's API, and the page does not claim a specific Llama version. The hard limit is no sexual content involving minors.

The facts that matter for the local-versus-hosted decision:

  • The context window is 100,000 tokens, prompt plus completion.
  • A full key allows 8 concurrent requests and 300 requests per minute.
  • Streaming, tool calling and JSON mode are supported.
  • Prompts are not used for training.
  • The price is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit that never expires.

It is text only. If you need images, audio or embeddings, you will need other tools alongside it. The quickstart shows the base URL and a first request.

A fair cost comparison

Local inference has no per-token fee, but it is not free. You pay for the hardware once, and for power and your own time continuously. The hosted option has no hardware cost and charges for what you use.

Take a typical chat turn of 2,000 input tokens and 500 output tokens through the hosted API:

  • Input: 2,000 x $0.15 / 1,000,000 = $0.0003
  • Output: 500 x $0.50 / 1,000,000 = $0.00025
  • Total: $0.00055 per turn, so 1,000 turns cost $0.55

Now suppose, as a made-up figure, that you would buy a $1,000 graphics card just for this. At $0.00055 per turn, that money covers about 1.8 million turns of hosted usage. If you expect to run far more than that, or already own the card, local wins on cost. If you run a few thousand turns a month, it does not. See the pricing page for the top-up options.

A setup that uses both

Many developers do not pick one. They run a small local model for quick offline tests and private notes, and keep an API key for the heavy work: long documents, batch jobs, or the model size their machine cannot hold. Because both speak the OpenAI format, a single environment variable switches between them, as in the code above.

New accounts can claim $0.50 of trial credit with one click on the API key page, valid for 7 days, with no card needed. That is enough to run the same prompts you tried locally and compare the answers. Start from the API key page.

If you are unsure which side your project falls on, run the same twenty prompts through both for an afternoon. Note the speed, the quality of the answers, and how often the local model declines something you consider reasonable. That small test tells you more than any benchmark chart will.

Questions and answers

Can I use Llama locally without a GPU?

Yes. Runtimes such as Ollama and llama.cpp run on the CPU, but generation is slow, especially for larger models. Small 1B to 3B models are the practical choice without a GPU.

Is running Llama locally free?

There is no per-token fee, and many Llama weights can be downloaded at no charge under their license terms. You still pay for hardware, electricity and your time, so read the license before commercial use.

How much RAM do I need to run Llama?

As a rough guide, a 4-bit 8B model needs about 5 GB for the weights plus room for context, so 16 GB of RAM is comfortable. A 70B model at 4-bit needs around 40 GB.

Can I switch from a local model to an API later?

If your code uses the OpenAI client, you only change the base URL, key and model name. The request format stays the same.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key