Skip to content

[FEAT] - Add gateway models with aliases, fallback and pinning - #108

Open
Henrik-3 wants to merge 15 commits into
masterfrom
feat/gateway-models
Open

Henrik-3 wants to merge 15 commits into
masterfrom
feat/gateway-models

Conversation

@Henrik-3

@Henrik-3 Henrik-3 commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

What

Admins can define gateway models in the Developer area: a public name such as anthropic/claude-sonnet-5, with aliases, that one or more provider models serve. API clients call the name or any alias. When a provider fails, the request moves on to the next one, with configurable retries, and a conversation stays with the provider that answered so its prompt cache is reused. /models lists each name and alias, every gateway response carries x-oxide-model naming the provider model that answered, and request logs show who served the request in a new Served by column.

Why

OxideChat should be able to replace LiteLLM's basic gateway features itself: several providers per model, aliases, and failover (retries, cooldown, fallback, a timeout to the first chunk), without relying on an upstream router. Covers all three slices of HEN-141.

How

  • Resolution: a requested model is looked up as presets/… first, then as a gateway model name or alias, then as a provider model. A gateway model wins over a provider model with the same ID, which is then hidden from /models. A gateway model with no usable target is "model not found" and never falls through to a provider model; a switched-off one frees its names again.
  • Order: lower priority first; targets with equal priority share the load by weight. Admission already skips a target whose budget refuses or that the engine does not know (for example a provider whose model sync failed).
  • Fallback (chat): GatewayFallbackMiddleware, between the guard and the provider-routing middleware, so a prompt is checked once, a guard reroute wins and every attempt gets its provider allowlist. It tries the targets for retries + 1 rounds; an attempt counts as answered at its first content event, and the first-chunk timeout applies to streamed requests only.
  • Fallback (everything else): embeddings, rerank, decisions, System One, images and audio never pass Omniference's middleware chain, so media::run_with_fallback runs the same loop around the skin call, judged by the response status.
  • Error rules: 400, 413 and 422 go straight back to the client. Connection errors, timeouts, 404, 429 and 5xx move on and put the target into a 30-second cooldown (process memory, per instance), during which it is tried after the healthy targets. 401/403 from the provider (our key) move on and leave that target out of the request's later rounds. The editor shows cooling targets with a badge.
  • Budget: every attempt reserves for its own model and only the answering one is billed; a target the budget refuses is skipped.
  • Request bodies: the client's body is kept when the target's provider speaks that protocol, otherwise the request goes through the IR. Non-chat bodies (JSON or multipart) get the target's model written in per attempt.
  • Pinning: gateway_route_pins, per key, gateway model and conversation, expiring an hour after last use. The conversation is keyed by the client's cache key, else a session header (x-session-id, Codex session_id, x-claude-code-session-id), else a hash of the messages up to the first user message. The pinned target goes first, and the pin moves to whichever target answered. Non-chat routes have no pins.
  • Naming: GatewayRoute was already taken, so the tables keep the issue's names and the old GatewayModel type (a provider model a key reaches) is now GatewayProviderModel.
  • UI: the target list and the preset Levels tab share a new SettingsSortableList (drag and drop through useSortable from @vueuse/integrations, arrows kept for the keyboard).

Decided without review, please check: retries counts extra rounds over all targets rather than repeats of one target; 401/403 trigger fallback; 404 counts as a failure; the cooldown is fixed at 30 s; pins are per API key, not per team.

Breaking changes / migrations

  • Folded into the initial schema, as before the first release: tables gateway_models, gateway_model_targets, gateway_model_aliases and gateway_route_pins, the column gateway_request_logs.gateway_model_id, and the permission admin.developer.models.edit (granted to the admin role; it also opens GET /api/v1/admin/models for the target picker).
  • New hourly job gateway_pin_prune_job.
  • API responses gain fields: developer request logs gateway_model_id and served_model_id, developer models gateway, admin gateway model targets cooling_down.
  • New response header x-oxide-model on every gateway inference response.
  • New frontend dependencies: @vueuse/integrations, sortablejs, @types/sortablejs.

Testing

  • cargo clippy --all-targets -- -D warnings: no warnings in the touched files; the crate still has older warnings elsewhere (for example doc_markdown in src/types/rag/).
  • cargo test: 705 pass. The 5 pgvector tests fail locally only because the local Postgres has no vector extension. Generated frontend types are committed.
  • e2e: gateway-models.spec.ts 6/6 (including a real fallback past a provider without models and a failing one, and the cooldown badge) and gateway-media.spec.ts 3/3 (including embeddings falling back past a failing provider); gateway, presets, preset-levels and guardrails also pass.
  • Not covered: the non-chat fallback against real providers (only the mock), and the cooldown across several instances.

Linear: https://linear.app/henrik3/issue/HEN-141/gateway-models


Generated by Claude Code

Slice 1 of HEN-141. A gateway model is a public name for API clients that
one or more provider models serve, with aliases:

- Tables gateway_models, gateway_model_targets (priority, weight, position)
  and gateway_model_aliases; names and aliases share one case-insensitive
  namespace, checked on save; gateway_request_logs.gateway_model_id.
- Resolution order presets/, gateway model or alias, provider model. A
  gateway model picks its first target the key's team may use, ordered by
  priority with a weighted random order inside one priority.
- /models lists every name and alias and hides provider models they cover;
  responses carry x-oxide-model naming the provider model that served them.
- Admin API /api/v1/admin/gateway-models (admin.developer.view, writes need
  the new admin.developer.models.edit), audited, with translated refusals.
- Developer area: Gateway models list and editor (drag-and-drop targets via
  @vueuse/integrations useSortable, load sharing with weights, retries and
  time to first chunk stored for slice 2), gateway rows on Models with a
  price span over the targets, and a Served by column on Logs.
- The old GatewayModel type (a provider model a key reaches) is now
  GatewayProviderModel; GatewayModel names the new table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SbfESZbPGT98Xejhk3ZQj9
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Slice 1 of HEN-141. A gateway model is a public name for API clients that
one or more provider models serve, with aliases:

- Tables gateway_models, gateway_model_targets (priority, weight, position)
  and gateway_model_aliases; names and aliases share one case-insensitive
  namespace, checked on save; gateway_request_logs.gateway_model_id.
- Resolution order presets/, gateway model or alias, provider model. A
  gateway model picks its first target the key's team may use, ordered by
  priority with a weighted random order inside one priority.
- /models lists every name and alias and hides provider models they cover;
  responses carry x-oxide-model naming the provider model that served them.
- Admin API /api/v1/admin/gateway-models (admin.developer.view, writes need
  the new admin.developer.models.edit), audited, with translated refusals.
- Developer area: Gateway models list and editor (drag-and-drop targets via
  @vueuse/integrations useSortable, load sharing with weights, retries and
  time to first chunk stored for slice 2), gateway rows on Models with a
  price span over the targets, and a Served by column on Logs.
- The old GatewayModel type (a provider model a key reaches) is now
  GatewayProviderModel; GatewayModel names the new table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SbfESZbPGT98Xejhk3ZQj9
Slice 2 and 3 of HEN-141:
- GatewayFallbackMiddleware (between guard and provider routing) tries a
  gateway model's targets in order for retries + 1 rounds, with a 30 s
  in-memory cooldown per failing target, a first-chunk timeout for
  streamed requests and a budget reservation per attempt
- 400/413/422 are answered at once; 401/403 from a provider move on
  without retrying that target; 404/429/5xx/timeouts cool it down
- Admission skips targets the engine cannot resolve or whose budget
  refuses; routes rewrite the body model after admission
- x-oxide-model and request logs name the target that answered
- gateway_route_pins keeps a key's conversation (cache key, session
  header or conversation start) on the target that last answered, for
  an hour after last use, pruned hourly
- Editor shows targets that are cooling down; the presets Levels tab
  uses the shared sortable list
- Unit, DB and e2e tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SbfESXX6k5T1d2cAhXtdch
Embeddings, rerank, decisions, System One, images and audio requests to a
gateway model now try its other targets like chat does: same order, rounds,
cooldown and stop rules, judged by the response status, with budget reserved
per attempt and the body rewritten to each target's model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SbfESXX6k5T1d2cAhXtdch
@Henrik-3 Henrik-3 changed the title [FEAT] - Add gateway models with aliases and several providers per name [FEAT] - Add gateway models with aliases, fallback and pinning Dec 4, 2026
@Henrik-3
Henrik-3 marked this pull request as ready for review December 5, 2026 00:00
@greptile-apps

greptile-apps Bot commented Dec 5, 2026

Copy link
Copy Markdown

Automatic reviews are disabled for this repository. Configure in Code Review Settings.

@Henrik-3
Henrik-3 added this pull request to stack #116 December 5, 2026 21:27
@Henrik-3
Henrik-3 removed this pull request from stack #116 December 6, 2026 00:30
Henrik-3 and others added 4 commits December 6, 2026 01:30
…oute

[FEAT] - Show and configure native endpoints for every model type
- Add gateway model alias management
- Show the routes preconfigured providers serve, own APIs included
- [FEAT] - Show and configure native endpoints for every model type
- [FEAT] - Fall back between gateway model targets on non-chat routes too
- [FEAT] - Fall back between gateway model targets and pin conversations
- [FEAT] - Add gateway models with aliases and several providers per name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants