Skip to content

feat(models): model aliases - redirect a model name to another configured model - #10414

Merged
mudler merged 14 commits into
masterfrom
feat/model-aliases
Jun 20, 2026
Merged

feat(models): model aliases - redirect a model name to another configured model#10414
mudler merged 14 commits into
masterfrom
feat/model-aliases

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Model Aliases

Adds a model alias: a model config that declares a name and transparently routes all traffic for it to another configured model, so operators can redirect or rename a model without reconfiguring any clients, and swap the target live.

name: gpt-4
alias: my-llama-3

Every request for gpt-4 is served by my-llama-3. The alias name never changes for clients; the target can be re-pointed any time.

Semantics

  • 1:1, swappable at runtime. Re-point the alias via the UI, API, or the assistant without restarting.
  • Strict. The target must be an existing, non-alias, enabled model. Chains (alias -> alias) are rejected at load, at request time, and at create/swap time.
  • First-class identity. Both names appear in GET /v1/models; responses echo the alias; usage accounting records requested=alias / served=target (mirrors the Router stamps). Composes with the Router (an alias may point at a Router-enabled model).
  • All modalities. Resolution lives in the universal request middleware (SetModelAndConfig), so chat, completions, embeddings, audio, and images all inherit it.

What's included

  • Config: alias field + IsAlias() + self-validation (core/config/model_config.go); loader ResolveAlias/ValidateAliasTarget + a dangling-alias load warning (model_config_loader.go).
  • Request path: alias resolution + requested/served stamping in SetModelAndConfig, with RouteModel preserving an upstream alias as the requested model.
  • Create/swap enforcement: target validation in ImportModelEndpoint, EditYAML, and PatchConfig.
  • API: GET /api/aliases (admin) listing {name, target}; swagger regenerated; entry added to /api/instructions.
  • MCP: set_alias (swap-first: PATCH config, fall back to import on not-found) and list_aliases; deletion reuses delete_model.
  • UI: an "Alias / Routing" template card and a read-only alias -> target badge on the Manage page; the editor renders the target via the existing model-select field.
  • Docs: a Model Aliases feature page.

Testing

  • Behavioral Ginkgo/Gomega specs across config, loader, middleware, modeladmin, the API endpoint, and the MCP tool/client layers (httpapi + inproc).
  • Playwright e2e for the template card and Manage badge.
  • Full build, all touched test packages, and golangci-lint --new-from-merge-base are green; swagger regenerated.

AI assistance is recorded via Assisted-by: trailers on the commits, per the repository's AI-contribution policy; the change is owned and reviewed by the submitter.

🤖 Generated with Claude Code

mudler added 13 commits June 20, 2026 09:32
Add ModelConfig.Alias (yaml: alias), IsAlias(), and an alias
short-circuit at the top of Validate() that rejects self-reference and
forbids setting backend/parameters.model on a pure-redirect alias.

Assisted-by: Claude:claude-opus-4-8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:opus-4-8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…entity

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…/edit

Validate alias targets at create/swap entry points (ImportModelEndpoint,
EditYAML, PatchConfig) so a dangling, chained, or disabled alias target is
rejected at save time rather than surfacing as a runtime error.

Assisted-by: Claude:opus-4-8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Adds an admin-gated read-only endpoint that lists every model alias
config as {name, target} pairs, backed by the loader's existing
GetAllModelsConfigs().

Assisted-by: Claude:opus-4.8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Expose model-alias management over the LocalAI Assistant MCP surface:
list_aliases (read-only, GET /api/aliases) and set_alias (mutating).
SetAlias is swap-first: PATCH /api/models/config-json/:name swaps an
existing alias's target (validated, non-destructive) and a 404 falls
back to POST /models/import to create a fresh {name, alias} config. The
inproc client mirrors this via ConfigService.PatchConfig + a create path
modeled on ImportModelEndpoint. Deletion reuses delete_model.

Assisted-by: Claude:claude-opus-4 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Add an 'alias' section to DefaultSections() and an 'alias' field override
in DefaultRegistry() so the schema-driven React editor renders the new
top-level ModelConfig.Alias field as a model picker in its own section.

Assisted-by: Claude:opus-4.8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Add an 'Alias / Routing' template to the create-flow gallery that seeds a
minimal name + alias config, and a read-only 'alias -> target' badge on the
Manage Models tab. The capabilities row payload does not carry the alias
field, so the badge resolves targets from GET /api/aliases looked up by name.

Assisted-by: Claude:claude-opus-4 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Adds the /api/aliases path and AliasInfo schema generated from the
ListAliasesEndpoint annotation.

Assisted-by: Claude:claude-opus-4-8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…ructions

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Comment thread pkg/mcp/localaitools/inproc/client.go Fixed
The inproc createAlias path wrote the alias YAML with 0644, which gosec
flags as a new G306 finding on the PR. The LocalAI process is the sole
reader/writer of model configs, so 0600 is correct and keeps the scan clean.

Assisted-by: Claude:claude-opus-4-8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
@mudler
mudler merged commit 9565db5 into master Jun 20, 2026
60 checks passed
@mudler
mudler deleted the feat/model-aliases branch June 20, 2026 20:38
@localai-bot localai-bot added the enhancement New feature or request label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants