Skip to main content
Apidly Cloud
Cookie policy

Analytics and ad cookies stay off unless you accept. Cookie policy

We would like to use Google Analytics and Microsoft Clarity to understand how the public pages are used, including page views and session recordings, and the Reddit Pixel to measure whether our ads on Reddit lead to visits and sign-ups. You choose here whether they are on. Rejecting changes nothing about how the site works.

Run GGUF models with llama.cpp on a cloud GPU

Serve any GGUF model from Hugging Face with llama.cpp on a rented GPU: pick a quantization that fits, chat in the browser, call the OpenAI-style API and stop paying.

Published November 26, 20267 min read

GGUF is the file format most people download when they run open language models themselves. Most popular models on Hugging Face have GGUF versions, usually in several "quantized" sizes that trade a little quality for much less memory. llama.cpp is the open-source program that runs these files, and it is fast and light on a GPU. On a rented GPU you get a server with a chat page and an OpenAI-compatible API in a few minutes, and you pay by the second only while it runs. This guide shows how to pick a model and a quantization that fit, start the server, chat with it, call it from code and keep the cost down.

What you need

  • An Apidly account with some credit.
  • The name of a GGUF repository on Hugging Face, or the default small model for a first test.
  • Nothing else: you do not need an SSH key, because the chat page and the API open in the browser.

Step 1: Choose a model and a quantization

The llama.cpp server (GGUF models) template downloads the model named in the LLAMA_ARG_HF_REPO environment variable at the first start. The default, ggml-org/gemma-3-1b-it-GGUF, is a small model that is good for checking that everything works. For real work, search Hugging Face for GGUF models and note the repository name.

A GGUF repository usually holds the same model in several quantizations. The name after the colon picks one, for example bartowski/Qwen2.5-7B-Instruct-GGUF:Q4_K_M. The common choices:

Quantization What it means When to use it
Q4_K_M About 4 bits per weight The usual default: small, fast and close to the original quality
Q5_K_M About 5 bits per weight A little better quality when memory allows
Q8_0 About 8 bits per weight Close to the original, roughly twice the size of Q4_K_M

The file size listed on Hugging Face is the number that matters. The file must fit in the GPU memory (VRAM) with room to spare for the context, the working memory that holds the conversation. As a rough guide, a 7B or 8B model at Q4_K_M is a file of a few gigabytes and fits comfortably on a 12 GB card. Check the model's licence on its page before you use it in a product. How much VRAM do you need? explains the arithmetic for bigger models.

Step 2: Choose a GPU

The template asks for at least 8 GB of VRAM and recommends 12 GB. Add up the GGUF file size and a margin for the context, then pick the smallest card that holds both: llama.cpp is efficient, so a bigger card mostly buys room for bigger models and longer contexts rather than much more speed for a small one. Open Deploy, sort by Price, low to high and use the GPU memory filter. Compare the live prices on GPU pages such as the RTX 3090, the RTX 4090 and the RTX A6000, or on live pricing. Prices follow supply, so check them rather than a number in a guide.

How to pick a GPU for LLM inference goes deeper into the choice when many people will use the model at once.

Step 3: Start the server

Open Quick start with this template, or open Deploy, pick a GPU, select Serve an API above the template cards and choose the llama.cpp server (GGUF models) card. The llama.cpp template page lists everything it sets up.

Under Environment variables you can change four settings before the start:

  • LLAMA_ARG_HF_REPO: the model repository, with an optional quantization after a colon.
  • LLAMA_ARG_CTX_SIZE: the context length in tokens, 8192 by default. A longer context holds longer conversations and documents but takes more VRAM.
  • LLAMA_ARG_N_GPU_LAYERS: how many layers of the model run on the GPU. The default 999 means all of them, which is what you want on a card that fits the model.
  • LLAMA_API_KEY: leave it empty and the server creates a key for you. The key stays the same when you stop and start the server.

Check Per hour on the review step and select Start my server. When the status is Running, the server downloads the model into /workspace/models. A small model is ready in a minute or two; a large one takes longer, and the page answers once the model is loaded.

Step 4: Chat in the browser

  1. Open the server and its Connect tab.
  2. Show and copy the API key.
  3. Press Open on the port 8080 entry. The llama.cpp chat page opens in a new tab.
  4. Open the page's settings, paste the key as the API key and save. Then type a message.

The chat page is plain and quick. If you want accounts for several people, chat history and document upload, the Open WebUI + Ollama (private chat) template is the better fit; see Run a private AI chat with Open WebUI and Ollama.

Step 5: Call the API

Copy the app address from the Connect tab; below, it is SERVER_ADDRESS, and the key is YOUR_KEY. Ask a question with curl:

curl http://SERVER_ADDRESS/v1/chat/completions \
  -H "Authorization: Bearer YOUR_KEY" -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Explain a GPU in one sentence."}]}'

The answer is in choices[0].message.content. Add "stream": true to get the reply word by word, as chat apps do.

Because the API follows the OpenAI format, the openai Python package works once you change the base address and the key:

from openai import OpenAI

client = OpenAI(base_url="http://SERVER_ADDRESS/v1", api_key="YOUR_KEY")
reply = client.chat.completions.create(
    model="local",
    messages=[{"role": "user", "content": "Write a haiku about GPUs."}],
)
print(reply.choices[0].message.content)

llama.cpp serves the one model it loaded, so the model name is only a label. Many apps and coding tools that let you set an OpenAI base URL can use your server the same way.

The address can change when you stop and start the server, so check the Connect tab after a restart.

llama.cpp, Ollama or vLLM?

  • llama.cpp runs any GGUF file you name, starts quickly and fits small GPUs. It suits one person or a small team, and models that are only published as GGUF.
  • Ollama wraps llama.cpp with a model library you pull from by name. With Open WebUI on top it is the easiest private chat.
  • vLLM serves the original model weights and handles many users at once better. It needs more VRAM for the same model. See Run an open LLM with vLLM on a rented GPU.

Keep it private

The page and the API use plain http, and anyone with the address and the key can use your model. Do not share the key, and do not paste secrets into chats. If the key leaks, destroy the server and start a new one.

Control the cost

  • Stop when you finish. Stopping ends the compute charge. The disk, with the downloaded model, is kept and still billed, so the next start does not download the model again.
  • Add an automatic stop. Under the server's Settings, Automation, stop the server when the GPU has been idle for a number of minutes. See Automation.
  • Pick the smallest card that fits. A quantized model on a modest card is often all a personal assistant needs.
  • Destroy servers you no longer use. To try another model, start a new server with the new LLAMA_ARG_HF_REPO and destroy the old one, so its disk stops costing money.

How billing by the second works has worked examples, and Control costs covers budgets and warnings.

Common problems

  • 401 or "Invalid API Key". The API always needs the key, in the chat page's settings too. Copy it again from the Connect tab and send it as Authorization: Bearer YOUR_KEY.
  • The server runs but the page does not answer. The model is still downloading or loading. Bigger files take longer; wait and reload.
  • The model does not start, or answers very slowly. It does not fit in VRAM. Choose a smaller quantization, such as Q4_K_M instead of Q8_0, lower LLAMA_ARG_CTX_SIZE, or pick a card with more memory.
  • The model download fails. The name in LLAMA_ARG_HF_REPO is misspelled, the repository has no GGUF files, or the quantization after the colon does not exist in it. Copy the name from the model page. If you added an SSH key, the log in /workspace/llama-server.log shows the exact error.

Next steps

Run a GGUF model with llama.cpp has the same steps in short form. For an app that serves many users, see the LLM inference use case. When you are ready, start a llama.cpp server.

Try what this guide shows

Start one of these templates on a rented GPU server. You see the price per hour before you start, and you pay by the second.

  • Language modelsOpens in your browser

    vLLM (OpenAI-compatible)

    High-throughput LLM inference server exposing an OpenAI-compatible API on port 8000.

    Minimum GPU memory
    16 GB
    Default disk
    100 GB

Try it on a real GPU server

Create a free account and add a balance from $10. Servers are billed by the second, and the review step shows the price per hour before you request one.

Related guides