{"record":{"id":"58463d93ac735e60","repo":"microsoft/semantic-kernel","slug":"streaming-not-supported-by-this-model","errorCode":null,"errorMessage":"Streaming not supported by this model.","messagePattern":"Streaming not supported by this model\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/Models/AI21Labs/AI21JurassicService.cs","lineNumber":55,"sourceCode":"    public IReadOnlyList<TextContent> GetInvokeResponseBody(InvokeModelResponse response)\n    {\n        using var reader = new StreamReader(response.Body);\n        var responseBody = JsonSerializer.Deserialize<AI21JurassicResponse>(reader.ReadToEnd());\n\n        if (responseBody?.Completions is not { Count: > 0 })\n        {\n            return [];\n        }\n\n        return responseBody.Completions\n            .Select(completion => new TextContent(completion.Data?.Text, innerContent: responseBody))\n            .ToList();\n    }\n\n    /// <inheritdoc/>\n    public IEnumerable<StreamingTextContent> GetTextStreamOutput(JsonNode chunk)\n    {\n        throw new NotSupportedException(\"Streaming not supported by this model.\");\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":58,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/Models/AI21Labs/AI21JurassicService.cs#L37-L58","documentation":"Thrown by AI21JurassicService.GetTextStreamOutput. AI21 Jurassic (j2-) models do not support streaming, so any streaming text-generation call against a j2- model hits this NotSupportedException. The interface method is implemented but explicitly forbidden for this provider.","triggerScenarios":"Calling a streaming text API (GetStreamingTextContentsAsync / InvokeStreamingAsync) with a modelId whose provider resolves to AI21 Jurassic, e.g. 'ai21.j2-ultra' or 'ai21.j2-mid'. BedrockServiceFactory.CreateTextGenerationService maps 'j2-' to AI21JurassicService, and its GetTextStreamOutput always throws.","commonSituations":"Applying the same streaming code path used for Claude/Titan to an AI21 j2 model. Migrating a streaming pipeline onto a Jurassic model. Config-driven model selection where the config points at a non-streaming model.","solutions":["Use a non-streaming text-generation call (GetTextContentAsync / InvokeAsync) for AI21 j2 models.","Switch to a streaming-capable model (Claude, Titan, Meta Llama, Mistral, Cohere command-r, AI21 Jamba) if streaming is required.","Guard the modelId before choosing the streaming path and fall back to non-streaming for j2-."],"exampleFix":"// before\nawait foreach (var chunk in kernel.InvokeStreamingAsync<StreamingTextContent>(promptFunc)) { /* ... */ }\n// throws when modelId = ai21.j2-ultra\n\n// after\nbool streamingCapable = !modelId.Contains(\"j2-\", StringComparison.OrdinalIgnoreCase);\nif (streamingCapable)\n    await foreach (var chunk in kernel.InvokeStreamingAsync<StreamingTextContent>(promptFunc)) { /* ... */ }\nelse\n    await kernel.InvokeAsync(promptFunc);","handlingStrategy":"type-guard","validationCode":"bool SupportsStreaming(string modelId)\n{\n    var p = modelId.Split('.');\n    if (p.Length < 2) return true;\n    var provider = p[0].ToUpperInvariant();\n    var name = p[1].ToUpperInvariant();\n    // AI21 Jurassic (j2-) is the only shipped text model that does not stream\n    return !(provider == \"AI21\" && name.StartsWith(\"J2-\"));\n}","typeGuard":"bool IsStreamingCapable(string modelId)\n{\n    var parts = modelId.Split('.');\n    return !(parts.Length > 1 && parts[0].Equals(\"ai21\", StringComparison.OrdinalIgnoreCase)\n             && parts[1].StartsWith(\"j2-\", StringComparison.OrdinalIgnoreCase));\n}","tryCatchPattern":"try { await foreach (var c in kernel.InvokeStreamingAsync<StreamingTextContent>(fn, ct)) { /* ... */ } }\ncatch (NotSupportedException ex) when (ex.Message == \"Streaming not supported by this model.\")\n{ _logger.LogInformation(\"Model {ModelId} cannot stream; using non-streaming call\", modelId); await kernel.InvokeAsync(fn); }","preventionTips":["Gate streaming behind a capability check keyed on the provider/model prefix.","Keep a known non-streaming list (AI21 j2-) when modelId is config-driven.","Default to non-streaming unless streaming is required."],"tags":["bedrock","streaming","ai21","model-capability","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}