Skip to main content
Version: Next

OCI Generative AI Chat (In Development)

Spring AI Oracle provides a Spring AI ChatModel backed by OCI Generative AI.

This is the replacement path for new Spring AI applications that want to call OCI Generative AI through standard Spring AI ChatModel and ChatClient APIs.

Dependency Coordinates

<dependency>
<groupId>com.oracle.spring.ai</groupId>
<artifactId>spring-ai-starter-model-oracle</artifactId>
</dependency>

On-Demand Chat

Use spring.ai.model.chat=oci-genai to select the provider. This is the default when no chat selector is configured; set spring.ai.model.chat=none to disable chat auto-configuration. For on-demand serving, configure an OCI compartment and model ID.

spring:
ai:
model:
chat: oci-genai
oci:
genai:
authentication-type: FILE
config-file: ~/.oci/config
profile: DEFAULT
chat:
compartment-id: ocid1.compartment.oc1..example
serving-mode: ON_DEMAND
model: cohere.command-a-03-2025
temperature: 0.2
max-tokens: 512

The OCI model catalog lists current model IDs, regions, API formats, and supported serving modes: Pretrained Foundational Models in Generative AI.

Dedicated Endpoint Chat

For dedicated serving, configure the endpoint OCID instead of an on-demand model ID.

spring:
ai:
model:
chat: oci-genai
oci:
genai:
chat:
compartment-id: ocid1.compartment.oc1..example
serving-mode: DEDICATED
endpoint-id: ocid1.generativeaiendpoint.oc1..example

Usage

Inject the standard Spring AI model or build a ChatClient from it.

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.stereotype.Service;

@Service
class AnswerService {

private final ChatClient chatClient;

AnswerService(ChatModel chatModel) {
this.chatClient = ChatClient.builder(chatModel).build();
}

String answer(String question) {
return chatClient.prompt()
.user(question)
.call()
.content();
}
}

Use the standard Spring AI streaming APIs when the application should receive incremental chat responses.

import reactor.core.publisher.Flux;

Flux<String> answerStream(String question) {
return chatClient.prompt()
.user(question)
.stream()
.content();
}

Direct ChatModel callers can use stream(Prompt) and consume the returned Flux<ChatResponse>. Streaming uses OCI Generative AI server-sent events and supports the same text chat request formats as synchronous chat: GENERIC, COHERE_V2, and legacy COHERE.

Observability

Chat calls emit Spring AI model observations when an ObservationRegistry is available. Observations use Spring AI's standard chat model convention, include synchronous and streaming requests, and report OCI Generative AI as oci_genai.

Direct OracleGenAiChatModel construction uses OracleGenAiChatModel.builder(), which matches the Spring AI provider convention for optional dependencies such as retry, tool calling, and observation configuration.

Conversation Memory

Spring AI Oracle follows Spring AI chat memory conventions. The chat model is stateless and does not store conversation history; MessageChatMemoryAdvisor loads prior turns from ChatMemory and adds them to the prompt as typed Spring AI messages before the request reaches OCI Generative AI.

The starter includes Spring AI chat memory auto-configuration. Applications can use the default in-memory implementation for simple cases or provide their own ChatMemory or ChatMemoryRepository bean.

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatModel;

class ConversationalAnswers {

private final ChatClient chatClient;

ConversationalAnswers(ChatModel chatModel, ChatMemory chatMemory) {
this.chatClient = ChatClient.builder(chatModel)
.defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
.build();
}

String answer(String conversationId, String question) {
return chatClient.prompt()
.advisors(advisor -> advisor.param(ChatMemory.CONVERSATION_ID, conversationId))
.user(question)
.call()
.content();
}
}

Direct ChatModel callers manage memory explicitly by retrieving messages from ChatMemory and passing them in a Prompt.

Tool Calling

Spring AI Oracle supports Spring AI tool calling for OCI GENERIC and COHERE_V2 chat API formats. Register tools with the standard Spring AI ChatClient APIs; the model sends tool definitions to OCI Generative AI, executes returned tool calls through Spring AI's ToolCallingManager, and returns the final model response.

Synchronous and streaming calls use the same internal tool execution semantics. When a streaming response contains tool calls and internal tool execution is enabled, the provider buffers the tool-call stream and emits only the direct tool result or the final model response after tool execution.

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.annotation.Tool;

class WeatherTools {

@Tool(description = "Get the current weather for a city")
String weather(String city) {
return "72F and clear in " + city;
}
}

class ToolCallingAnswers {

private final ChatClient chatClient;

ToolCallingAnswers(ChatClient.Builder chatClientBuilder, WeatherTools weatherTools) {
this.chatClient = chatClientBuilder
.defaultTools(weatherTools)
.build();
}

String answer(String question) {
return chatClient.prompt()
.user(question)
.call()
.content();
}
}

Legacy COHERE chat requests continue to support text chat, but tool calling requires GENERIC or COHERE_V2. Use a COHERE_V2 model such as Cohere Command A, or set spring.ai.oci.genai.chat.api-format=GENERIC for model families that use the generic OCI chat request shape.

The live OCI Generative AI chat test suite includes bounded tool-calling coverage for selected GENERIC and COHERE_V2 chat models when OCI_COMPARTMENT_ID is set. Legacy COHERE models remain covered by text chat only because OCI does not support tool definitions or tool response messages for that chat format.

Applications can customize tool execution eligibility by providing a ToolExecutionEligibilityPredicate bean. Auto-configuration uses that bean when constructing the OracleGenAiChatModel; otherwise it uses Spring AI's default predicate.

Configuration

NameDescriptionRequiredDefault
spring.ai.model.chatSelects the Spring AI chat providerNooci-genai
spring.ai.oci.genai.chat.compartment-idOCI compartment OCID for chat requestsYes
spring.ai.oci.genai.chat.serving-modeON_DEMAND or DEDICATEDNoON_DEMAND
spring.ai.oci.genai.chat.modelOn-demand model IDFor on-demand
spring.ai.oci.genai.chat.endpoint-idDedicated endpoint OCIDFor dedicated
spring.ai.oci.genai.chat.api-formatOCI chat request format: GENERIC, COHERE_V2, or COHERE; inferred as COHERE_V2 for Cohere Command A, COHERE for other Cohere chat models, and GENERIC for other model familiesNoinferred
spring.ai.oci.genai.chat.temperatureSampling temperatureNo
spring.ai.oci.genai.chat.top-pTop P sampling valueNo
spring.ai.oci.genai.chat.top-kTop K sampling valueNo
spring.ai.oci.genai.chat.max-tokensMaximum output tokensNo
spring.ai.oci.genai.chat.frequency-penaltyRepetition penaltyNo
spring.ai.oci.genai.chat.presence-penaltyPresence penaltyNo
spring.ai.oci.genai.chat.stop-sequencesStop sequencesNo

Authentication

OCI authentication is configured under spring.ai.oci.genai.*.

NameDescriptionRequiredDefault
spring.ai.oci.genai.authentication-typeFILE, INSTANCE_PRINCIPAL, RESOURCE_PRINCIPAL, WORKLOAD_IDENTITY, SIMPLE, or SESSION_TOKENNoFILE
spring.ai.oci.genai.federation-endpointFederation endpoint for principal-based authNo
spring.ai.oci.genai.config-fileOCI config file pathNo
spring.ai.oci.genai.profileOCI config profileNoDEFAULT
spring.ai.oci.genai.tenant-idTenancy OCID for simple authFor simple auth
spring.ai.oci.genai.user-idUser OCID for simple authFor simple auth
spring.ai.oci.genai.fingerprintAPI key fingerprint for simple authFor simple auth
spring.ai.oci.genai.private-keyPrivate key content for simple authFor simple auth
spring.ai.oci.genai.pass-phrasePrivate key pass phraseNo
spring.ai.oci.genai.regionOCI regionNo
spring.ai.oci.genai.endpointOCI Generative AI inference endpoint overrideNo

If the application provides its own OCI BasicAuthenticationDetailsProvider or GenerativeAiInference bean, auto-configuration uses that bean instead of creating one from properties.

Current Scope

The Spring AI Oracle chat provider supports synchronous and streaming text chat. Tool calling is supported for GENERIC and COHERE_V2 chat formats. Structured output, multimodal chat, and rerank are planned as separate provider additions.