404 Resource Not Found Error When Calling OCI AI Agent from Cloud Function

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?

Double-check your agent endpoint OCID - the console sometimes shows outdated info. I hit this same issue because I was using an old endpoint ID that got recreated during deployment. List all your agent endpoints through API/CLI to make sure the actual OCID matches what’s in your code.

Had the same problem recently - turned out to be a regional endpoint mismatch. Your agent’s in Frankfurt, but the actual service endpoint might be different than you think. Set the service endpoint explicitly in your client config instead of using the default regional mapping. Also, make sure your agent endpoint is ACTIVE, not just deployed - there’s a difference between these two states in OCI. Run a quick oci cli command to check the agent endpoint status. Mine was still transitioning even though the console said it was ready. Double-check that your resource principal has compartment-level permissions for the generative AI agent service specifically, not just general AI service permissions.