Neocortex Logo
Run a local LLM in Godot 4: serve a model with Ollama, call it from GDScript with HTTPRequest, keep chat history, and know what local models cost players.

How to Run a Local LLM in Godot 4

TutorialGodotLocal AI

Running a language model locally in Godot means your NPCs can talk with no internet and no per-message bill. The simplest setup is Ollama, which serves open models on your own machine, plus Godot's built-in HTTPRequest node. This guide builds a local NPC chat in GDScript, then covers what shipping a local model to players really involves.

Two ways to run a model locally

  • A local server such as Ollama runs beside the game and answers over HTTP. Easy to set up, ideal for prototyping, but every player would need it installed.
  • A model inside the game through a GDExtension that embeds llama.cpp, as open-source addons such as NobodyWho do. Nothing extra for players to install, but the model ships with your game and runs on their hardware.

This guide uses Ollama, because it takes ten minutes and the GDScript is the same idea for any HTTP model server.

Step 1: run a model with Ollama

Install Ollama, then download a small model and test it in a terminal. Small models of a few billion parameters respond quickly on a typical gaming GPU, and they're plenty for testing dialogue. Ollama listens on http://localhost:11434 while it runs.

Step 2: call it from GDScript

Add an HTTPRequest node as a child of your NPC, then attach this script. It keeps the conversation history so the model knows what was said before:

extends Node

@onready var http: HTTPRequest = $HTTPRequest

var history: Array = [
	{"role": "system", "content": "You are Brannoch, a gruff village blacksmith. Answer in one or two sentences."}
]

func _ready() -> void:
	http.request_completed.connect(_on_request_completed)

func ask(player_line: String) -> void:
	history.append({"role": "user", "content": player_line})
	var body := JSON.stringify({"model": "MODEL_NAME", "messages": history, "stream": false})
	http.request("http://localhost:11434/api/chat", ["Content-Type: application/json"], HTTPClient.METHOD_POST, body)

func _on_request_completed(result: int, code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
	if result != HTTPRequest.RESULT_SUCCESS or code != 200:
		push_warning("Local model request failed: %d" % code)
		return
	var reply: Dictionary = JSON.parse_string(body.get_string_from_utf8())["message"]
	history.append(reply)
	print(reply["content"])  # show it in your dialogue UI

Replace MODEL_NAME with the model you downloaded, call ask("Is the north road safe?"), and Brannoch answers from your own machine. An HTTPRequest handles one request at a time, so wait for the reply before sending the next line.

Step 3: make it feel like a character

A raw model is a chatbot. To make it an NPC you'll want:

  • A tighter system prompt: what the character wants, what they don't know, how they talk. See how to give NPCs unique personalities.
  • History trimming: the history grows with every line, and so does the time to answer. Keep the system prompt plus the last few exchanges.
  • Game context: add a short line about what just happened ("The player returned the stolen hammer.") before the player's message.

What a local model costs players

Local inference moves the cost from a server bill to the player's hardware:

  • Memory. The model shares the GPU with your game. On our own on-device runtime, a 3B model needs about 3 GB of VRAM and a 2B model under 1 GB.
  • Download size. Models add gigabytes to your game.
  • Quality. Small models know less and drift out of character more easily.
  • Platforms. Web exports and most phones can't run them well.

What it leaves you to build

A local model gives you text. A game character usually needs more:

The cloud route in Godot

When you want a character rather than a chatbot, the Neocortex Godot SDK runs characters in the cloud, so players need nothing installed and no GPU to spare. You design the character in a browser editor with a personality, a knowledge base, a voice and actions, and the SDK gives you voice in and out, an emotion on every line and actions as data, from GDScript. The walkthrough is in how to add AI NPC dialogue in Godot 4.

Studios that need on-device inference in production can talk to us about our on-device runtime, available as a Custom plan: it returns its first token in 0.06 seconds and starts speaking in about one second on a laptop RTX 3080. Contact us to plan it.

Next steps

For latency trade-offs, read how to get AI NPC voice replies under a second. For Unity, the same topic is covered in how to run an LLM locally in a Unity game. Every tutorial is in the guide to building AI NPCs.

Frequently Asked Questions

How do I run a local LLM in Godot?

Run a model on your machine with Ollama, then call its local HTTP API from GDScript with an HTTPRequest node. It works offline and costs nothing per message, which makes it a good way to prototype NPC dialogue.

Can I ship a game that uses Ollama?

Only if every player installs Ollama and downloads a model, which few will. Shipped games either bundle the model inside the build or use a cloud service such as Neocortex, which needs nothing on the player's machine.

What size of local model can an NPC use?

Models of a few billion parameters run on typical gaming GPUs. On our own on-device runtime, a 3B model needs about 3 GB of VRAM. Larger models give better answers but need far more memory.

Does a local LLM in Godot support voice?

Not by itself: you'd add speech recognition and text-to-speech separately. The Neocortex Godot SDK gives characters voice in and out, emotions and actions, running in the cloud.

Written by

Sercan Altundas

Date

Nov 17, 2026

Read time

8 min

Read More