spring-projects/spring-ai · error · java.lang.UnsupportedOperationException

Streaming chat completion is not supported for this model:

Error message

Streaming chat completion is not supported for this model: 

What it means

AbstractBedrockApi's default chatCompletionStream(I) throws UnsupportedOperationException. Streaming chat completion is an optional capability: subclasses whose Bedrock model does not support streaming responses (or does not implement the override) reject streaming calls, so requesting a Flux-based streaming invocation on such a client fails immediately.

Source

Thrown at models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java:216

	/**
	 * Chat completion invocation.
	 *
	 * @param request The chat completion request.
	 * @return The chat completion response.
	 */
	protected O chatCompletion(I request) {
		throw new UnsupportedOperationException("Chat completion is not supported for this model: " + this.modelId);
	}

	/**
	 * Chat completion invocation with streaming response.
	 *
	 * @param request The chat completion request.
	 * @return The chat completion response stream.
	 */
	protected Flux<SO> chatCompletionStream(I request) {
		throw new UnsupportedOperationException(
				"Streaming chat completion is not supported for this model: " + this.modelId);
	}

	/**
	 * Internal method to invoke the model and return the response.
	 * https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html
	 * https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html
	 * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/bedrockruntime/BedrockRuntimeClient.html#invokeModel
	 *
	 * @param request Model invocation request.
	 * @param clazz The response class type
	 * @return The model invocation response.
	 *
	 */
	protected O internalInvocation(I request, Class<O> clazz) {

		SdkBytes body;
		try {

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Use a Bedrock model/client that overrides chatCompletionStream (e.g. Anthropic, Cohere streaming implementations)
  2. Fall back to the blocking chatCompletion() call when streaming is unavailable
  3. Check the concrete API class documentation for streaming support before calling stream()

Example fix

// before
Flux<ChatResponse> flux = model.stream(new Prompt("hi")); // throws for non-streaming model
// after
ChatResponse response = model.call(new Prompt("hi")); // blocking fallback
Defensive patterns

Strategy: fallback

Validate before calling

boolean streamingKnown = Set.of("anthropic","cohere","llama","titan").stream().anyMatch(modelId::contains);

Try / catch

try { return model.stream(prompt); } catch (UnsupportedOperationException e) { return Flux.just(model.call(prompt)); }

Prevention

When it happens

Trigger: Calling chatCompletionStream(request) — directly or via ChatModel.stream() — on a Bedrock API subclass that did not override the streaming method, e.g. embedding-only or non-streaming chat models.

Common situations: Using .stream() on a Bedrock chat model whose backing model/API does not implement streaming; generic code that always streams regardless of model capabilities.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/4e27cbbe9a70523d. Report an issue: GitHub.