Oracle Cloud Generative AI Agent encounters a 404 error when accessed via serverless function

I’m experiencing an issue with Oracle Cloud while trying to invoke a Generative AI Agent from a serverless function using Python. My intention is to connect this functionality to Oracle APEX, enabling users to search the database via the AI agent.

However, upon making the request, I consistently receive a 404 error indicating that the requested resource is unavailable. Here’s the detailed error message I received:

{
  "status": "failed",
  "error_message": "Resource lookup failed: {
    'service': 'generative_ai_agent_runtime',
    'http_code': 404,
    'error_code': '404',
    'request_id': '5A73B68G25A34267B8F99C4D82E7A59D/19596G13EC04969F05E5D079576352BC/A3GF4049BD2CC5F7B9D17F5FBG5G5206',
    'description': 'Resource not found a4c33fc6-ec55-5ge8-c280-ef834bb513bb',
    'action': 'chat',
    'created_at': '2025-06-11T10:42:51.445123+00:00',
    'sdk_version': 'Oracle-PythonSDK/2.154.1',
    'endpoint_url': 'POST https://agent-runtime.generativeai.eu-frankfurt-1.oci.oraclecloud.com/20240531/agentEndpoints/ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqab4ezfogmvxa8nrjysfumahguzno8hdmco4fwsrjg3amor/actions/chat'
  }
}

Here’s the Python function I’m using:

import json
import oci
import uuid
from oci.auth.signers import get_resource_principals_signer

def invoke_ai_agent(user_input):
    try:
        # Get resource principal authentication
        auth_signer = get_resource_principals_signer()
        
        # Create AI agent client
        ai_client = oci.generative_ai_agent_runtime.GenerativeAiAgentRuntimeClient(
            config={}, 
            signer=auth_signer
        )
        
        # Generate unique session
        conversation_id = str(uuid.uuid4())
        
        # Make chat request
        response = ai_client.chat(
            agent_endpoint_id="ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqab4ezfogmvxa8nrjysfumahguzno8hdmco4fwsrjg3amor",
            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"AI agent invocation failed: {str(error)}"

I have verified that the agent endpoint is correctly configured in the eu-frankfurt-1 region and that the OCID is accurate. The IAM policies permissions are in place for the function’s dynamic group to access generative AI resources. The authentication is working well, as there are no authorization errors raised. The agent is confirmed as active in the console. Is there anything that could be causing this 404 error?

the agent endpoint prob isn’t fully deployed yet, even tho the console shows it’s active. I’ve hit this b4 - had to wait like 15-20 mins after creating it before it actually worked. also check your region settings in the client config, that’s usually where the mismatch happens.

I’ve seen this before - usually happens when the agent endpoint OCID is valid but the actual agent got deleted or deactivated. Even though your endpoint shows active, double-check that the agent resource still exists and is configured right. Also try explicitly setting the service_endpoint parameter in your GenerativeAiAgentRuntimeClient instead of letting it auto-detect the region. The SDK sometimes builds wonky URLs when you’re using resource principals with cross-region resources. I’d test the endpoint directly with OCI CLI first to see if it’s a code problem or the service itself.