Oracle Generative AI Agent throws 404 'Unknown resource' error when called from Function

I’m having trouble with Oracle Cloud Infrastructure where I get a 404 error when trying to call a Generative AI Agent from an Oracle Function using Python SDK. The goal is to connect this agent to Oracle APEX so it can run SQL queries against our database.

The error response looks like this:

{
  "status": "success",
  "response": "Failed to reach AI agent: {
    'service': 'generative_ai_agent_runtime',
    'status_code': 404,
    'error_code': '404',
    'request_id': '7819356BA25353670BFCC3E88F2679CD/19596G13EC04969FB05E5079576352BC/03GF4049BD2CC5F7B9D17F5FBG5G5206',
    'error_msg': 'Unknown resource 8ca33fc6-ec55-5ge8-c290-ef834bb513bb',
    'action': 'chat',
    'time': '2025-06-11T10:42:18.345821+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.amaaaaaabumsjqaa4ezfogklva8nrjyxfulmhguznx8hdmco4fwsrjg3amor/actions/chat'
  }
}

Here’s my Python function:

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

def invoke_ai_agent(user_input):
    try:
        # Setup resource principal authentication
        auth_signer = get_resource_principals_signer()
        
        ai_client = oci.generative_ai_agent_runtime.GenerativeAiAgentRuntimeClient(
            config={}, 
            signer=auth_signer
        )
        
        chat_session = str(uuid.uuid4())
        
        response = ai_client.chat(
            agent_endpoint_id="ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqaa4ezfogklva8nrjyxfulmhguznx8hdmco4fwsrjg3amor",
            chat_details=oci.generative_ai_agent_runtime.models.ChatDetails(
                user_message=user_input,
                session_id=chat_session
            )
        )
        
        return response.data
        
    except Exception as error:
        return f"Failed to reach AI agent: {str(error)}"

I’ve double checked that the agent and endpoint are created in eu-frankfurt-1 region and the OCIDs are correct. My Dynamic Group has proper IAM policies for generative-ai-family resources. The function authenticates fine with resource principals but still gets this 404 error. Any ideas what might be wrong?

Had the same issue last month - turned out to be the agent endpoint status. Your OCID looks fine, but the endpoint might not be active or got recreated recently. Check the console to make sure it’s actually deployed and running. Mine got stuck provisioning after I changed the config.

Also check if your function’s subnet has egress rules for the generative AI endpoints. I had to add specific routes in my VCN for the agent-runtime domain.

Another gotcha - SDK version compatibility. Update to the latest Python SDK since Oracle’s been pushing frequent updates for generative AI services.

Your resource principal permissions look standard, but double-check you’ve got the exact compartment OCID where the agent endpoint lives in your policy statements.

That endpoint OCID got truncated or corrupted somewhere. The UUID in your error 8ca33fc6-ec55-5ge8-c290-ef834bb513bb doesn’t match the actual endpoint OCID format.

This usually happens when your SDK client region config doesn’t match where the endpoint actually lives. Even with resource principals, the client might default to a different region internally.

Try setting the region explicitly:

ai_client = oci.generative_ai_agent_runtime.GenerativeAiAgentRuntimeClient(
    config={'region': 'eu-frankfurt-1'},
    signer=auth_signer
)

I’ve seen this exact issue - works fine in testing, fails in production because the runtime environment has different default region settings. Since your resource principal auth works but endpoint lookup fails, it’s definitely a region routing problem, not permissions.

Check your region endpoint first - the SDK sometimes ignores what you specify and uses the default config instead. I got the same 404s because mine was hitting us-ashburn when I needed eu-frankfurt. Try recreating the agent endpoint ID too, they can get corrupted during updates. Also make sure your function timeout is long enough since gen AI calls take forever.

That 404 with the garbled OCID screams deleted or moved endpoint. I’ve hit this exact issue when agents get shuffled between compartments.

Quick check from your function:

from oci.generative_ai_agent import GenerativeAiAgentClient

# List all endpoints in your compartment
agent_client = GenerativeAiAgentClient(config={}, signer=auth_signer)
endpoints = agent_client.list_agent_endpoints(compartment_id="your-compartment-ocid")
print([ep.id for ep in endpoints.data])

Bet your endpoint OCID won’t be there. Happens all the time - someone recreates the agent in console but doesn’t update the function code.

Oh, and Oracle’s been shuffling gen AI stuff between regions. Even if you made it in Frankfurt, check if it got migrated or needs a different endpoint URL.

Your auth’s fine since you’re getting a clean 404, not an auth error. It’s definitely a bad resource reference.