fix(ai/providers): restricted service tier usage to OpenAI-compatible providers

- Replaced service-tier gating in OpenAI provider request builders with provider-aware checks before writing params.service_tier.
- Updated the shared service-tier helper to accept provider context and only return true for flex, scale, or priority on openai/openai-codex providers.
This commit is contained in:
can1357
2026-04-26 07:22:53 +02:00
parent 2f4d5c68c4
commit 4f0da4eae5
5 changed files with 15 additions and 9 deletions
@@ -10,11 +10,11 @@ import {
type Api,
type AssistantMessage,
type Context,
isSpecialServiceTier,
type Model,
type ServiceTier,
type StreamFunction,
type StreamOptions,
shouldSendServiceTier,
type Tool,
type ToolChoice,
} from "../types";
@@ -298,7 +298,7 @@ function buildParams(
if (options?.repetitionPenalty !== undefined) {
params.repetition_penalty = options.repetitionPenalty;
}
if (isSpecialServiceTier(options?.serviceTier)) {
if (shouldSendServiceTier(options?.serviceTier, model.provider)) {
params.service_tier = options.serviceTier;
}
@@ -19,12 +19,12 @@ import {
type Api,
type AssistantMessage,
type Context,
isSpecialServiceTier,
type Model,
type ProviderSessionState,
type ServiceTier,
type StreamFunction,
type StreamOptions,
shouldSendServiceTier,
type TextContent,
type ThinkingContent,
type Tool,
@@ -493,7 +493,7 @@ async function buildTransformedCodexRequestBody(
if (options?.repetitionPenalty !== undefined) {
params.repetition_penalty = options.repetitionPenalty;
}
if (isSpecialServiceTier(options?.serviceTier)) {
if (shouldSendServiceTier(options?.serviceTier, model.provider)) {
params.service_tier = options.serviceTier;
}
if (context.tools && context.tools.length > 0) {
@@ -14,7 +14,6 @@ import { getEnvApiKey } from "../stream";
import {
type AssistantMessage,
type Context,
isSpecialServiceTier,
type Message,
type MessageAttribution,
type Model,
@@ -23,6 +22,7 @@ import {
type StopReason,
type StreamFunction,
type StreamOptions,
shouldSendServiceTier,
type TextContent,
type ThinkingContent,
type Tool,
@@ -811,7 +811,7 @@ function buildParams(
if (options?.repetitionPenalty !== undefined) {
params.repetition_penalty = options.repetitionPenalty;
}
if (isSpecialServiceTier(options?.serviceTier)) {
if (shouldSendServiceTier(options?.serviceTier, model.provider)) {
params.service_tier = options.serviceTier;
}
@@ -11,13 +11,13 @@ import {
type AssistantMessage,
type CacheRetention,
type Context,
isSpecialServiceTier,
type MessageAttribution,
type Model,
type ProviderSessionState,
type ServiceTier,
type StreamFunction,
type StreamOptions,
shouldSendServiceTier,
type Tool,
type ToolChoice,
} from "../types";
@@ -384,7 +384,7 @@ function buildParams(
if (options?.repetitionPenalty !== undefined) {
params.repetition_penalty = options.repetitionPenalty;
}
if (isSpecialServiceTier(options?.serviceTier)) {
if (shouldSendServiceTier(options?.serviceTier, model.provider)) {
params.service_tier = options.serviceTier;
}
+7 -1
View File
@@ -152,7 +152,13 @@ export type CacheRetention = "none" | "short" | "long";
/** OpenAI service tier for processing priority. Only applies to OpenAI-compatible APIs. */
export type ServiceTier = "auto" | "default" | "flex" | "scale" | "priority";
export function isSpecialServiceTier(serviceTier?: ServiceTier | null): serviceTier is "flex" | "scale" | "priority" {
export function shouldSendServiceTier(
serviceTier?: ServiceTier | null,
provider?: Provider,
): serviceTier is "flex" | "scale" | "priority" {
if (provider !== "openai" && provider !== "openai-codex") {
return false;
}
return serviceTier === "flex" || serviceTier === "scale" || serviceTier === "priority";
}