This guide helps existing oci-openai users migrate to oci-genai-auth.
- Replace dependency
oci-openaiwithoci-genai-auth. - Continue using the
openaiPython SDK client. - Use
OciSessionAuthto sign requests with OCI IAM. - Use endpoint
https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1with aprojectOCID.
Uninstall old package and install the new one:
pip uninstall -y oci-openai
pip install oci-genai-auth openaiIf you pin dependencies, update your requirements file accordingly.
from oci_openai import OciSessionAuthUse the OpenAI-compatible endpoint and provide project OCID:
import httpx
from openai import OpenAI
from oci_genai_auth import OciSessionAuth
client = OpenAI(
base_url="https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1",
api_key="not-used",
project="<ocid1.generativeaiproject...>",
http_client=httpx.Client(auth=OciSessionAuth(profile_name="DEFAULT")),
)base_url:https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1- required:
project=<PROJECT_OCID>