oci-genai-auth
The OCI GenAI Auth Python library provides OCI request-signing helpers for SDKs that call OCI Generative AI, including the OpenAI and Google Gen AI SDKs.
Table of Contents
- Installation
- Using OCI IAM Auth
- Using API Key Auth
- Using the Google Gen AI SDK
- Using OCI Enterprise AI Agents APIs
- Examples
- Contributing
- Security
- License
Installation
pip install oci-genai-auth
oci-genai-auth is designed to work together with the official OpenAI SDK.
Using OCI IAM Auth
Use OCI IAM auth when you want to sign requests with your OCI profile (session/user/resource/instance principal). Recommended if you are building OCI-native production workloads.
import httpx
from openai import OpenAI
from oci_genai_auth import OciSessionAuth
client = OpenAI(
base_url="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/openai/v1",
api_key="not-used",
http_client=httpx.Client(auth=OciSessionAuth(profile_name="DEFAULT")),
)
Using the Google Gen AI SDK
Install the optional Google SDK dependency:
pip install 'oci-genai-auth[google]'
With an OCI Generative AI API key:
import os
from google import genai
client = genai.Client(
api_key=os.environ["OCI_GENAI_API_KEY"],
http_options={
"base_url": "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/google"
},
)
For OCI IAM authentication, pass an OCI-signing httpx client. HttpxOciAuth
removes Google SDK API-key headers and query parameters before signing the request.
import httpx
from google import genai
from oci_genai_auth import OciSessionAuth
client = genai.Client(
api_key="not-used",
http_options={
"base_url": "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/google",
"httpx_client": httpx.Client(auth=OciSessionAuth(profile_name="DEFAULT")),
},
)
Using API Key Auth
Use OCI Generative AI API Keys if you want a long-lived API key style auth. Recommended if you are migrating from other OpenAI-compatible API providers.
To create the OCI Generative AI API Keys, follow this guide.
You don't need to install oci-genai-auth if you use API key auth.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/openai/v1",
api_key=os.getenv("OCI_GENAI_API_KEY"),
)
Using OCI Enterprise AI Agents APIs
OCI Enterprise AI Agents provides a unified API for interacting with models and agentic capabilities.
- It is compatible with OpenAI's Responses API and the Open Responses Spec, enabling developers to build agents with OpenAI SDK, OpenAI Agents SDK, LangChain, LangGraph, AI SDK, CrewAI, and more.
- It offers a uniform interface, auth, billing to access multiple model providers including OpenAI, Gemini, xAI, and GPT-OSS models hosted in OCI and your Dedicated AI Cluster.
- It provides built-in agentic primitives such as agent loop, reasoning, short-term memory, long-term memory, web search, file search, image generation, code execution, and more.
In addition to the compatible endpoint to Responses API, OCI Enterprise AI Agents also offers compatible endpoints to Files API, Vector Stores API, and Containers API.
Explore examples to get started.
Note: OpenAI commercial models and image generation are only available to Oracle internal teams at this moment.
import httpx
from openai import OpenAI
from oci_genai_auth import OciSessionAuth
client = OpenAI(
base_url="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/openai/v1",
api_key="not-used",
project="ocid1.generativeaiproject.oc1.us-chicago-1.aaaaaaaaexample",
http_client=httpx.Client(auth=OciSessionAuth(profile_name="DEFAULT")),
)
Examples
Demo code and instructions on how to run them can be found in the examples folder.
Install the example dependency with:
pip install -e '.[examples]'
The examples include Responses quickstarts and sync/async Chat Completions quickstarts:
- Responses API with API key auth:
examples/quickstart_responses_create_api_key.py - Responses API with OCI IAM auth:
examples/quickstart_responses_create_oci_iam.py - Chat Completions API with API key auth:
examples/quickstart_chat_completions_create_api_key.py - Chat Completions API with API key auth, async:
examples/quickstart_chat_completions_create_api_key_async.py - Chat Completions API with OCI IAM auth:
examples/quickstart_chat_completions_create_oci_iam.py - Chat Completions API with OCI IAM auth, async:
examples/quickstart_chat_completions_create_oci_iam_async.py - Google Gen AI API-key quickstart:
examples/google/generate_content_api_key.py - Google Gen AI OCI IAM quickstart:
examples/google/generate_content_oci_iam.py
Contributing
This project welcomes contributions from the community. Before submitting a pull request, please review our contribution guide
Security
Please consult the security guide for our responsible security vulnerability disclosure process
License
Copyright (c) 2026 Oracle and/or its affiliates.
Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/.
Metadata
Release files for oci-genai-auth 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oci_genai_auth-1.1.1.tar.gz | 25.8 kB | Without provenance | Details for oci_genai_auth-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oci_genai_auth-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for oci_genai_auth-1.1.1-py3-none-any.whl |
Total release size: 35.5 kB
Release files / oci_genai_auth-1.1.1.tar.gz
| Download URL | oci_genai_auth-1.1.1.tar.gz |
|---|---|
| Size | 25.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e550d0d76090dc5268b2d246b0e3a5e9b4b2f7dcfeaa2d158b0f9e93426b0dc0
|
|
BLAKE2b-256 checksum How to use checksums |
5a5ef9caadca8533d27c2b4c3655d923471ade59c43f5c94e5cbbd2f308368ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / oci_genai_auth-1.1.1-py3-none-any.whl
| Download URL | oci_genai_auth-1.1.1-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c31aa721131353e83bf7af494c16b46f673e2c75c3262ab9061b340f8337512f
|
|
BLAKE2b-256 checksum How to use checksums |
28ae460fa86f1494ba5670e67a9cc47ec7b53c91bdbfa64e3d683e72fca75a46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for oci-genai-auth 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.