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

I’m trying to integrate an Oracle Cloud AI Agent with my Oracle Function using Python SDK, but I keep getting a 404 error saying the resource is unknown. My goal is to connect this to Oracle Apex so it can query the database using SQL tools.

The error response looks like this:

{
  "status": "error",
  "response": "AI agent call failed: {
    'service': 'generative_ai_agent_runtime',
    'status': 404,
    'code': '404',
    'request-id': '3175158ED25353360BFCC3E88F2679CD/09596E03EC04969FE05E5A79576352BC/A30E4A49BC2CC5F7B9D17F5EBF5E5206',
    'message': 'Unknown resource 3ce33fc6-ec55-5ge8-c280-ef834bb513bb',
    'operation': 'chat',
    'timestamp': '2025-06-11T10:42:18.342108+00:00',
    'sdk_version': 'Oracle-PythonSDK/2.154.1',
    'endpoint': 'POST https://agent-runtime.generativeai.eu-frankfurt-1.oci.oraclecloud.com/20240531/agentEndpoints/ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqaa4ezfogmwva8nrjyxfulahgsznx8hdmco4fwqrjg3amor/actions/chat'
  }
}

Here’s my Python implementation:

import json
import oci
import uuid
from oci.config import from_file

def invoke_ai_agent(message):
    try:
        # Initialize with Resource Principal authentication
        auth_signer = oci.auth.signers.get_resource_principals_signer()

        ai_agent_client = oci.generative_ai_agent_runtime.GenerativeAiAgentRuntimeClient(
            config={}, signer=auth_signer
        )

        conversation_id = str(uuid.uuid4())

        response = ai_agent_client.chat(
            agent_endpoint_id="ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqaa4ezfogmwva8nrjyxfulahgsznx8hdmco4fwqrjg3amor",
            chat_details=oci.generative_ai_agent_runtime.models.ChatDetails(
                user_message=message,
                session_id=conversation_id
            )
        )

        return response.data

    except Exception as error:
        return f"AI agent invocation failed: {str(error)}"

I’ve already set up the AI agent and endpoint in eu-frankfurt-1 region and double checked the OCIDs. The Dynamic Group has proper IAM policies for generative-ai-family access in the right compartment. Authentication works fine with resource principals. Both agent and endpoint are active and the compartment OCID is verified. The function runs in Oracle Cloud and uses the Python SDK correctly.

Had this exact issue last month. Your agent endpoint config is probably the problem, not your code. The endpoint shows ACTIVE but check if it’s actually linked to the agent - sometimes it gets created but loses connection during deployment. Recreate the endpoint and make sure you pick the right agent during setup. Also verify your agent has SQL tools configured properly. If the agent config is incomplete, the endpoint exists but throws 404 when you call it. Your auth and region setup looks fine based on that error response.

that unknown resource error usually means your agent endpoint isn’t deployed or you’ve got a region mismatch. i kno you said you checked, but double-check the endpoint shows as ACTIVE in the console - not just created. also try explicitly setting the region in your client config to be safe.