OCI Responses API
Use the OCI Responses API to call supported models, generate model outputs, and build tool-based or multi-step workflows through a single OpenAI-compatible, Open Responses-compliant API. It supports text and image inputs and text outputs. You can use it to build stateful interactions with conversation history, add supported tools such as File Search and Code Interpreter, and connect the model to external systems through Function Calling and MCP Calling.
How The Responses API Fits Into Agent Building
Use the Responses API together with the following agent-building components in OCI Generative AI:
| Component | Purpose |
|---|---|
| Responses API | The primary OpenAI-compatible API for interacting with supported models and agentic workflows. |
| Agent Tools | Tools for the Responses API, including File Search, Code Interpreter, Function Calling, and MCP Calling. |
| Agent Memory | Memory for the Conversations API, including long-term memory access, and short-term memory context compaction. |
| Foundational Agent Building Blocks | OpenAI-compatible foundational API such as Files, Vector Stores, and Containers API that you can use with the Responses API for direct control over resources. |
If needed, you can use the low-level foundational building blocks with the Responses API.
What You Can Do With The Responses API
Use the Responses API to:
- Call supported hosted models and imported models.
- Send text and image inputs and receive text outputs.
- Generate text or structured outputs.
- Run single-step prompts or multi-step workflows.
- Add supported tools in the request.
- Run longer requests in the background and retrieve their status later.
- Stream responses back to the client.
- Use OCI-managed conversation state through the Conversations API.
- Reuse conversation history or previous outputs as context for later requests.
- Connect the model to external systems and data through Function Calling and MCP Calling.
- Combine model requests with files, vector stores, or containers when needed.
This lets you start with a simple prompt and expand to more advanced workflows without switching to a different API.
When to Use The Responses API
For most new applications, start with the Responses API.
Use it when you want to:
- Use one API for model interaction and agentic capabilities.
- Add supported tools to a model request.
- Use OCI-managed conversation history.
- Generate structured outputs.
- Run requests without keeping the original connection open until generation finishes.
- Build workflows that can also use files, vector stores, or containers when needed.
Supported API Endpoint
| Base URL | Endpoint Path | Authentication |
|---|---|---|
https://inference.generativeai.${region}.oci.oraclecloud.com/openai/v1 |
/responses |
API key or IAM session |
Replace ${region} with a supported 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.
The OCI Responses API uses the same format as the OpenAI Responses API with the OCI OpenAI-compatible endpoint. For syntax and request details, see the OpenAI Responses API documentation. If you use tools, ensure that you use only the tool types supported by the OCI OpenAI-compatible endpoint.
Authentication
You can access OCI OpenAI-compatible endpoints in two ways:
Use API keys for testing and early development. Use IAM-based authentication for production workloads and OCI-managed environments.
Before You Begin
Before calling the Responses API:
- Create an OCI Generative AI project. OCI OpenAI-compatible API calls require a project.
- Set up the client with the OCI OpenAI-compatible base URL.
- Set up authentication.
- Use a supported model in a supported region.
For setup steps, see QuickStart, Authentication, and Supported Models and Regions.
To call the Responses API from code, we recommend using the OpenAI SDK. See the QuickStart.
Create Your First Response
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="<your-api-key>", # replace with your Generative AI API Key
project="ocid1.generativeaiproject.oc1.us-chicago-1.xxxxxxxx",
)
response = client.responses.create(
model="<supported-model-id>",
input="Write a one-sentence explanation of what a database is."
)
print(response.output_text)
In this example:
base_urlpoints to the OCI OpenAI-compatible endpoint.client.responses.create(...)calls the OCI Responses API.projectidentifies the OCI Generative AI project for the request.
Run a Response in the Background
Use background mode when a response might take longer than you want to keep an HTTP connection open. OCI Generative AI accepts the request, continues processing it after the initial call returns, and lets your application retrieve the response until it reaches a final status. Background mode changes how your application waits for the result; it doesn't reduce model processing time.
Set background to true when you create the
response. Save the returned response ID because you need it to retrieve or
cancel the request.
| Method | Endpoint Path | Purpose |
|---|---|---|
POST |
/responses |
Create a response with background=true. |
GET |
/responses/{response_id} |
Retrieve the current status and, after completion, the output. |
POST |
/responses/{response_id}/cancel |
Cancel a background response that hasn't reached a final status. |
GET |
/responses/{response_id}?stream=true&starting_after={sequence_number} |
Resume a background stream after the last event that the client received. |
Create a Background Response
The following example starts a request and stores its response ID:
response = client.responses.create(
model="<supported-model-id>",
input="Analyze this incident timeline and propose a prioritized remediation plan.",
background=True,
)
response_id = response.id
print(f"Response ID: {response_id}")
print(f"Initial status: {response.status}")The initial status is typically queued or
in_progress. The request continues running independently
of the initial connection.
Retrieve the Status and Result
Retrieve the response periodically while its status is
queued or in_progress. Any other status
indicates that processing has ended.
from time import sleep
while response.status in {"queued", "in_progress"}:
sleep(5)
response = client.responses.retrieve(response_id)
print(f"Current status: {response.status}")
if response.status == "completed":
print(response.output_text)
else:
print(f"Response ended with status: {response.status}")For production applications, choose a polling interval that avoids unnecessary requests and handle non-completion statuses before attempting to use the output.
Cancel a Background Response
To stop a response that is still running, pass its ID to the cancel operation:
response = client.responses.cancel(response_id)
print(f"Status: {response.status}")Repeating the cancel operation for the same response doesn't change its final result. The service returns the response in its current final state.
Stream a Background Response
You can receive streaming events while retaining the ability to reconnect
if the stream is interrupted. Set both background and
stream to true when you create the
response. Record the sequence_number from the most recent
event. To reconnect, retrieve the response as a stream and pass that value
in starting_after.
You can resume streaming only if the background response was originally
created with stream=true.
Response Storage
Background execution requires temporary response storage so that the
service can continue processing the request and return its status and
result. This temporary storage is required even when the request sets
store to false. Response data remains
within OCI.
For the compatible request format and additional background-mode details, see Background mode in the OpenAI API documentation.
Use Agent Memory with Responses API
To let OCI manage multi-turn conversation history, first create a conversation:
conversation = client.conversations.create()
Then include the conversation ID in the Responses API request:
response = client.responses.create(
model="<supported-model-id>",
input=[
{
"role": "user",
"content": "Recommend a restaurant based on the food I like."
}
],
conversation=conversation.id,
)
Use this pattern when you want OCI to manage conversation state across requests.
For more information about memory capabilities, see Conversations API, Short-Term Memory, Long-Term Memory, and Short-Term Memory Compaction.
Use Tools with the Responses API
The Responses API supports tool-enabled workflows through the tools property. For many use cases, you can declare the tools in the request and let OCI Generative AI coordinate model execution and tool use.
Tool support is available only through the API.
Supported Tool Types
OCI Generative AI supports the following tool types with the Responses API:
| Tool | tools[].type |
Description |
|---|---|---|
| File Search | "file_search" |
Lets the model search uploaded files and vector store content for retrieval-based responses. |
| Code Interpreter | "code_interpreter" |
Lets the model run code in an OCI-managed sandbox environment. |
| Function Calling | "function" |
Lets the user define local functions and have the application run the functions and return the results to the model. |
| MCP Calling | "mcp" |
Gives the model access to methods exposed by a remote MCP server. |
For setup steps and examples, select the link for each tool in the table.
OpenAI documents other tool types, but OCI Generative AI supports only the tool types listed here for the Responses API. Other OCI capabilities, such as NL2SQL, are documented separately and aren't configured through the Responses API tools field.
Example: MCP Calling
The following example defines an MCP tool in the request:
response = client.responses.create(
model="openai.gpt-oss-120b",
tools=[
{
"type": "mcp",
"server_url": "https://example.com/mcp",
}
],
input="What events are scheduled for 2026-04-02?"
)In this example, the Responses API invokes the model and passes the MCP tool definition as part of the same request. You don't need a separate MCP-specific API.
When to Use Foundational API
You can use the low-level foundational agent building blocks with the Responses API when your workflow needs direct control over files, vector stores, or containers.
Common examples include:
- Uploading files before sending a model request
- Managing vector store contents directly
- Reusing files or resources across multiple requests
- Working with sandbox containers as part of a broader workflow
The following API are commonly used with the Responses API:
| API | Endpoint Path | Typical Use with the Responses API |
|---|---|---|
| Files API | /files |
Upload and manage files that you later reference in a response request. |
| Vector Stores API | /vector_stores/... |
Manage vector store contents used for retrieval workflows such as File Search. |
| Containers API | /containers and /containers/{id}/files |
Manage sandbox resources used in tool-enabled workflows. |
Example: Upload a file first, then use it in the Responses API
First upload a file:
file_response = client.files.create(
file=open("example-document.pdf", "rb"),
purpose="assistants"
)
file_id = file_response.id
Then reference the uploaded file in the Responses API request:
response = client.responses.create(
model="<model-id>",
input=[
{
"role": "user",
"content": [
{ "type": "input_file", "file_id": file_id },
{ "type": "input_text", "text": "List all the cities mentioned in this document." }
]
}
]
)
In this example, the Files API and the Responses API work together in one workflow.
SDKs and Frameworks
You can use the OCI Responses API with the OpenAI SDK. You can also use it with compatible client-side agent frameworks.
The OpenAI SDK supports these languages:
- Python
- Java
- TypeScript
- Go
- .NET
More language support is available through community libraries.
Compatible agent frameworks include:
- OpenAI Agents SDK (recommended)
- OpenAI Codex SDK
- Microsoft Agent Framework
- LangChain
- LangGraph
- CrewAI
- AutoGen
- LlamaIndex
- Pydantic
OCI Responses API and OpenAI Responses API
| Feature | OCI Responses API | OpenAI Responses API |
|---|---|---|
| Model choice | Supports OCI-hosted models and non-OpenAI models | OpenAI models only |
| Model serving infrastructure | OCI shared infrastructure or dedicated AI clusters | OpenAI shared infrastructure |
| Authentication | OCI IAM or API keys | API keys |
| Data retention | Data remains in OCI | Data is stored in OpenAI |
| Private networking | Supports OCI VCN integration and private endpoints | Not available |
| Endpoint model | Regional endpoints | Global endpoint |