n8n-io/n8n · error · Error

Model ID is required

Error message

Model ID is required

What it means

`createModel` accepts a model config as either a string (`"provider/model"`) or an object (`{ id: "provider/model", ...creds }`). It extracts `rawId` and throws when the ID is empty, whitespace-only, or absent. Without a model ID the factory cannot resolve a provider or instantiate a language model.

Source

Thrown at packages/@n8n/agents/src/runtime/model/model-factory.ts:227

			})(model);
		},
	},
};

const SUPPORTED_PROVIDERS = Object.keys(LANGUAGE_PROVIDERS).join(', ');

/**
 * Provider packages are loaded dynamically via require() so only the
 * provider needed at runtime must be installed.
 */
export function createModel(config: ModelConfig, fetch?: FetchFn): LanguageModel {
	if (isLanguageModel(config)) {
		return config;
	}

	const rawId = typeof config === 'string' ? config : config.id;
	if (!rawId || rawId.trim() === '') {
		throw new Error('Model ID is required');
	}

	const slashIndex = rawId.indexOf('/');
	if (slashIndex <= 0) {
		throw new Error(`Invalid model ID "${rawId}": expected "provider/model-name" format`);
	}
	const provider = rawId.slice(0, slashIndex) as ProviderId;
	const modelName = rawId.slice(slashIndex + 1);

	const entry = LANGUAGE_PROVIDERS[provider];
	if (!entry) {
		throw new Error(
			`Unsupported provider: "${provider}". Supported providers: ${SUPPORTED_PROVIDERS}`,
		);
	}

	// Collect credential fields: strip `id`, pass the rest to Zod validation.
	let credFields: Record<string, unknown> = {};

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Check the value being passed to `.model()` or `createModel()` — log it before the call.
  2. Ensure your model configuration source (env var, DB row, settings) has a non-empty `provider/model-name` value.
  3. Add a UI-level or config-level validation that rejects empty model IDs before they reach the runtime.
  4. If the model comes from user input, default to a known-good model when blank rather than passing empty through.

Example fix

// before:
const model = createModel(config.modelId); // config.modelId is ''

// after:
const modelId = config.modelId || 'openai/gpt-4o';
if (!modelId.trim()) throw new Error('Model ID must be configured');
const model = createModel(modelId);
Defensive patterns

Strategy: validation

Validate before calling

function validateModelId(id: string | undefined): string {
  if (!id || id.trim() === '') {
    throw new Error('Model ID must be a non-empty "provider/model-name" string');
  }
  return id;
}

// Before calling createModel:
const modelId = validateModelId(config.modelId);
const model = createModel(modelId);

Type guard

function isNonEmptyModelId(id: unknown): id is string {
  return typeof id === 'string' && id.trim().length > 0;
}

Prevention

When it happens

Trigger: Calling `createModel('')`, `createModel({ id: '' })`, `createModel({ id: ' ' })`, or `createModel({})` (no `id` field at all). Also triggered when a credential resolution layer passes an empty model string.

Common situations: A credential/model configuration UI saved an empty model field. An environment variable or settings key for the model was not set, defaulting to empty string. The model ID was trimmed to empty by input sanitization. Instance AI config emitted `{ id: '', url: '...' }`.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/8b7a9ab50a96beed. Report an issue: GitHub.