vercel/ai · error · UnsupportedFunctionalityError

AI_UnsupportedFunctionalityError

AI_UnsupportedFunctionalityError

Error message

'tool choice type: ${_exhaustiveCheck}' functionality not supported.

What it means

prepareTools maps AI SDK toolChoice values ('auto','none','required','tool') to Alibaba's API. When the internal discriminated union's type falls through all known cases, an exhaustive-check default branch throws UnsupportedFunctionalityError. Hitting it means an unknown/unmapped tool choice type reached the provider.

Source

Thrown at packages/alibaba/src/alibaba-prepare-tools.ts:74

  const type = toolChoice.type;

  switch (type) {
    case 'auto':
    case 'none':
    case 'required':
      return { tools: alibabaTools, toolChoice: type, toolWarnings };
    case 'tool':
      return {
        tools: alibabaTools,
        toolChoice: {
          type: 'function',
          function: { name: toolChoice.toolName },
        },
        toolWarnings,
      };
    default: {
      const _exhaustiveCheck: never = type;
      throw new UnsupportedFunctionalityError({
        functionality: `tool choice type: ${_exhaustiveCheck}`,
      });
    }
  }
}

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Update @ai-sdk/alibaba to the latest version so new toolChoice types are mapped
  2. In the meantime use toolChoice: 'auto' | 'none' | 'required' or { type: 'tool', toolName } which are supported
  3. Pin 'ai' and '@ai-sdk/alibaba' to compatible versions

Example fix

// before
toolChoice: { type: 'someNewKind' } as any
// after
toolChoice: { type: 'tool', toolName: 'getWeather' }
Defensive patterns

Strategy: try-catch

Validate before calling

const supported = ['auto','none','required','tool'];
if (toolChoice && !supported.includes(toolChoice.type)) throw new Error(`toolChoice type ${toolChoice.type} unsupported by @ai-sdk/alibaba`);

Type guard

function isSupportedToolChoice(tc: unknown): boolean {
  const t = (tc as { type?: string } | undefined)?.type;
  return t === undefined || ['auto','none','required','tool'].includes(t);
}

Try / catch

try {
  await generateText({ ...args, toolChoice });
} catch (e) {
  if (UnsupportedFunctionalityError.isInstance(e) && e.functionality.startsWith('tool choice type')) {
    return generateText({ ...args, toolChoice: 'auto' });
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling generateText/streamText with a toolChoice whose type is not one of the Alibaba provider's mapped variants — typically a newer AI SDK toolChoice type used with an outdated @ai-sdk/alibaba version.

Common situations: Version mismatch: users upgrade the core 'ai' package (which adds new toolChoice kinds) but keep an older alibaba provider package that does not handle the new type.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/82e02970ed0294f8. Report an issue: GitHub.