Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
OciOpenAI
✓ from oci_openai import OciOpenAI
✗ from oci_openai import OCIAuthMiddleware
AsyncOciOpenAI
✓ from oci_openai import AsyncOciOpenAI
OciUserPrincipalAuth
✓ from oci_openai import OciUserPrincipalAuth
Initialize OpenAI client with OCI authentication middleware.
import os
from openai import OpenAI
from oci_openai import OCIAuthMiddleware
default_compartment = os.environ.get('OCI_COMPARTMENT_ID', '')
client = OpenAI(
api_key=default_compartment, # Placeholder, OCI signature is used instead
default_headers={
"oci-auth-middleware": OCIAuthMiddleware()
}
)
# Example: client.chat.completions.create(...)
Debug
Known issues
gotchaThe OCI authentication middleware replaces the standard API key; the 'api_key' parameter in OpenAI client is ignored but must be set to a non-empty string (e.g., a placeholder).fixSet api_key to any non-empty string, e.g., api_key='placeholder'.
affects: >=1.0.0
breakingVersion 1.0.0 introduced a breaking change: the middleware class was renamed from 'OCIAuth' to 'OCIAuthMiddleware'.fixReplace 'from oci_openai import OCIAuth' with 'from oci_openai import OCIAuthMiddleware'.
affects: <1.0.0 to >=1.0.0
gotchaOCI environment variables (OCI_CONFIG_FILE, OCI_CONFIG_PROFILE) must be set correctly; otherwise the middleware silently fails to authenticate.fixVerify OCI configuration by running 'oci os ns get' before using the library.
affects: >=1.0.0
deprecatedPython 3.9 is the minimum; support for older Python versions was dropped in earlier releases.fixEnsure Python version >= 3.9.
affects: >=1.0.0
Upgrade
Version history
1.1.0latest on PyPI · released Feb 3, 2026
Audit
Dependencies
openairequiredOCI OpenAI works as a request middleware for the OpenAI Python SDK
ocirequiredOCI SDK for authentication and signing