@@ -137,12 +137,14 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
137137 }
138138 }
139139
140+ const isGrokXAI = this . _isGrokXAI ( this . options . openAiBaseUrl )
141+
140142 const requestOptions : OpenAI . Chat . Completions . ChatCompletionCreateParamsStreaming = {
141143 model : modelId ,
142144 temperature : this . options . modelTemperature ?? ( deepseekReasoner ? DEEP_SEEK_DEFAULT_TEMPERATURE : 0 ) ,
143145 messages : convertedMessages ,
144146 stream : true as const ,
145- stream_options : { include_usage : true } ,
147+ ... ( isGrokXAI ? { } : { stream_options : { include_usage : true } } ) ,
146148 }
147149 if ( this . options . includeMaxTokens ) {
148150 requestOptions . max_tokens = modelInfo . maxTokens
@@ -265,6 +267,8 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
265267 if ( this . options . openAiStreamingEnabled ?? true ) {
266268 const methodIsAzureAiInference = this . _isAzureAiInference ( this . options . openAiBaseUrl )
267269
270+ const isGrokXAI = this . _isGrokXAI ( this . options . openAiBaseUrl )
271+
268272 const stream = await this . client . chat . completions . create (
269273 {
270274 model : modelId ,
@@ -276,7 +280,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
276280 ...convertToOpenAiMessages ( messages ) ,
277281 ] ,
278282 stream : true ,
279- stream_options : { include_usage : true } ,
283+ ... ( isGrokXAI ? { } : { stream_options : { include_usage : true } } ) ,
280284 reasoning_effort : this . getModel ( ) . info . reasoningEffort ,
281285 } ,
282286 methodIsAzureAiInference ? { path : AZURE_AI_INFERENCE_PATH } : { } ,
@@ -337,6 +341,11 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
337341 }
338342 }
339343
344+ private _isGrokXAI ( baseUrl ?: string ) : boolean {
345+ const urlHost = this . _getUrlHost ( baseUrl )
346+ return urlHost . includes ( "x.ai" )
347+ }
348+
340349 private _isAzureAiInference ( baseUrl ?: string ) : boolean {
341350 const urlHost = this . _getUrlHost ( baseUrl )
342351 return urlHost . endsWith ( ".services.ai.azure.com" )
0 commit comments