{"record":{"id":"6aa81688978c33ca","repo":"spring-projects/spring-ai","slug":"chat-completion-is-not-supported-for-this-model","errorCode":null,"errorMessage":"Chat completion is not supported for this model: ","messagePattern":"Chat completion is not supported for this model: ","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java","lineNumber":206,"sourceCode":"\n\t/**\n\t * Compute the embedding for the given text.\n\t *\n\t * @param request The embedding request.\n\t * @return Returns the embedding response.\n\t */\n\tprotected O embedding(I request) {\n\t\tthrow new UnsupportedOperationException(\"Embedding is not supported for this model: \" + this.modelId);\n\t}\n\n\t/**\n\t * Chat completion invocation.\n\t *\n\t * @param request The chat completion request.\n\t * @return The chat completion response.\n\t */\n\tprotected O chatCompletion(I request) {\n\t\tthrow new UnsupportedOperationException(\"Chat completion is not supported for this model: \" + this.modelId);\n\t}\n\n\t/**\n\t * Chat completion invocation with streaming response.\n\t *\n\t * @param request The chat completion request.\n\t * @return The chat completion response stream.\n\t */\n\tprotected Flux<SO> chatCompletionStream(I request) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\"Streaming chat completion is not supported for this model: \" + this.modelId);\n\t}\n\n\t/**\n\t * Internal method to invoke the model and return the response.\n\t * https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html\n\t * https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html\n\t * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/bedrockruntime/BedrockRuntimeClient.html#invokeModel","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java#L188-L224","documentation":"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.","triggerScenarios":"Calling chatCompletion(request) on an AbstractBedrockApi subclass that only implements embedding(), such as using the Titan embedding client for text generation.","commonSituations":"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.","solutions":["Use a chat-capable Bedrock API subclass (AnthropicChatApi, CohereChatApi, LlamaChatApi, TitanChatApi)","Confirm the modelId configured supports chat/invoke-mode completions","Fix Spring bean wiring so the ChatModel references the correct AbstractBedrockApi implementation"],"exampleFix":"// before\nvar api = new BedrockTitanEmbeddingApi(\"amazon.titan-embed-text-v1\", region);\napi.chatCompletion(request); // throws\n// after\nvar api = new BedrockAnthropicChatApi(\"anthropic.claude-v2\", region);\napi.chatCompletion(request);","handlingStrategy":"try-catch","validationCode":"if (modelId.contains(\"embed\")) { throw new IllegalStateException(\"Model \" + modelId + \" does not support chat completion\"); }","typeGuard":"boolean supportsChat(AbstractBedrockApi<?> api) { return !(api instanceof BedrockTitanEmbeddingApi); }","tryCatchPattern":"try { api.chatCompletion(request); } catch (UnsupportedOperationException e) { /* switch to a chat-capable client */ }","preventionTips":["Verify modelId capabilities on AWS Bedrock docs before wiring a ChatModel","Keep embedding and chat clients in separate, clearly named beans","Don't reuse embedding API clients for generation tasks"],"tags":["bedrock","chat-completion","unsupported-operation"],"backgroundTag":"method-not-implemented","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}