xAI: Enable backend web search Closes #4160

34873024b0ac31c832a65c267192271e6327c15d

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +12 -1Ignore whitespace
public/index.html+1 -1
@@ -1969,7 +1969,7 @@
19691969 </span>
19701970 </div>
19711971 </div>
19721972 <div class="range-block" data-source="makersuite,vertexai,aimlapi,openrouter,claude,xai">
19731973 <label for="openai_enable_web_search" class="checkbox_label flexWrap widthFreeExpand">
19741974 <input id="openai_enable_web_search" type="checkbox" />
19751975 <span data-i18n="Enable web search">Enable web search</span>
src/endpoints/backends/chat-completions.js+11 -0
@@ -965,6 +965,17 @@ async function sendXaiRequest(request, response) {
965965 bodyParams['reasoning_effort'] = request.body.reasoning_effort === 'high' ? 'high' : 'low';
966966 }
967967
968+ if (request.body.enable_web_search) {
969+ bodyParams['search_parameters'] = {
970+ mode: 'on',
971+ sources: [
972+ { type: 'web', safe_search: false },
973+ { type: 'news', safe_search: false },
974+ { type: 'x' },
975+ ],
976+ };
977+ }
978+
968979 const processedMessages = request.body.messages = convertXAIMessages(request.body.messages, getPromptNames(request));
969980
970981 const requestBody = {