{"record":{"id":"38c8db5a348de7b0","repo":"vercel/ai","slug":"tool-choice-type-type-functionality-not-supp","errorCode":null,"errorMessage":"'tool choice type: ${type}' functionality not supported.","messagePattern":"'tool choice type: (.+?)' functionality not supported\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/xai/src/responses/xai-responses-prepare-tools.ts","lineNumber":208,"sourceCode":"      if (selectedTool.type === 'provider') {\n        // xAI API does not support forcing specific server-side tools via toolChoice\n        // Only function tools can be forced with {\"type\": \"function\", \"function\": {\"name\": \"...\"}}\n        toolWarnings.push({\n          type: 'unsupported',\n          feature: `toolChoice for server-side tool \"${selectedTool.name}\"`,\n        });\n        return { tools: xaiTools, toolChoice: undefined, toolWarnings };\n      }\n\n      return {\n        tools: xaiTools,\n        toolChoice: { type: 'function', name: selectedTool.name },\n        toolWarnings,\n      };\n    }\n    default: {\n      const _exhaustiveCheck: never = type;\n      throw new UnsupportedFunctionalityError({\n        functionality: `tool choice type: ${_exhaustiveCheck}`,\n      });\n    }\n  }\n}\n","sourceCodeStart":190,"sourceCodeEnd":214,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/xai/src/responses/xai-responses-prepare-tools.ts#L190-L214","documentation":"prepareResponsesTools switches on the toolChoice type (auto/none/required/tool). The default branch is an exhaustiveness guard that throws UnsupportedFunctionalityError for any tool-choice type the xAI Responses adapter does not implement — typically reached when the SDK type system is bypassed with a cast or a newer tool-choice type exists that xAI has not mapped.","triggerScenarios":"Passing toolChoice: { type: <unrecognized> } (e.g. a custom/extended value or an old spec value like 'any'/'message') with a cast to the responses-model toolChoice, causing the never check to fail at runtime.","commonSituations":"Migrating code from other providers where toolChoice values differ (e.g. { type: 'any' } from older SDK versions); hand-constructed provider calls; SDK version skew between spec types and provider package.","solutions":["Use only auto | none | required | { type: 'tool', toolName } for xAI responses models","Replace legacy values like 'any' with 'required'","Upgrade @ai-sdk/xai to the latest version so new tool-choice types are mapped"],"exampleFix":"// before\ntoolChoice: { type: 'any' } as any\n// after\ntoolChoice: { type: 'required' }","handlingStrategy":"validation","validationCode":"const allowed = ['auto','none','required','tool'];\nif (toolChoice && !allowed.includes(toolChoice.type)) {\n  throw new Error(`toolChoice type ${toolChoice.type} not supported by xai`);\n}","typeGuard":"function isXaiToolChoice(tc: unknown): boolean {\n  const t = (tc as any)?.type;\n  return tc == null || ['auto','none','required','tool'].includes(t);\n}","tryCatchPattern":"try {\n  await generateText({ model, prompt, toolChoice: tc as any });\n} catch (e) {\n  if ((e as any).name === 'AI_UnsupportedFunctionalityError' && (e as Error).message.includes('tool choice type')) {\n    // fall back to toolChoice: 'auto'\n  }\n}","preventionTips":["Only use documented toolChoice values for xAI","Map provider-specific values (like legacy 'any') to 'required' in an adapter layer","Avoid `as any` casts around toolChoice"],"tags":["xai","tool-choice","unsupported-functionality","exhaustiveness"],"backgroundTag":"unsupported-functionality","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}