mastra-ai/mastra · error
Expected format ${gatewayPrefix}/model, but got ${routerId}
Error message
Expected format ${gatewayPrefix}/model, but got ${routerId} What it means
Gateways without a separate provider segment (e.g. "amazon-bedrock") use a 2-part router id "gateway/model". When the id has exactly 2 parts and the first matches the gatewayPrefix, the second part (model id) must be non-empty; otherwise the function throws because it cannot resolve an empty model.
Source
Thrown at packages/core/src/llm/model/gateway-resolver.ts:34
if (gatewayPrefix === 'azure-openai') {
const modelId = idParts.slice(1).join('/');
if (!modelId) {
throw new Error(`Expected format azure-openai/deployment-name, but got ${routerId}`);
}
return {
providerId: 'azure-openai',
modelId, // Deployment name
};
}
// Provider-equals-gateway: a gateway whose provider id is the same as its
// gateway id (e.g. amazon-bedrock) uses a 2-part router id (gateway/model),
// because there is no separate provider segment to namespace. Catalog ids
// for such gateways are always two parts (model ids contain no slashes).
if (gatewayPrefix && idParts.length === 2 && idParts[0] === gatewayPrefix) {
const modelId = idParts[1];
if (!modelId) {
throw new Error(`Expected format ${gatewayPrefix}/model, but got ${routerId}`);
}
return {
providerId: gatewayPrefix,
modelId,
};
}
// Standard 3-part format for other prefixed gateways (Netlify, etc.)
if (gatewayPrefix && idParts.length < 3) {
throw new Error(
`Expected atleast 3 id parts ${gatewayPrefix}/provider/model, but only saw ${idParts.length} in ${routerId}`,
);
}
const providerId = idParts.at(gatewayPrefix ? 1 : 0);
const modelId = idParts.slice(gatewayPrefix ? 2 : 1).join(`/`);
if (!routerId.includes(`/`) || !providerId || !modelId) {View on GitHub (pinned to 75dd419e61)
Solutions
- Supply the model id: "amazon-bedrock/your-model-id".
- Guard the model value is non-empty before constructing the router id.
- Strip trailing slashes when composing ids from base path + model.
Example fix
// before
parseModelRouterId(`amazon-bedrock/${modelId}`, "amazon-bedrock"); // modelId === ""
// after
if (!modelId) throw new Error("modelId is required");
parseModelRouterId(`amazon-bedrock/${modelId}`, "amazon-bedrock"); Defensive patterns
Strategy: validation
Validate before calling
const modelId = 'embed-model-id';
if (!modelId) throw new Error('Model id is required for gateway router id');
const routerId = `amazon-bedrock/${modelId}`;
parseModelRouterId(routerId, 'amazon-bedrock'); Type guard
const isValidGatewayModelId = (id, prefix) => id.startsWith(`${prefix}/`) && Boolean(id.split('/')[1]); Try / catch
try {
const { providerId, modelId } = parseModelRouterId(routerId, 'amazon-bedrock');
} catch (e) {
if (e instanceof Error && e.message.includes(`${gatewayPrefix}/model`)) {
console.error(`Empty model segment in router id: "${routerId}"`);
} else throw e;
} Prevention
- Trim trailing slashes when composing gateway/model ids.
- Guard interpolated variables for emptiness before building ids.
- Validate stored ids at load time so failures surface at boot, not at request time.
When it happens
Trigger: parseModelRouterId("amazon-bedrock/", "amazon-bedrock") — gateway-prefixed id whose model segment after the slash is empty.
Common situations: Model variable empty/undefined during string interpolation; trailing slash left from path joining; data migrated with truncated ids.
Related errors
- Expected ${gatewayPrefix}/ in model router ID ${routerId}
- Linear project source id is invalid.
- Expected format azure-openai/deployment-name, but got ${rout
- Expected atleast 3 id parts ${gatewayPrefix}/provider/model,
- Attempted to parse provider/model from ${routerId} but this
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/f3d5c844abe4b4e5.
Report an issue: GitHub.