@@ -107,6 +107,89 @@ describe("OpenAI Chat route", () => {
107107 } ) ,
108108 )
109109
110+ it . effect ( "lowers OpenAI-compatible thinking toggles to the wire body" , ( ) =>
111+ Effect . gen ( function * ( ) {
112+ const prepared = yield * LLMClient . prepare < OpenAIChat . OpenAIChatBody > (
113+ LLM . request ( {
114+ model,
115+ prompt : "think" ,
116+ providerOptions : { openai : { thinking : { type : "disabled" } } } ,
117+ } ) ,
118+ )
119+
120+ expect ( prepared . body . thinking ) . toEqual ( { type : "disabled" } )
121+ } ) ,
122+ )
123+
124+ it . effect ( "passes z.ai clear_thinking through the thinking toggle" , ( ) =>
125+ Effect . gen ( function * ( ) {
126+ const prepared = yield * LLMClient . prepare < OpenAIChat . OpenAIChatBody > (
127+ LLM . request ( {
128+ model,
129+ prompt : "think" ,
130+ providerOptions : { openai : { thinking : { type : "enabled" , clear_thinking : false } } } ,
131+ } ) ,
132+ )
133+
134+ expect ( prepared . body . thinking ) . toEqual ( { type : "enabled" , clear_thinking : false } )
135+ } ) ,
136+ )
137+
138+ it . effect ( "rejects max reasoning effort on OpenAI-managed chat" , ( ) =>
139+ Effect . gen ( function * ( ) {
140+ const error = yield * LLMClient . prepare (
141+ LLM . request ( {
142+ model,
143+ prompt : "think" ,
144+ providerOptions : { openai : { reasoningEffort : "max" } } ,
145+ } ) ,
146+ ) . pipe ( Effect . flip )
147+ expect ( error . message ) . toContain ( "does not support reasoning effort max" )
148+ } ) ,
149+ )
150+
151+ it . effect ( "passes max reasoning effort through for OpenAI-compatible providers" , ( ) =>
152+ Effect . gen ( function * ( ) {
153+ const deepseek = OpenAIChat . route
154+ . with ( {
155+ provider : "opencode.deepseek" ,
156+ endpoint : { baseURL : "https://api.example.test/v1/" } ,
157+ auth : Auth . bearer ( "test" ) ,
158+ } )
159+ . model ( { id : "deepseek-v4-pro" } )
160+ const prepared = yield * LLMClient . prepare < OpenAIChat . OpenAIChatBody > (
161+ LLM . request ( {
162+ model : deepseek ,
163+ prompt : "think" ,
164+ providerOptions : { openai : { reasoningEffort : "max" } } ,
165+ } ) ,
166+ )
167+
168+ expect ( prepared . body . reasoning_effort ) . toBe ( "max" )
169+ } ) ,
170+ )
171+
172+ it . effect ( "replays reasoning_content from native openaiCompatible metadata" , ( ) =>
173+ Effect . gen ( function * ( ) {
174+ const prepared = yield * LLMClient . prepare < OpenAIChat . OpenAIChatBody > (
175+ LLM . request ( {
176+ model,
177+ messages : [
178+ Message . make ( {
179+ role : "assistant" ,
180+ content : "Hello" ,
181+ native : { openaiCompatible : { reasoning_content : "thinking" } } ,
182+ } ) ,
183+ ] ,
184+ } ) ,
185+ )
186+
187+ expect ( prepared . body . messages ) . toEqual ( [
188+ { role : "assistant" , content : "Hello" , reasoning_content : "thinking" } ,
189+ ] )
190+ } ) ,
191+ )
192+
110193 it . effect ( "adds native query params to the Chat Completions URL" , ( ) =>
111194 LLMClient . generate (
112195 LLM . updateRequest ( request , {
@@ -526,6 +609,45 @@ describe("OpenAI Chat route", () => {
526609 } ) ,
527610 )
528611
612+ it . effect ( "prefers DeepSeek native cache fields over the cached_tokens detail" , ( ) =>
613+ Effect . gen ( function * ( ) {
614+ const body = sseEvents (
615+ deltaChunk ( { role : "assistant" , content : "Hi" } ) ,
616+ deltaChunk ( { } , "stop" ) ,
617+ usageChunk ( {
618+ prompt_tokens : 100 ,
619+ completion_tokens : 2 ,
620+ total_tokens : 102 ,
621+ prompt_tokens_details : { cached_tokens : 1 } ,
622+ prompt_cache_hit_tokens : 88 ,
623+ prompt_cache_miss_tokens : 12 ,
624+ } ) ,
625+ )
626+ const response = yield * LLMClient . generate ( request ) . pipe ( Effect . provide ( fixedResponse ( body ) ) )
627+ expect ( response . events . at ( - 1 ) ) . toEqual ( {
628+ type : "finish" ,
629+ reason : "stop" ,
630+ usage : new Usage ( {
631+ inputTokens : 100 ,
632+ outputTokens : 2 ,
633+ nonCachedInputTokens : 12 ,
634+ cacheReadInputTokens : 88 ,
635+ totalTokens : 102 ,
636+ providerMetadata : {
637+ openai : {
638+ prompt_tokens : 100 ,
639+ completion_tokens : 2 ,
640+ total_tokens : 102 ,
641+ prompt_tokens_details : { cached_tokens : 1 } ,
642+ prompt_cache_hit_tokens : 88 ,
643+ prompt_cache_miss_tokens : 12 ,
644+ } ,
645+ } ,
646+ } ) ,
647+ } )
648+ } ) ,
649+ )
650+
529651 it . effect ( "parses OpenAI-compatible reasoning content deltas" , ( ) =>
530652 Effect . gen ( function * ( ) {
531653 const body = sseEvents (
0 commit comments