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 PullModel

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

Overview

Concrete tool for downloading models from the Ollama registry provided by the server package.

Description

PullModel orchestrates the complete model download flow. It fetches the remote manifest, iterates over each layer, checks for local cache hits, and downloads missing blobs via downloadBlob. Progress is reported through a callback function that streams api.ProgressResponse events.

The HTTP handler PullHandler exposes this functionality as the /api/pull endpoint, parsing the request body and invoking PullModel with appropriate registry options.

The underlying downloadBlob function handles individual blob downloads with support for parallel chunked transfers, HTTP range requests for resume, and SHA-256 integrity verification after each download completes.

Usage

Use PullModel when downloading a model from the Ollama registry. The PullHandler HTTP endpoint is the standard entry point for API clients and the CLI.

Code Reference

Source Location

  • Repository: ollama
  • File: server/images.go (PullModel), server/routes.go (PullHandler), server/download.go (downloadBlob)
  • Lines: images.go:L552-667 (PullModel), routes.go:L882-932 (PullHandler), download.go:L468-509 (downloadBlob)

Signature

func PullModel(ctx context.Context, name string, regOpts *registryOptions, fn func(api.ProgressResponse)) error
func (s *Server) PullHandler(c *gin.Context)
func downloadBlob(ctx context.Context, opts downloadOpts) (cacheHit bool, _ error)

Import

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

I/O Contract

Inputs

Name Type Required Description
ctx context.Context Yes Cancellation context
name string Yes Model name (e.g., "llama3:latest")
regOpts *registryOptions Yes Registry authentication and endpoint options
fn func(api.ProgressResponse) Yes Progress callback for streaming download status

Outputs

Name Type Description
error error Non-nil if download fails (network error, digest mismatch, etc.)
Side effect Blob files Downloaded blobs written to ~/.ollama/models/blobs/sha256-<hash>
Side effect Manifest file Model manifest written to ~/.ollama/models/manifests/

Usage Examples

Pull via CLI

# Pull a model from the registry
ollama pull llama3:latest

# Pull with streaming progress
ollama pull llama3:70b

Pull via API

curl -X POST http://localhost:11434/api/pull \
  -d '{"name": "llama3:latest"}'

Related Pages

Implements Principle

Requires Environment

Page Connections

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