OCI Conversations API

Use the OCI Conversations API to manage session memory. With the Conversations API, you create a conversation first and then include the conversation ID in the Responses API request. This creates a dedicated conversation object that you can reuse across turns.

Note

The OCI Conversations API uses the same format as the OpenAI Conversations API with the OCI OpenAI-compatible endpoint. For syntax and request details, see the OpenAI Conversations API documentation. For unsupported properties, see the OCI Limitations section for each operation on this page.

Supported API Endpoint

Base URL Endpoint Path Authentication
https://inference.generativeai.${region}.oci.oraclecloud.com/openai/v1 /conversations API key or IAM session

Replace ${region} with a supported OCI region such as us-chicago-1.

Although the request format is OpenAI-compatible, authentication uses OCI credentials, requests are routed through OCI Generative AI inference endpoints, and resources and execution remain in OCI.

Tip

For setup steps before using this API, see QuickStart.

Creating a Conversation

POST /conversations

Reference

Create conversation

Python example:

# create a conversation
conversation = client.conversations.create(
   ...
)
print(conversation.id)
OCI Limitations
None

Retrieving a Conversation

GET /conversations/{conversation_id}

Reference

Retrieve conversation

Python example:

# retrieve a conversation
conversation = client.conversations.retrieve(
    "conversation_id",
)
print(conversation.id)
OCI Limitations
None

Updating a Conversation

POST /conversations/{conversation_id}

Reference

Update conversation

Python example:

# update a conversation
updated_conversation = client.conversations.update(
   ...
)
print(updated_conversation)
OCI Limitations
None

Deleting a Conversation

DELETE /conversations/{conversation_id}

Reference

Delete conversation

Python example:

# delete a conversation
client.conversations.delete(
    "conversation_id"
)
OCI Limitations
None

Create Your First Conversation

The following example uses the OpenAI SDK with the OCI OpenAI-compatible endpoint, an OCI Generative AI API key, and a project OCID:

from openai import OpenAI

client = OpenAI(
    base_url="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/openai/v1",
    api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    project="ocid1.generativeaiproject.oc1.us-chicago-1.xxxxxxxx",
)

# create a conversation
conversation = client.conversations.create(
    metadata={"topic": "offsite"}
)
print("Conversation ID:", conversation.id)

# first question
response1 = client.responses.create(
    model="openai.gpt-oss-120b",
    input="Give me three ideas for a team offsite.",
    conversation=conversation.id,
)
print("Response 1:", response1.output_text)

# second question
response2 = client.responses.create(
    model="openai.gpt-oss-120b",
    input="Make the second idea more budget friendly.",
    conversation=conversation.id,
)
print("Response 2:", response2.output_text)

In this example:

  • base_url points to the OCI OpenAI-compatible endpoint.
  • client.responses.create(...) calls the OCI Responses API.
  • project identifies an already created OCI Generative AI project for the request.