vercel/ai · error · UnsupportedFunctionalityError

'element streams in enum mode' functionality not supported.

Error message

'element streams in enum mode' functionality not supported.

What it means

The enum output strategy throws this UnsupportedFunctionalityError because there is no streaming of elements in `output: 'enum'` mode — the result is a single string chosen from a fixed list, so an element stream is meaningless. `streamObject` with enum output exposes `textStream`/`partialObjectStream`, but `elementStream` is explicitly unsupported.

Source

Thrown at packages/ai/src/generate-object/output-strategy.ts:396

            value,
            cause: 'value must be a string in the enum',
          }),
        };
      }

      return {
        success: true,
        value: {
          partial:
            possibleEnumValues.length > 1 ? result : possibleEnumValues[0],
          textDelta,
        },
      };
    },

    createElementStream() {
      // no streaming in enum mode
      throw new UnsupportedFunctionalityError({
        functionality: 'element streams in enum mode',
      });
    },
  };
};

export function getOutputStrategy<SCHEMA>({
  output,
  schema,
  enumValues,
}: {
  output: 'object' | 'array' | 'enum' | 'no-schema';
  schema?: FlexibleSchema<SCHEMA>;
  enumValues?: Array<SCHEMA>;
}): OutputStrategy<any, any, any> {
  switch (output) {
    case 'object':
      return objectOutputStrategy(asSchema(schema!));

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. For enum mode, await `result.object` or consume `textStream`/`partialObjectStream` instead of `elementStream`.
  2. If you truly need streamed elements, switch to `output: 'array'` with a string enum schema for elements.
  3. Gate any `elementStream` access behind `output === 'array'` in generic code.

Example fix

// before
const result = streamObject({ model, prompt, output: 'enum', enumValues: ['a','b'] });
for await (const el of result.elementStream) { ... }

// after
const result = streamObject({ model, prompt, output: 'enum', enumValues: ['a','b'] });
const choice = await result.object; // 'a' | 'b'
Defensive patterns

Strategy: validation

Validate before calling

// only request elementStream in array mode
if (options.output !== undefined && options.output !== 'array') {
  throw new Error('elementStream requires output: "array"');
}

Type guard

function isEnumMode(o: unknown): o is 'enum' {
  return o === 'enum';
}

Try / catch

try {
  for await (const el of result.elementStream) { /* ... */ }
} catch (e) {
  if (UnsupportedFunctionalityError.isInstance(e)) {
    const value = await result.object; // enum result is a single string
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `streamObject({ output: 'enum', enumValues: [...], ... })` and then consuming `result.elementStream`, typically via untyped code, `as any` casts, or generic wrappers that unconditionally read `elementStream`.

Common situations: Classification tasks using enum output where a developer reuses array-streaming iteration code; runtime-polymorphic stream handlers that branch on stream shape without checking output mode.

Related errors


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