Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama Routes Aliases

From Leeroopedia
Knowledge Sources
Domains HTTP API, Model Management
Last Updated 2025-02-15 00:00 GMT

Overview

Implements the HTTP API route handlers for model alias CRUD operations, providing create, list, and delete endpoints for managing model name aliases.

Description

The file contains three Gin HTTP handlers: ListAliasesHandler retrieves all aliases from the store and returns them as JSON. CreateAliasHandler validates the alias and target model names, checks for self-referencing aliases, verifies that the alias does not conflict with an existing local model, supports prefix matching mode, detects alias cycles, and persists the alias to the store. DeleteAliasHandler removes an alias by name, supporting both valid model names and raw strings (for prefix aliases that may not parse as valid model names).

Usage

These handlers are registered on the server's HTTP router and are invoked when clients make requests to the alias management API endpoints (e.g., GET /api/aliases, POST /api/aliases, DELETE /api/aliases).

Code Reference

Source Location

  • Repository: Ollama
  • File: server/routes_aliases.go
  • Lines: 1-159

Signature

type aliasListResponse struct {
    Aliases []aliasEntry `json:"aliases"`
}

type aliasDeleteRequest struct {
    Alias string `json:"alias"`
}

func (s *Server) ListAliasesHandler(c *gin.Context)
func (s *Server) CreateAliasHandler(c *gin.Context)
func (s *Server) DeleteAliasHandler(c *gin.Context)

Import

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

I/O Contract

Inputs

Name Type Required Description
aliasEntry.Alias string Yes The alias name to create (CreateAliasHandler)
aliasEntry.Target string Yes The target model name (CreateAliasHandler)
aliasEntry.PrefixMatching bool No Enable prefix-based matching (CreateAliasHandler)
aliasDeleteRequest.Alias string Yes The alias name to delete (DeleteAliasHandler)

Outputs

Name Type Description
aliasListResponse JSON List of all aliases with their targets
aliasEntry JSON Created alias with normalized names (CreateAliasHandler)
{"deleted": true} JSON Confirmation of successful deletion
{"error": "..."} JSON Error message with appropriate HTTP status code

Usage Examples

// Register alias routes on the Gin router
r.GET("/api/aliases", s.ListAliasesHandler)
r.POST("/api/aliases", s.CreateAliasHandler)
r.DELETE("/api/aliases", s.DeleteAliasHandler)

// Client creates an alias
// POST /api/aliases
// {"alias": "my-model", "target": "llama3:latest"}

// Client lists aliases
// GET /api/aliases
// Response: {"aliases": [{"alias": "my-model", "target": "llama3:latest"}]}

// Client deletes an alias
// DELETE /api/aliases
// {"alias": "my-model"}

Related Pages

Page Connections

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