feat(gateway): add per-request model routing to API server - #5862
Closed
jbarket wants to merge 1 commit into
Closed
Conversation
The API server /v1/chat/completions endpoint now respects the "model"
field from the request body. When a model other than "hermes-agent" is
specified, it overrides the config.yaml default for that request.
Supports two formats:
- Simple model name: "claude-sonnet-4-20250514"
Uses the default provider with the specified model.
- Provider-prefixed: "ollama/gemma4:26b"
Resolves the provider's base_url, api_key, and transport from the
"providers" section in config.yaml, then uses the model name after
the slash.
This enables multi-model pipelines through a single Hermes API server
instance — e.g. n8n workflows that route implementation tasks to Sonnet,
research to a local Gemma model via Ollama, and review steps to Opus,
all through the same endpoint.
The model_override flows through _create_agent -> _run_agent for both
streaming and non-streaming paths.
Collaborator
This was referenced May 9, 2026
This was referenced May 23, 2026
1 task
Contributor
|
Thanks for the focused API-server routing work. This is now implemented on current
The merged implementation uses configured |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The API server
/v1/chat/completionsendpoint now respects themodelfield from the request body. When a model other than"hermes-agent"is specified, it overrides theconfig.yamldefault for that request.Problem: The API server always uses the model configured in
config.yaml. There is no way to route individual requests to different models or providers. When using the API server as a backend for automation pipelines (e.g., n8n workflows), every step uses the same model — even when cheaper models would suffice for implementation tasks and local models could handle research/writing.Solution: Pass the request body's
modelfield through to_create_agentas amodel_override. Two formats are supported:The provider-prefixed format looks up the provider name in
config.yaml'sproviderssection and resolvesbase_url,api_key, andtransportautomatically.Related Issue
N/A — discovered while building multi-model n8n automation pipelines (architecture → implement → review) where different steps benefit from different models.
Type of Change
Changes Made
gateway/platforms/api_server.py: Addedmodel_overrideparameter to_create_agent()and_run_agent(). When provided, overrides the config default. Provider-prefixed models (e.g."ollama/gemma4:26b") resolve credentials from theprovidersconfig section. Wired into both streaming and non-streaming/v1/chat/completionspaths.tests/gateway/test_api_server_model_routing.py: 7 new tests covering default behavior, simple override, provider-prefixed override, and unknown provider handling.How to Test
config.yaml:"model": "hermes-agent"— should use the config default as before.pytest tests/gateway/test_api_server_model_routing.py -v(7 passed)Checklist
"model": "hermes-agent"(or omitted) behaves identically to before