vercel/ai · error · LoadSettingError

${description} setting must be a string.

Error message

${description} setting must be a string.

What it means

loadSetting validates a provider setting (e.g. region, fetch function) resolved from options or environment. If a value was supplied that is neither a string nor null/undefined, it throws LoadSettingError with this message, preventing invalid setting types from reaching the provider internals.

Source

Thrown at packages/provider-utils/src/load-setting.ts:28

 * @returns The setting value.
 */
export function loadSetting({
  settingValue,
  environmentVariableName,
  settingName,
  description,
}: {
  settingValue: string | undefined;
  environmentVariableName: string;
  settingName: string;
  description: string;
}): string {
  if (typeof settingValue === 'string') {
    return settingValue;
  }

  if (settingValue != null) {
    throw new LoadSettingError({
      message: `${description} setting must be a string.`,
    });
  }

  if (typeof process === 'undefined') {
    throw new LoadSettingError({
      message:
        `${description} setting is missing. ` +
        `Pass it using the '${settingName}' parameter. ` +
        `Environment variables are not supported in this environment.`,
    });
  }

  settingValue = process.env[environmentVariableName];

  if (settingValue == null) {
    throw new LoadSettingError({
      message:

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Pass the setting as a string (e.g. region: 'us-east-1')
  2. Coerce or validate config-derived values before constructing the provider
  3. Check provider docs for the option's expected type and allowed values
  4. If the value may be absent, pass undefined rather than a wrong-typed placeholder so env fallback applies

Example fix

// before
const bedrock = createAmazonBedrock({ region: 123 });
// after
const bedrock = createAmazonBedrock({ region: 'us-east-1' });
Defensive patterns

Strategy: validation

Validate before calling

const region = cfg.region;
if (region != null && typeof region !== 'string') throw new Error('region must be a string, got ' + typeof region);
const bedrock = createAmazonBedrock({ region });

Type guard

function isSettingString(value: unknown): value is string {
  return typeof value === 'string';
}

Try / catch

try {
  const bedrock = createAmazonBedrock({ region: config.region });
} catch (error) {
  if (/setting must be a string/.test(String(error.message))) {
    throw new Error('Config error: region must be a string');
  }
  throw error;
}

Prevention

When it happens

Trigger: Passing a non-string, non-nullish value for a setting like region: createAmazonBedrock({ region: 123 }) or { fetch: 'notAFunction' }-style wrong-typed options handled by loadSetting.

Common situations: Config files or CLI parsers yielding numbers/booleans; copy-paste mistakes passing a settings object instead of a string; template literals accidentally wrapping objects.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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