I’m having trouble connecting to an Oracle Cloud AI Agent through a serverless function. When I try to make a request to the chat endpoint, I keep getting a 404 error saying the resource is unknown. My goal is to integrate this with Oracle Apex so users can query our database using natural language.
The error message looks like this:
{
"status": "failed",
"error_details": {
"service": "ai_agent_runtime",
"http_code": 404,
"message": "Resource not found: 3cf33fb6-ec55-5ge8-c280-ef834bb513bb",
"request_id": "5375358GF25353560BFCC3F88G2679CD",
"action": "chat",
"sdk_version": "Oracle-PythonSDK/2.155.2",
"endpoint": "POST https://agent-runtime.generativeai.eu-frankfurt-1.oci.oraclecloud.com/20240531/agentEndpoints/ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqaa4ezfogmlwa8nrjyxfulahguzno8hdmco4fwqrjg3amor/actions/chat"
}
}
Here’s my function code:
import json
import oci
import uuid
from oci.auth.signers import get_resource_principals_signer
def invoke_ai_agent(user_input):
try:
# Initialize with resource principal authentication
auth_signer = get_resource_principals_signer()
ai_client = oci.generative_ai_agent_runtime.GenerativeAiAgentRuntimeClient(
config={},
signer=auth_signer
)
conversation_id = str(uuid.uuid4())
response = ai_client.chat(
agent_endpoint_id="ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqaa4ezfogmlwa8nrjyxfulahguzno8hdmco4fwqrjg3amor",
chat_details=oci.generative_ai_agent_runtime.models.ChatDetails(
user_message=user_input,
session_id=conversation_id
)
)
return response.data
except Exception as error:
return f"Failed to connect to AI agent: {str(error)}"
I’ve double checked that the agent endpoint is deployed and active in the Frankfurt region. The IAM policies look correct and the function can authenticate properly. The endpoint ID is copied directly from the console. Anyone know what might be causing this resource not found issue?