microsoft/semantic-kernel · error · NotSupportedException

Unsupported AI21 model: {modelId}

Error message

Unsupported AI21 model: {modelId}

What it means

CreateTextGenerationService routes an AI21 model to a text-generation service. AI21 is supported only for model names starting with 'jamba' (AI21JambaService) or 'j2-' (AI21JurassicService). Any other AI21 model name throws NotSupportedException. The model name is the segment after the first dot in the modelId.

Source

Thrown at dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/BedrockServiceFactory.cs:58

    /// <param name="modelId">The model to be used for the service.</param>
    /// <returns><see cref="IBedrockTextGenerationService"/> instance</returns>
    /// <exception cref="NotSupportedException">Thrown if provider or model is not supported for text generation.</exception>
    internal IBedrockTextGenerationService CreateTextGenerationService(string modelId)
    {
        (string modelProvider, string modelName) = this.GetModelProviderAndName(ScrubCrossRegionPrefix(modelId));

        switch (modelProvider.ToUpperInvariant())
        {
            case "AI21":
                if (modelName.StartsWith("jamba", StringComparison.OrdinalIgnoreCase))
                {
                    return new AI21JambaService();
                }
                if (modelName.StartsWith("j2-", StringComparison.OrdinalIgnoreCase))
                {
                    return new AI21JurassicService();
                }
                throw new NotSupportedException($"Unsupported AI21 model: {modelId}");
            case "AMAZON":
                if (modelName.StartsWith("titan-", StringComparison.OrdinalIgnoreCase))
                {
                    return new AmazonService();
                }
                throw new NotSupportedException($"Unsupported Amazon model: {modelId}");
            case "ANTHROPIC":
                if (modelName.StartsWith("claude-", StringComparison.OrdinalIgnoreCase))
                {
                    return new AnthropicService();
                }
                throw new NotSupportedException($"Unsupported Anthropic model: {modelId}");
            case "COHERE":
                if (modelName.StartsWith("command-r", StringComparison.OrdinalIgnoreCase))
                {
                    return new CohereCommandRService();
                }
                if (modelName.StartsWith("command-", StringComparison.OrdinalIgnoreCase))

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Use a supported AI21 text-generation modelId such as 'ai21.jamba-1-5-large-v1:0' or 'ai21.j2-ultra-v1'.
  2. Upgrade Connectors.Amazon to add support for newer AI21 models.
  3. Verify the modelId format is 'ai21.<model-name>' and that model access is enabled in the AWS Bedrock console.

Example fix

// before
var modelId = "ai21.jamba-instruct-v1"; // name does not start with 'jamba' as expected? check exact prefix

// after - use a recognized AI21 text-generation model
var modelId = "ai21.jamba-1-5-large-v1:0";
Defensive patterns

Strategy: validation

Validate before calling

static bool IsSupportedAi21TextModel(string modelId)
{
    var (_, name) = SplitModelId(modelId);
    return name.StartsWith("jamba", StringComparison.OrdinalIgnoreCase)
        || name.StartsWith("j2-", StringComparison.OrdinalIgnoreCase);
}

static (string provider, string name) SplitModelId(string modelId)
{
    var parts = modelId.Split('.');
    return (parts[0], parts.Length > 1 ? parts[1] : string.Empty);
}

Type guard

static bool IsSupportedAi21TextModel(string modelId)
{
    var (_, name) = SplitModelId(modelId);
    return name.StartsWith("jamba", StringComparison.OrdinalIgnoreCase)
        || name.StartsWith("j2-", StringComparison.OrdinalIgnoreCase);
}

Try / catch

try
{
    var text = await bedrockTextGen.GetTextContentAsync(prompt, settings, ct);
}
catch (NotSupportedException ex) when (ex.Message.Contains("AI21"))
{
    logger.LogError(ex, "AI21 modelId '{Id}' not supported for text generation. Use jamba* or j2-*.", modelId);
    throw;
}

Prevention

When it happens

Trigger: Calling text generation with modelId whose provider is 'ai21' but whose model-name segment matches neither 'jamba*' nor 'j2-*' (e.g. 'ai21.some-other-model'). Also a typo or a regional prefix that shifts parsing.

Common situations: Using a newly released AI21 model not yet recognized by the installed connector. Wrong/malformed modelId (missing dot, extra segment). Copying a modelId from docs that the current package version doesn't support.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/4fa0247309c8ec56. Report an issue: GitHub.