Repository navigation
fix(sse): forward configured combo service tier #18553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 5 commits into
cheaper-inference:release/v3.8.53
from
dankarization:fix/combo-service-tier-upstream
Nov 4, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e40eea9
fix(sse): forward configured combo service tier
dankarization fac56be
fix(sse): forward the combo service tier only to targets that accept it
diegosouzapw 9471986
docs(sse): add the changelog fragment for the combo service tier
diegosouzapw f834388
Merge branch 'release/v3.8.53' into fix/combo-service-tier-upstream
diegosouzapw 13f1724
Merge branch 'release/v3.8.53' into fix/combo-service-tier-upstream
diegosouzapw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - **feat(sse):** A combo can pin an OpenAI tier with `config.service_tier` (or `serviceTier`). It reaches `openai`, `azure-openai` and `codex` targets on every attempt, replacing the client's tier there, and other targets get the request as the client sent it. API writes reject values outside `auto`, `default`, `flex`, `priority` and `scale`. ([#18553](https://github.com/cheaper-inference/OmniRoute/pull/18553)) — thanks @dankarization |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** OpenAI `service_tier` values, shared by the request translators and combo config. */ | ||
| export const OPENAI_SERVICE_TIER_VALUES = ["auto", "default", "flex", "priority", "scale"] as const; | ||
|
|
||
| export const OPENAI_SERVICE_TIERS: ReadonlySet<string> = new Set(OPENAI_SERVICE_TIER_VALUES); | ||
|
|
||
| // Only targets known to accept a top-level service_tier get it; strict | ||
| // OpenAI-compatible gateways reject unknown fields with a 400. | ||
| export const SERVICE_TIER_PROVIDERS: ReadonlySet<string> = new Set([ | ||
| "openai", | ||
| "azure-openai", | ||
| "codex", | ||
| ]); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { OPENAI_SERVICE_TIERS, SERVICE_TIER_PROVIDERS } from "../../config/serviceTier.ts"; | ||
| import { parseModel } from "../model.ts"; | ||
| import type { HandleSingleModel, SingleModelTarget } from "./types.ts"; | ||
|
|
||
| type ComboWithConfig = { config?: Record<string, unknown> | null } | null | undefined; | ||
|
|
||
| /** The combo's configured tier (`service_tier` beats `serviceTier`), or null when absent or invalid. */ | ||
| export function resolveComboServiceTier(combo: ComboWithConfig): string | null { | ||
| const raw = combo?.config?.service_tier ?? combo?.config?.serviceTier; | ||
| if (typeof raw !== "string") return null; | ||
| const tier = raw.trim().toLowerCase(); | ||
| return OPENAI_SERVICE_TIERS.has(tier) ? tier : null; | ||
| } | ||
|
|
||
| function targetProvider(modelStr: string, target?: SingleModelTarget): string | null { | ||
| const resolved = target && "provider" in target ? target.provider : null; | ||
| return resolved || parseModel(modelStr).provider; | ||
| } | ||
|
|
||
| /** | ||
| * Per-combo tier is a bucket policy: on a target that accepts `service_tier` it replaces the | ||
| * client's tier on every strategy and attempt. Any other target gets the body as the client | ||
| * sent it, so a mixed combo never sends a strict gateway a field it rejects. An API key's | ||
| * forced Codex tier still wins in the executor, and the tier beats a connection's default. | ||
| */ | ||
| export function withComboServiceTier( | ||
| handleSingleModel: HandleSingleModel, | ||
| combo: ComboWithConfig | ||
| ): HandleSingleModel { | ||
| const tier = resolveComboServiceTier(combo); | ||
| if (!tier) return handleSingleModel; | ||
| return (body, modelStr, target) => { | ||
| const provider = targetProvider(modelStr, target); | ||
| const accepted = provider !== null && SERVICE_TIER_PROVIDERS.has(provider); | ||
| return handleSingleModel(accepted ? { ...body, service_tier: tier } : body, modelStr, target); | ||
| }; | ||
| } |
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: cheaper-inference/OmniRoute
Length of output: 13693
Pass the original dispatcher into recursive combos.
When a combo-ref runs in fusion or runtime-unit mode,
buildBaseOptionsforwards the wrappedhandleSingleModelto the child. The child wraps it again, so the parent wrapper can replace the child’s configured tier or apply the parent tier when the child has none.Pass
dispatchSingleModelthrough recursive options. KeephandleSingleModelWithTimeoutfor the parent’s own targets.Suggested fix
const fusionDispatch = await tryFusionDispatch({ body, combo, cfg, config, strategy, allCombos, nesting, - handleSingleModel, + handleSingleModel: dispatchSingleModel, handleSingleModelWithTimeout,const runtimeUnitDispatch = await tryRuntimeUnitDispatch({ body, combo, config, strategy, allCombos, nesting, - handleSingleModel, + handleSingleModel: dispatchSingleModel, handleSingleModelWithTimeout,Add a parent/child tier test for a supported target. Cover both a child with a configured tier and a child without one.