@@ -24,6 +24,7 @@ import {
2424} from "../schema/index.js"
2525import { classifyProviderFailure } from "../provider-error.js"
2626import { isRecord , JsonObject , optionalArray , optionalNull , ProviderShared } from "./shared.js"
27+ import { cacheControl } from "./utils/cache.js"
2728import { OpenAIOptions } from "./utils/openai-options.js"
2829import { Lifecycle } from "./utils/lifecycle.js"
2930import { ToolStream } from "./utils/tool-stream.js"
@@ -827,15 +828,16 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (
827828 request . model . compatibility ?. zaiToolStream ?? detectZaiToolStream ( provider , baseURL , request . model . id )
828829 const hasHistory = hasToolHistory ( request . messages )
829830 const hasActiveTools = flattened . tools . length > 0
831+ const lowering = { ...options , cacheControl : options . cacheControl ?? declaredCacheControl ( request ) }
830832 return {
831833 model : request . model . id ,
832- messages : yield * lowerMessages ( flattened . request , options ) ,
834+ messages : yield * lowerMessages ( flattened . request , lowering ) ,
833835 tools :
834836 flattened . tools . length === 0
835837 ? hasHistory
836838 ? [ ]
837839 : undefined
838- : flattened . tools . map ( ( tool ) => lowerTool ( tool , options , supportsStrictMode ) ) ,
840+ : flattened . tools . map ( ( tool ) => lowerTool ( tool , lowering , supportsStrictMode ) ) ,
839841 tool_choice : hasActiveTools && request . toolChoice ? yield * lowerToolChoice ( request . toolChoice ) : undefined ,
840842 stream : true as const ,
841843 ...( supportsUsageInStreaming ? { stream_options : { include_usage : true } } : { } ) ,
@@ -853,6 +855,10 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (
853855 }
854856} )
855857
858+ // Provider wrappers that pass their own marker writer keep it; otherwise a declared cache format adds one.
859+ const declaredCacheControl = ( request : LLMRequest ) =>
860+ request . model . compatibility ?. cacheFormat === undefined ? undefined : cacheControl ( )
861+
856862// =============================================================================
857863// Stream Parsing
858864// =============================================================================
0 commit comments