Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,14 @@ The **OCI GenAI Auth** Python library provides OCI request-signing helpers for t

## Table of Contents

- [Before you start](#before-you-start)
- [Using OCI IAM Auth](#using-oci-iam-auth)
- [Using API Key Auth](#using-api-key-auth)
- [Using AgentHub APIs (non-passthrough)](#using-agenthub-apis-non-passthrough)
- [Using Partner APIs (passthrough)](#using-partner-apis-passthrough)
- [Running the Examples](#running-the-examples)

## Before you start

**Important!**

Note that this package, as well as API keys package described below, only supports OpenAI, xAi Grok and Meta LLama models on OCI Generative AI.

Before you start using this package, determine if this is the right option for you.

If you are looking for a seamless way to port your code from an OpenAI compatible endpoint to OCI Generative AI endpoint, and you are currently using OpenAI-style API keys, you might want to use [OCI Generative AI API Keys](https://docs.oracle.com/en-us/iaas/Content/generative-ai/api-keys.htm) instead.

With OCI Generative AI API Keys, use the native `openai` SDK like before. Just update the `base_url`, create API keys in your OCI console, insure the policy granting the key access to generative AI services is present and you are good to go.

- Create an API key in Console: **Generative AI** -> **API Keys**
- Create a security policy: **Identity & Security** -> **Policies**

To authorize a specific API Key
```
allow any-user to use generative-ai-family in compartment <compartment-name> where ALL { request.principal.type='generativeaiapikey', request.principal.id='ocid1.generativeaiapikey.oc1.us-chicago-1....' }
```

To authorize any API Key
```
allow any-user to use generative-ai-family in compartment <compartment-name> where ALL { request.principal.type='generativeaiapikey' }
```
- [Contributing](#contributing)
- [Security](#security)
- [License](#license)

## Using OCI IAM Auth

Expand All @@ -57,7 +34,7 @@ client = OpenAI(

## Using API Key Auth

Use OCI Generative AI API Keys if you want a direct API-key workflow with the OpenAI SDK.
Use OCI Generative AI API Keys if you want a direct API-key workflow with the OpenAI SDK. In-order to create the OCI Generative AI API Keys, follow [this guide](https://docs.oracle.com/en-us/iaas/Content/generative-ai/api-keys.htm)

```python
import os
Expand Down Expand Up @@ -115,3 +92,18 @@ client = OpenAI(
3. Install optional dev dependencies: `pip install -e '.[dev]'`.

Run an example either by calling its `main()` method or from the command line.

## Contributing

*If your project has specific contribution requirements, update the CONTRIBUTING.md file to ensure those requirements are clearly explained*

This project welcomes contributions from the community. Before submitting a pull request, please [review our contribution guide](./CONTRIBUTING.md)

## Security

Please consult the [security guide](./SECURITY.md) 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/.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

from agents import Agent, Runner, set_default_openai_client, trace

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "openai.gpt-4o"
MODEL = "xai.grok-4-1-fast-reasoning"

# Set the OCI OpenAI Client as the default client to use with OpenAI Agents
set_default_openai_client(common.build_agenthub_async_client())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@
PROJECT_OCID = "<<ENTER_PROJECT_ID>>"
REGION = "us-chicago-1"

AGENTHUB_OPENAI_URL = f"https://inference.generativeai.{REGION}.oci.oraclecloud.com/openai/v1"
AGENTHUB_OPENAI_CP_URL = f"https://generativeai.{REGION}.oci.oraclecloud.com/20231130/openai/v1"
AGENTHUB_URL = f"https://inference.generativeai.{REGION}.oci.oraclecloud.com/openai/v1"
AGENTHUB_CP_URL = f"https://generativeai.{REGION}.oci.oraclecloud.com/20231130/openai/v1"


def build_agenthub_client() -> OpenAI:
return OpenAI(
base_url=AGENTHUB_OPENAI_URL,
api_key=os.getenv("OCI_GENAI_API_KEY", "not-used"),
base_url=AGENTHUB_URL,
api_key="not-used",
project=os.getenv("OCI_GENAI_PROJECT_ID", PROJECT_OCID),
http_client=httpx.Client(auth=OciSessionAuth(profile_name=PROFILE_NAME)),
)


def build_agenthub_async_client() -> AsyncOpenAI:
return AsyncOpenAI(
base_url=AGENTHUB_OPENAI_URL,
api_key=os.getenv("OCI_GENAI_API_KEY", "not-used"),
base_url=AGENTHUB_URL,
api_key="not-used",
project=os.getenv("OCI_GENAI_PROJECT_ID", PROJECT_OCID),
http_client=httpx.AsyncClient(auth=OciSessionAuth(profile_name=PROFILE_NAME)),
)


def build_agenthub_cp_client() -> OpenAI:
return OpenAI(
base_url=AGENTHUB_OPENAI_CP_URL,
api_key=os.getenv("OCI_GENAI_API_KEY", "not-used"),
base_url=AGENTHUB_CP_URL,
api_key="not-used",
http_client=httpx.Client(auth=OciSessionAuth(profile_name=PROFILE_NAME)),
project=os.getenv("OCI_GENAI_PROJECT_ID", PROJECT_OCID),
default_headers={"opc-compartment-id": COMPARTMENT_ID},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates CRUD operations for conversation items in AgentHub."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates CRUD operations for conversations in AgentHub."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pathlib import Path

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from rich import print

from examples.agenthub.openai import common
from examples.agenthub import common
from examples.fc_tools import fc_tools

MODEL = "openai.gpt-4.1"
MODEL = "xai.grok-4-1-fast-reasoning"


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from openai.types.responses.response_input_param import FunctionCallOutput
from rich import print

from examples.agenthub.openai import common
from examples.agenthub import common
from examples.fc_tools import execute_function_call, fc_tools

MODEL = "openai.gpt-4.1"
MODEL = "xai.grok-4-1-fast-reasoning"


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from rich import print

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "openai.gpt-4.1"
MODEL = "xai.grok-4-1-fast-reasoning"


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from rich import print

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "openai.gpt-4.1"
MODEL = "xai.grok-4-1-fast-reasoning"


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from rich import print

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "openai.gpt-4.1"
MODEL = "xai.grok-4-1-fast-reasoning"


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from rich import print

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "openai.gpt-4.1"
MODEL = "xai.grok-4-1-fast-reasoning"


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import time

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "xai.grok-4-1-fast-reasoning"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import time

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "openai.gpt-5.1"
MODEL = "xai.grok-4-1-fast-reasoning"


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates short-term memory optimization in AgentHub."""

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "xai.grok-4-1-fast-reasoning"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates a multi-turn flow using the Conversations API."""

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL = "xai.grok-4-1-fast-reasoning"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates chaining responses across multiple turns."""

from examples.agenthub.openai import common
from examples.agenthub import common

model = "xai.grok-4-1-fast-reasoning"

Expand Down
2 changes: 0 additions & 2 deletions examples/agenthub/openai/vector_stores/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from openai import OpenAI

from examples.agenthub.openai.common import PROJECT_OCID
from examples.agenthub.common import PROJECT_OCID


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
3. Run this script
"""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates creating a response with the Responses API on AgentHub."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates creating a response with storage disabled using the Responses API."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates deleting a response from the Responses API."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates providing file input by file ID to the Responses API."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates providing file input by URL to the Responses API."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates retrieving a response from the Responses API."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import base64
from pathlib import Path

from examples.agenthub.openai import common
from examples.agenthub import common


def encode_image(image_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates providing image input via URL to the Responses API."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

"""Demonstrates a reasoning-style Responses API request."""

from examples.agenthub.openai import common
from examples.agenthub import common

MODEL="openai.gpt-oss-120b"

def main():
client = common.build_agenthub_client()
Expand All @@ -15,7 +16,7 @@ def main():
"""

response = client.responses.create(
model="openai.gpt-oss-120b",
model=MODEL,
input=prompt,
reasoning={"effort": "medium", "summary": "detailed"},
stream=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Demonstrates streaming Responses API output and handling text deltas."""

from examples.agenthub.openai import common
from examples.agenthub import common


def main():
Expand Down
Loading
Loading