spring-projects/spring-ai · error · UnsupportedOperationException

streaming is not supported

Error message

streaming is not supported

What it means

ChatModel.stream(Prompt) is a default interface method that throws UnsupportedOperationException to signal the model implementation does not support streaming responses. It exists so single-shot models can implement only call() without being forced to provide a streaming API. Calling stream() on such an implementation always fails with this message.

Source

Thrown at spring-ai-model/src/main/java/org/springframework/ai/chat/model/ChatModel.java:65

	/**
	 * Gets the chat options for this model.
	 * @return the chat options
	 * @since 2.0.0
	 */
	default ChatOptions getOptions() {
		return ChatOptions.builder().build();
	}

	/**
	 * @deprecated use {@link #getOptions()} instead.
	 */
	@Deprecated(forRemoval = true)
	default ChatOptions getDefaultOptions() {
		return getOptions();
	}

	default Flux<ChatResponse> stream(Prompt prompt) {
		throw new UnsupportedOperationException("streaming is not supported");
	}

}

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Implement stream(Prompt) in your ChatModel, e.g. wrapping the blocking call() result: Flux.just(new ChatResponse(List.of(new Generation(...)))) or map the full response to a Flux.
  2. Use the blocking call(Prompt) API instead of streaming if streaming is not needed.
  3. Choose a model/adapters build that supports streaming for the target provider.

Example fix

// before
Flux<ChatResponse> flux = chatModel.stream(new Prompt("hi"));
// after
ChatResponse response = chatModel.call(new Prompt("hi"));
Defensive patterns

Strategy: type-guard

Validate before calling

if (chatModel.getClass().getMethod("stream", Prompt.class).getDeclaringClass() == ChatModel.class) { throw new IllegalStateException("model does not support streaming"); }

Type guard

boolean supportsStreaming(ChatModel m) { try { return m.getClass().getMethod("stream", Prompt.class).getDeclaringClass() != ChatModel.class; } catch (NoSuchMethodException e) { return false; } }

Try / catch

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

Prevention

When it happens

Trigger: Calling ChatClient (flux stream paths) or directly calling stream(prompt) on a ChatModel whose concrete class does not override stream(), e.g. in tests like whenSimplePromptThenFluxChatClientResponse.

Common situations: Developers switch a ChatClient from call() to .stream()/Flux output while the configured model adapter only implements the blocking call() method; occurs after swapping model providers or using custom model wrappers.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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