> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OCI Generative AI Integration for LangChain

> Integrate with OCI Generative AI using LangChain Python.

This page covers all LangChain integrations with [Oracle Cloud Infrastructure (OCI)](https://www.oracle.com/cloud/).

## Installation and Setup

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-oci oci
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-oci oci
  ```
</CodeGroup>

## Authentication

<Note>
  Initializing [ChatOCIGenAI](#chatocigenai) is resource-intensive. For optimal performance, it is recommended to treat this client as a singleton and reuse the instance across your application.
</Note>

Four authentication methods are supported for OCI services. All methods follow the [standard OCI SDK authentication](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdk_authentication_methods.htm).

### API Key (Default)

Uses credentials from `~/.oci/config`:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import ChatOCIGenAI

llm = ChatOCIGenAI(
    model_id="meta.llama-3.3-70b-instruct",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..xxx",
    auth_type="API_KEY",        # Default
    auth_profile="DEFAULT",      # Profile name in ~/.oci/config
)
```

### Security Token

For session-based authentication:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
oci session authenticate --profile-name MY_PROFILE
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
llm = ChatOCIGenAI(
    model_id="meta.llama-3.3-70b-instruct",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..your-compartment-id",
    auth_type="SECURITY_TOKEN",
    auth_profile="MY_PROFILE",
)
```

### Instance Principal

For applications running on OCI compute instances:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
llm = ChatOCIGenAI(
    model_id="meta.llama-3.3-70b-instruct",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..your-compartment-id",
    auth_type="INSTANCE_PRINCIPAL",
)
```

### Resource Principal

For OCI Functions and other resources:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
llm = ChatOCIGenAI(
    model_id="meta.llama-3.3-70b-instruct",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..your-compartment-id",
    auth_type="RESOURCE_PRINCIPAL",
)
```

***

## OCI Generative AI

> Oracle Cloud Infrastructure (OCI) [Generative AI](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm) 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 are 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.

### Chat Models

#### ChatOCIGenAI

Main chat model for OCI Generative AI service with full LangChain feature support.

See [usage example](/oss/python/integrations/chat/oci_generative_ai).

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import ChatOCIGenAI

llm = ChatOCIGenAI(
    model_id="meta.llama-3.3-70b-instruct",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..xxx",
)
```

**Supported Features:**

* ✅ Tool calling (including parallel tools with Llama 4+)
* ✅ Structured output (Pydantic, JSON mode)
* ✅ Vision & multimodal (13+ models support images)
* ✅ Streaming (sync and async)
* ✅ Async operations (ainvoke, astream, abatch)
* ✅ PDF, video, audio processing (Gemini models)

#### ChatOCIOpenAI

OpenAI Responses API compatibility for OCI commercial OpenAI models.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import ChatOCIOpenAI

llm = ChatOCIOpenAI(
    model="openai.gpt-5.5",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..your-compartment-id",
)
```

**Features:**

* OpenAI-compatible interface
* Conversation store support for persistent memory
* Access to GPT-4, GPT-5, o1, o3 models (where available)

### Embedding Models

#### OCIGenAIEmbeddings

Text and image embedding models.

See [usage example](/oss/python/integrations/embeddings/oci_generative_ai).

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import OCIGenAIEmbeddings

# Text embeddings
embeddings = OCIGenAIEmbeddings(
    model_id="cohere.embed-english-v3.0",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..xxx",
)

# Image embeddings (with multimodal models)
vector = embeddings.embed_image("./architecture_diagram.png")
```

**Available Models:**

* `cohere.embed-english-v3.0` (1024 dimensions)
* `cohere.embed-multilingual-v3.0` (1024 dimensions)
* `cohere.embed-v4.0` (text + image, 256-1536 dimensions)

### Vision & Multimodal

13+ vision-capable models across Meta Llama, Google Gemini, xAI Grok, and Cohere:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.messages import HumanMessage
from langchain_oci import ChatOCIGenAI, load_image

llm = ChatOCIGenAI(
    model_id="meta.llama-3.2-90b-vision-instruct",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..xxx",
)

message = HumanMessage(content=[
    {"type": "text", "text": "Identify all microservices, data flows, and external dependencies."},
    load_image("./architecture_diagram.png"),
])
response = llm.invoke([message])
```

**Gemini Multimodal** (PDF, video, audio):

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import base64
from langchain.messages import HumanMessage
from langchain_oci import ChatOCIGenAI

llm = ChatOCIGenAI(
    model_id="google.gemini-2.5-flash",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..your-compartment-id",
)

# PDF processing - Extract structured data from contracts
with open("vendor_contract.pdf", "rb") as f:
    pdf_data = base64.b64encode(f.read()).decode()

message = HumanMessage(content=[
    {"type": "text", "text": "Extract: parties, effective date, payment terms. Return as JSON."},
    {"type": "document_url", "document_url": {"url": f"data:application/pdf;base64,{pdf_data}"}}
])
response = llm.invoke([message])
```

### AI Agents

Create LangGraph-powered ReAct agents with OCI models:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.tools import tool
from langchain_oci import create_oci_agent

@tool
def query_infrastructure(resource_type: str, region: str) -> dict:
    """Query OCI infrastructure status and health metrics.

    Args:
        resource_type: Type of resource (compute, database, network)
        region: OCI region to query
    """
    # Example: Call OCI monitoring API
    return {
        "status": "healthy",
        "active_instances": 12,
        "cpu_utilization": "45%",
        "alerts": []
    }

agent = create_oci_agent(
    model_id="meta.llama-4-scout-17b-16e-instruct",
    tools=[query_infrastructure],
    compartment_id="ocid1.compartment.oc1..xxx",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    system_prompt="You are an infrastructure monitoring assistant.",
)

from langchain.messages import HumanMessage
result = agent.invoke({
    "messages": [HumanMessage(content="Check compute resource health in us-ashburn-1")]
})
```

### Provider Coverage

| Provider   | Example Models                        | Key Features                  |
| ---------- | ------------------------------------- | ----------------------------- |
| **Meta**   | Llama 3.2, 3.3, 4 (Scout, Maverick)   | Vision, parallel tool calls   |
| **Google** | Gemini 2.0/2.5 Flash, Flash Lite, Pro | PDF, video, audio processing  |
| **xAI**    | Grok 3, 4 (Fast, Mini)                | Vision, reasoning modes       |
| **Cohere** | Command R+, Command A                 | RAG optimization, V2 vision   |
| **OpenAI** | GPT-5.5, GPT-5, o1, o3                | Reasoning (via ChatOCIOpenAI) |

> **Note:** Model availability varies by region. See the [OCI Generative AI documentation](https://docs.oracle.com/en-us/iaas/Content/generative-ai/pretrained-models.htm) for the current model catalog.

***

## OCI Data Science Model Deployments

> [OCI Data Science](https://docs.oracle.com/en-us/iaas/data-science/using/home.htm) is a fully managed and serverless platform for data science teams. Deploy custom models as endpoints using the [OCI Data Science Model Deployment Service](https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-about.htm).

### ChatOCIModelDeployment

Chat model for OCI Data Science Model Deployments.

See the [ChatOCIModelDeployment integration guide](/oss/python/integrations/chat/oci_data_science).

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import ChatOCIModelDeployment

llm = ChatOCIModelDeployment(
    endpoint="https://modeldeployment.us-ashburn-1.oci.customer-oci.com/ocid1.datasciencemodeldeployment.oc1.iad.xxx/predict",
    model="odsc-llm",
)
```

### ChatOCIModelDeploymentVLLM

Optimized for vLLM-based deployments with streaming support:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import ChatOCIModelDeploymentVLLM

llm = ChatOCIModelDeploymentVLLM(
    endpoint="https://modeldeployment.us-ashburn-1.oci.customer-oci.com/ocid1.datasciencemodeldeployment.oc1.iad.xxx/predict",
    model="meta-llama/Llama-2-7b-chat-hf",
    streaming=True,
)
```

### ChatOCIModelDeploymentTGI

For Text Generation Inference (TGI) deployments:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import ChatOCIModelDeploymentTGI

llm = ChatOCIModelDeploymentTGI(
    endpoint="https://modeldeployment.us-ashburn-1.oci.customer-oci.com/ocid1.datasciencemodeldeployment.oc1.iad.xxx/predict",
)
```

***

## Samples

For comprehensive guides covering all features, see the [langchain-oci samples](https://github.com/oracle/langchain-oracle/tree/main/samples):

| Sample                                                                                                           | Level        | Topics                                |
| ---------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------- |
| [01: Getting Started](https://github.com/oracle/langchain-oracle/tree/main/samples/01-getting-started)           | Beginner     | Authentication, basic chat, providers |
| [02: Vision & Multimodal](https://github.com/oracle/langchain-oracle/tree/main/samples/02-vision-and-multimodal) | Beginner     | Image analysis, PDF, video, audio     |
| [03: Building AI Agents](https://github.com/oracle/langchain-oracle/tree/main/samples/03-building-ai-agents)     | Intermediate | ReAct agents, tools, memory           |
| [04: Tool Calling Mastery](https://github.com/oracle/langchain-oracle/tree/main/samples/04-tool-calling-mastery) | Intermediate | Parallel tools, workflows             |
| [05: Structured Output](https://github.com/oracle/langchain-oracle/tree/main/samples/05-structured-output)       | Intermediate | Pydantic schemas, JSON modes          |
| [07: Async for Production](https://github.com/oracle/langchain-oracle/tree/main/samples/07-async-for-production) | Advanced     | ainvoke, astream, FastAPI             |
| [09: Provider Deep Dive](https://github.com/oracle/langchain-oracle/tree/main/samples/09-provider-deep-dive)     | Specialized  | Meta, Gemini, Cohere, xAI specifics   |
| [10: Embeddings](https://github.com/oracle/langchain-oracle/tree/main/samples/10-embeddings)                     | Specialized  | Text & image embeddings, RAG          |

***

## Additional Resources

* [API Reference](https://github.com/oracle/langchain-oracle/tree/main/libs/oci)
* [GitHub Repository](https://github.com/oracle/langchain-oracle)
* [OCI Generative AI Documentation](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm)
* [OCI Data Science Documentation](https://docs.oracle.com/en-us/iaas/data-science/using/home.htm)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/providers/oci.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
