Skip to content

Commit 51e7569

Browse files
committed
Revert "Also remove Partner API section and examples"
This reverts commit 59bb6bd.
1 parent 59bb6bd commit 51e7569

11 files changed

Lines changed: 372 additions & 5 deletions

MIGRATION.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This guide helps existing `oci-openai` users migrate to `oci-genai-auth`.
77
- Replace dependency `oci-openai` with `oci-genai-auth`.
88
- Continue using the `openai` Python SDK client.
99
- Use `OciSessionAuth` to sign requests with OCI IAM.
10-
- Use endpoint `https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1` with a `project` OCID.
10+
- Choose endpoint/config based on API mode.:
11+
- OCI Enterprise AI Agents: `https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1` + `project`
12+
- Partner : `https://inference.generativeai.<region>.oci.oraclecloud.com/20231130/actions/v1` + `opc-compartment-id`
1113

1214
## 1) Dependency Changes
1315

@@ -28,6 +30,8 @@ from oci_openai import OciSessionAuth
2830

2931
## 3) Client Initialization Changes
3032

33+
### OCI Enterprise AI Agents
34+
3135
Use the OpenAI-compatible endpoint and provide project OCID:
3236

3337
```python
@@ -43,7 +47,28 @@ client = OpenAI(
4347
)
4448
```
4549

50+
### Partner APIs
51+
52+
Use `/v1` and include compartment header:
53+
54+
```python
55+
import httpx
56+
from openai import OpenAI
57+
from oci_genai_auth import OciSessionAuth
58+
59+
client = OpenAI(
60+
base_url="https://inference.generativeai.<region>.oci.oraclecloud.com/v1",
61+
api_key="not-used",
62+
default_headers={"opc-compartment-id": "<ocid1.compartment...>"},
63+
http_client=httpx.Client(auth=OciSessionAuth(profile_name="DEFAULT")),
64+
)
65+
```
66+
4667
## 4) Endpoint and required parameters
4768

48-
- `base_url`: `https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1`
49-
- required: `project=<PROJECT_OCID>`
69+
- OCI Enterprise AI Agents:
70+
- `base_url`: `https://inference.generativeai.<region>.oci.oraclecloud.com/openai/v1`
71+
- required: `project=<PROJECT_OCID>`
72+
- Partner:
73+
- `base_url`: `https://inference.generativeai.<region>.oci.oraclecloud.com/v1`
74+
- required header: `opc-compartment-id=<COMPARTMENT_OCID>`

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ The **OCI GenAI Auth** Python library provides OCI request-signing helpers for t
1111
- [Using OCI IAM Auth](#using-oci-iam-auth)
1212
- [Using API Key Auth](#using-api-key-auth)
1313
- [Using OCI Enterprise AI Agents APIs](#using-oci-enterprise-ai-agents-apis)
14-
- [Examples](#examples)
14+
- [Using Partner APIs (passthrough)](#using-partner-apis-passthrough)
15+
- [Running the Examples](#running-the-examples)
1516
- [Contributing](#contributing)
1617
- [Security](#security)
1718
- [License](#license)
@@ -85,8 +86,33 @@ client = OpenAI(
8586
)
8687
```
8788

89+
## Using Partner APIs (passthrough)
90+
91+
OCI also offers Partner API which passes through your calls to partners such as OpenAI. We will support more partners in the future.
92+
93+
You can leverage Partner API when you want to use OpenAI's API and GPT models, but with OCI auth and billing.
94+
95+
Note: Currently Partner API is only available to Oracle internal teams. Only features that meet partner's Zero Data Retention are available through Partner API.
96+
97+
If you want multi-provider model access and features unavailable under partner's Zero Data Retention (such as File Search), use the OCI Enterprise AI Agents APIs above.
98+
99+
```python
100+
import httpx
101+
from openai import OpenAI
102+
from oci_genai_auth import OciSessionAuth
103+
104+
client = OpenAI(
105+
base_url="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/v1",
106+
api_key="not-used",
107+
default_headers={
108+
"opc-compartment-id": "ocid1.compartment.oc1..aaaaaaaaexample",
109+
},
110+
http_client=httpx.Client(auth=OciSessionAuth(profile_name="DEFAULT")),
111+
)
112+
```
113+
88114
## Examples
89-
Demo code and instructions on how to run them can be found in the ```examples``` folder.
115+
Demo code and instructions on how to run them, for both OCI Enterprise AI Agents and partner usecases can be found in ```examples``` folder.
90116

91117
## Contributing
92118

examples/partner/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Partner Examples
2+
3+
This folder contains partner API examples using the OpenAI Python SDK.
4+
5+
## Prerequisites
6+
7+
1. Install dependencies:
8+
9+
```bash
10+
pip install -e '.[dev]'
11+
```
12+
13+
2. Configure shared values in `examples/partner/common.py`:
14+
- `PROFILE_NAME`
15+
- `COMPARTMENT_ID`
16+
- `REGION`
17+
18+
## How to run
19+
20+
From repository root:
21+
22+
```bash
23+
python -m examples.partner.openai.quickstart_openai_chat_completions
24+
```
25+
26+
## Notes
27+
28+
- Partner endpoints use pass-through mode and require the `opc-compartment-id` header.
29+
- These examples use IAM signing through `oci-genai-auth`.

examples/partner/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (c) 2026 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

examples/partner/common.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2026 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
"""Partner example clients and configuration."""
5+
6+
from __future__ import annotations
7+
8+
import httpx
9+
from openai import AsyncOpenAI, OpenAI
10+
11+
from oci_genai_auth import OciSessionAuth
12+
13+
PROFILE_NAME = "DEFAULT"
14+
COMPARTMENT_ID = "<<ENTER_COMPARTMENT_ID>>"
15+
REGION = "us-chicago-1"
16+
17+
PARTNER_OPENAI_BASE_URL = f"https://inference.generativeai.{REGION}.oci.oraclecloud.com/20231130/actions/v1"
18+
19+
20+
def build_openai_client() -> OpenAI:
21+
client_kwargs = {
22+
"api_key": "not-used",
23+
"base_url": PARTNER_OPENAI_BASE_URL,
24+
"http_client": httpx.Client(auth=OciSessionAuth(profile_name=PROFILE_NAME)),
25+
}
26+
if COMPARTMENT_ID:
27+
client_kwargs["default_headers"] = {"opc-compartment-id": COMPARTMENT_ID}
28+
return OpenAI(**client_kwargs)
29+
30+
31+
def build_openai_async_client() -> AsyncOpenAI:
32+
client_kwargs = {
33+
"api_key": "not-used",
34+
"base_url": PARTNER_OPENAI_BASE_URL,
35+
"http_client": httpx.AsyncClient(auth=OciSessionAuth(profile_name=PROFILE_NAME)),
36+
}
37+
if COMPARTMENT_ID:
38+
client_kwargs["default_headers"] = {"opc-compartment-id": COMPARTMENT_ID}
39+
return AsyncOpenAI(**client_kwargs)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (c) 2026 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2026 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
"""Demonstrates a basic chat completion request for the Partner endpoint."""
5+
6+
from rich import print
7+
8+
from examples.partner import common
9+
10+
MODEL = "openai.gpt-5.2"
11+
12+
13+
def main():
14+
openai_client = common.build_openai_client()
15+
16+
completion = openai_client.chat.completions.create(
17+
model=MODEL,
18+
messages=[
19+
{"role": "system", "content": "You are a concise assistant."},
20+
{"role": "user", "content": "List three creative uses for a paperclip."},
21+
],
22+
max_tokens=128,
23+
)
24+
25+
print(completion.model_dump_json(indent=2))
26+
27+
28+
if __name__ == "__main__":
29+
main()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2026 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
"""Demonstrates the Basic chat completion api key example."""
5+
6+
import os
7+
8+
from openai import OpenAI
9+
10+
MODEL = "openai.gpt-5.2"
11+
12+
13+
def main() -> None:
14+
client = OpenAI(
15+
api_key=os.getenv("OPENAI_API_KEY"),
16+
base_url="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/openai/v1",
17+
)
18+
19+
response = client.chat.completions.create(
20+
model=MODEL,
21+
messages=[
22+
{
23+
"role": "system",
24+
"content": "You are a concise assistant who answers in one paragraph.",
25+
},
26+
{
27+
"role": "user",
28+
"content": "Explain why the sky is blue as if you were a physics teacher.",
29+
},
30+
],
31+
)
32+
33+
print(response.choices[0].message.content)
34+
35+
36+
if __name__ == "__main__":
37+
main()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2026 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
"""Demonstrates a simple openai chat completions example."""
5+
6+
import logging
7+
8+
from examples.partner import common
9+
10+
logging.basicConfig(level=logging.DEBUG)
11+
12+
MODEL="openai.gpt-5.2"
13+
14+
def main():
15+
client = common.build_openai_client()
16+
17+
completion = client.chat.completions.create(
18+
model=MODEL,
19+
messages=[
20+
{
21+
"role": "user",
22+
"content": "How do I output all files in a directory using Python?",
23+
},
24+
],
25+
)
26+
print(completion.model_dump_json())
27+
28+
# Process the stream
29+
print("=" * 80)
30+
print("Process in streaming mode")
31+
streaming = client.chat.completions.create(
32+
model=MODEL,
33+
messages=[
34+
{
35+
"role": "user",
36+
"content": "How do I output all files in a directory using Python?",
37+
},
38+
],
39+
stream=True,
40+
)
41+
for chunk in streaming:
42+
print(chunk)
43+
44+
45+
if __name__ == "__main__":
46+
main()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2026 Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
"""Demonstrates streaming chat completion responses for the Partner (pass-through) endpoint."""
5+
6+
from examples.partner import common
7+
8+
MODEL = "openai.gpt-5.2"
9+
10+
11+
def main():
12+
openai_client = common.build_openai_client()
13+
14+
stream = openai_client.chat.completions.create(
15+
model=MODEL,
16+
messages=[
17+
{
18+
"role": "system",
19+
"content": "You are a concise assistant who answers in one paragraph.",
20+
},
21+
{
22+
"role": "user",
23+
"content": "Explain why the sky is blue as if you were a physics teacher.",
24+
},
25+
],
26+
stream=True,
27+
)
28+
29+
for chunk in stream:
30+
for choice in chunk.choices:
31+
delta = choice.delta
32+
if delta.content:
33+
print(delta.content, end="", flush=True)
34+
print()
35+
36+
37+
if __name__ == "__main__":
38+
main()

0 commit comments

Comments
 (0)