Error: 400 Bad Request: invalid model name from ollama create usually means
the GGUF file on the Modelfile's FROM line is not where Ollama looked. When the path
finds no file, Ollama treats the text as a model name instead, and a path is not a valid one. Fix the
path, or build FROM a model you already have.
A relative path is resolved against the folder that holds the Modelfile, not the folder you run the
command from. Test-Path on the path from the FROM line, run in the
Modelfile's folder, answers the question in a second.
The error
PS> Get-Content Modelfile
FROM ./models/clinic-helper.gguf
PARAMETER temperature 0.2
SYSTEM """You answer questions about clinic opening hours in one short sentence."""
PS> Test-Path .\models\clinic-helper.gguf
False
PS> ollama create fix5-test -f Modelfile
gathering model components
Error: 400 Bad Request: invalid model name
fix5-test, clinic-helper.gguf and the i4 folder below are
names made up for the test.
Why it happens
FROM accepts either an existing model or a path to weights on disk. The client expands
the argument against the Modelfile's folder and hashes the file it finds there; in the Ollama source
(parser/parser.go), a "file does not exist" result is not an error but a switch, and the
original text is sent to the server as a model name. ./models/clinic-helper.gguf breaks
the naming rules, so the server answers HTTP 400. Nothing in the message mentions a file.
Every spelling of a missing path behaved the same: .\models\clinic-helper.gguf with
backslashes, the full C:\ path, ./clinic-helper.gguf and a bare folder
./models/ all gave the 400. A bare file name with no folder, FROM
clinic-helper.gguf, is a valid model name, so Ollama tried to pull it from the registry and
failed with Error: pull model manifest: file does not exist instead.
The fix
Put the file where the line says, or change the line to where the file is. Here the file was placed
in models next to the Modelfile, and the unchanged Modelfile was then run from the
folder one level up:
PS> Test-Path .\models\clinic-helper.gguf
True
PS> ollama create fix5-test -f i4\Modelfile
gathering model components
parsing GGUF
using existing layer sha256:5ee4f07cdb9beadbbb293e85803c569b01bd37ed059d2715faa7bb405f31caa6
creating new layer sha256:2335c0ef126cbbb5d23c805a2669e0c7654c75e26f04567814521f4eb97b59b1
creating new layer sha256:81c1dabb49a2d396200b91ae4ab60b882ac576dba062629e360980062253fd22
writing manifest
success
PS> ollama list | findstr "NAME fix5"
NAME ID SIZE MODIFIED
fix5-test:latest df19e600898e 1.9 GB Less than a second ago
PS> ollama rm fix5-test
deleted 'fix5-test'
It worked although the current folder was not the Modelfile's, which shows the path is read relative
to the Modelfile. The parsing GGUF line is the sign that Ollama found a file.
If you only want a system prompt or parameters on top of a model you already pulled, skip the file
entirely: FROM qwen2.5:3b with the same PARAMETER and
SYSTEM lines created fix5-test from the existing layers and reported
success. Use the exact name from ollama list there, or you are back to a
name error.
How it was reproduced
On Windows 11 with Ollama 0.40.6 running as the tray app, in Windows PowerShell 5.1. The Modelfile
above sat in a folder with no models subfolder; ollama create exited with
code 1 and created nothing. For the fix, models\clinic-helper.gguf was a hard link to the
qwen2.5:3b weights already in the local model store, which is why the output says using
existing layer rather than copying 1.9 GB. Both test models were removed with
ollama rm, and ollama list showed no fix5 entry afterwards.
Frequently asked
- Why does ollama create say invalid model name for my GGUF file?
- Because Ollama did not find the file. When the path on the FROM line does not exist, the text is sent to the server as a model name, and a path is not a valid model name. Check the path relative to the Modelfile's folder.
- Is the FROM path in a Modelfile relative to the Modelfile or to the current folder?
- To the Modelfile. In the test, the same Modelfile with FROM ./models/clinic-helper.gguf worked when run from the folder above it, because the path was resolved against the folder that holds the Modelfile.
- How do I create an Ollama model from one I already have?
- Write FROM followed by the exact name from ollama list, for example FROM qwen2.5:3b, add your PARAMETER and SYSTEM lines, and run ollama create with -f pointing at the Modelfile. No file path is needed.
More decoded errors in the Fixes category. For the same message
from ollama run or ollama pull, see
Ollama: invalid model name.