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

Chat completion is not supported for this model:

Error message

Chat completion is not supported for this model: 

What it means

AbstractBedrockApi provides default chatCompletion(I) implementations that throw UnsupportedOperationException. Subclasses that only support embeddings (e.g. the Titan embedding API) do not override it, so any chat completion request routed to such a client is rejected because the underlying Bedrock modelId does not expose a chat/converse-style invocation.

Source

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

	/**
	 * Compute the embedding for the given text.
	 *
	 * @param request The embedding request.
	 * @return Returns the embedding response.
	 */
	protected O embedding(I request) {
		throw new UnsupportedOperationException("Embedding is not supported for this model: " + this.modelId);
	}

	/**
	 * 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

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Use a chat-capable Bedrock API subclass (AnthropicChatApi, CohereChatApi, LlamaChatApi, TitanChatApi)
  2. Confirm the modelId configured supports chat/invoke-mode completions
  3. Fix Spring bean wiring so the ChatModel references the correct AbstractBedrockApi implementation

Example fix

// before
var api = new BedrockTitanEmbeddingApi("amazon.titan-embed-text-v1", region);
api.chatCompletion(request); // throws
// after
var api = new BedrockAnthropicChatApi("anthropic.claude-v2", region);
api.chatCompletion(request);
Defensive patterns

Strategy: try-catch

Validate before calling

if (modelId.contains("embed")) { throw new IllegalStateException("Model " + modelId + " does not support chat completion"); }

Type guard

boolean supportsChat(AbstractBedrockApi<?> api) { return !(api instanceof BedrockTitanEmbeddingApi); }

Try / catch

try { api.chatCompletion(request); } catch (UnsupportedOperationException e) { /* switch to a chat-capable client */ }

Prevention

When it happens

Trigger: Calling chatCompletion(request) on an AbstractBedrockApi subclass that only implements embedding(), such as using the Titan embedding client for text generation.

Common situations: Wiring an embedding API client into a ChatModel; choosing a non-chat Bedrock model ID (e.g. titan-embed) and attempting conversation calls; misconfigured Spring beans of type AbstractBedrockApi.

Related errors


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