Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Ollama Ollama CreateHandler

From Leeroopedia
Knowledge Sources
Domains Storage, Model_Management
Last Updated 2026-02-14 00:00 GMT

Overview

Concrete tool for creating custom model manifests from Modelfile specifications provided by the server package.

Description

CreateHandler is the HTTP handler for the /api/create endpoint. It orchestrates the entire model creation pipeline: resolves the base model layers, processes Modelfile overrides (system prompt, template, parameters), converts adapters to GGUF format, creates content-addressed blob layers, and writes the final manifest.

WriteManifest writes the JSON manifest file to the model store. NewLayer creates a content-addressed blob from arbitrary content (template text, system prompt, parameter JSON).

Usage

Invoked via the ollama create CLI command or the /api/create API endpoint.

Code Reference

Source Location

  • Repository: ollama
  • File: server/create.go (CreateHandler), manifest/manifest.go (WriteManifest), manifest/layer.go (NewLayer)
  • Lines: create.go:L46-260 (CreateHandler), manifest.go:L148-174 (WriteManifest), layer.go:L24-71 (NewLayer)

Signature

func (s *Server) CreateHandler(c *gin.Context)
func WriteManifest(name model.Name, config Layer, layers []Layer) error
func NewLayer(r io.Reader, mediatype string) (Layer, error)

Import

import "github.com/ollama/ollama/server"
import "github.com/ollama/ollama/manifest"

I/O Contract

Inputs (CreateHandler)

Name Type Required Description
c *gin.Context Yes HTTP context with api.CreateRequest JSON body
Name string Yes New model name (in request body)
From string No Base model name (FROM directive)
Files map[string]string No File digests for uploaded content
Adapters map[string]string No Adapter file digests
Template string No Chat template override
System string No System prompt override
Parameters map[string]any No Parameter overrides
Quantize string No Target quantization type

Outputs

Name Type Description
Streaming progress NDJSON Progress responses during creation
Side effect Manifest file Written to ~/.ollama/models/manifests/
Side effect Blob files Content-addressed blobs in ~/.ollama/models/blobs/

Usage Examples

Create via CLI

# Create from Modelfile
ollama create my-model -f Modelfile

# Create with quantization
ollama create my-model -f Modelfile --quantize q4_0

Create via API

curl http://localhost:11434/api/create -d '{
  "name": "my-model",
  "from": "llama3",
  "system": "You are a helpful assistant.",
  "parameters": {"temperature": 0.7}
}'

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment