Skip to main content


This notebook provides a quick overview for getting started with OCIGenAI chat models. For detailed documentation of all ChatOCIGenAI features and configurations head to the API reference.

Oracle Cloud Infrastructure (OCI) Generative AI is a fully managed service that provides a set of state-of-the-art, customizable large language models (LLMs) that cover a wide range of use cases, and which is available through a single API. Using the OCI Generative AI service you can access ready-to-use pretrained models, or create and host your own fine-tuned custom models based on your own data on dedicated AI clusters. Detailed documentation of the service and API is available here and here.


Integration details

ClassPackageLocalSerializableJS supportPackage downloadsPackage latest
ChatOCIGenAIlangchain-communityPyPI - DownloadsPyPI - Version

Model features

Tool callingStructured outputJSON modeImage inputAudio inputVideo inputToken-level streamingNative asyncToken usageLogprobs


To access OCIGenAI models you'll need to install the oci and langchain-community packages.


The credentials and authentication methods supported for this integration are equivalent to those used with other OCI services and follow the standard SDK authentication methods, specifically API Key, session token, instance principal, and resource principal.

API key is the default authentication method used in the examples above. The following example demonstrates how to use a different authentication method (session token)


The LangChain OCIGenAI integration lives in the langchain-community package and you will also need to install the oci package:

%pip install -qU langchain-community oci


Now we can instantiate our model object and generate chat completions:

from langchain_community.chat_models.oci_generative_ai import ChatOCIGenAI
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage

chat = ChatOCIGenAI(
model_kwargs={"temperature": 0.7, "max_tokens": 500},


messages = [
SystemMessage(content="your are an AI assistant."),
AIMessage(content="Hi there human!"),
HumanMessage(content="tell me a joke."),
response = chat.invoke(messages)


We can chain our model with a prompt template like so:

from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_template("Tell me a joke about {topic}")
chain = prompt | chat

response = chain.invoke({"topic": "dogs"})
API Reference:ChatPromptTemplate

API reference

For detailed documentation of all ChatOCIGenAI features and configurations head to the API reference:

Was this page helpful?

You can also leave detailed feedback on GitHub.