Receiving 404 'Unknown resource' error when invoking OCI Generative AI Agent from Oracle Function

I’m experiencing issues with Oracle Cloud Infrastructure. I’m attempting to invoke a Generative AI Agent through an Oracle Function with the Python SDK, but I keep encountering a 404 error.

The error message indicates ‘Unknown resource’ when I try to access the chat endpoint. My intention is to link this agent to Oracle Apex so that it can use SQL tools for querying the database.

Here’s the error message I am getting:

{
  "status": "success",
  "ai_response": "Error invoking AI agent: {
    'service': 'generative_ai_agent_runtime',
    'status': 404,
    'code': '404',
    'opc-request-id': '4264247FE14242459AEBB2F77E1568BC/08485F02DB93858AE94D4968465241AB/92FE3938AC1BB4E6A8C06F4EAF4F4195',
    'message': 'Unknown resource 2bf22eb5-db44-4fd7-b179-de723aa402aa',
    'operation_name': 'chat',
    'timestamp': '2025-06-11T09:35:37.231897+00:00',
    'client_version': 'Oracle-PythonSDK/2.154.1',
    'request_endpoint': 'POST https://agent-runtime.generativeai.eu-frankfurt-1.oci.oraclecloud.com/20240531/agentEndpoints/ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqaa3dyenfkvuz7mqixqetkzgftymw7gclbn3evpqif2zlnq/actions/chat'
  }"
}

Here is my Python function code:

import io
import os
import json
import oci
import uuid
import logging
from oci.config import from_file

def call_generative_ai(prompt):
    try:
        # Use Resource Principal Signer
        signer = oci.auth.signers.get_resource_principals_signer()

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

        session_id = str(uuid.uuid4())

        chat_response = generative_ai_agent_runtime_client.chat(
            agent_endpoint_id="ocid1.genaiagentendpoint.oc1.eu-frankfurt-1.amaaaaaabumsjqaa3dyenfkvuz7mqixqetkzgftymw7gclbn3evpqif2zlnq",
            chat_details=oci.generative_ai_agent_runtime.models.ChatDetails(
                user_message=prompt,
                session_id=session_id
            )
        )

        return chat_response.data

    except Exception as e:
        return f"Error invoking AI agent: {str(e)}"

I have confirmed that the AI agent and endpoint were created in the correct region (eu-frankfurt-1) and their OCIDs are accurate. I’ve also set up a Dynamic Group for the Oracle Function and granted it IAM policies for access to generative-ai-family. The Function authentication is functioning correctly with resource principals. Despite all this, I still encounter the 404 error. What could be wrong?

Check your Python SDK version - I had this exact error with an older version that didn’t support the agent runtime properly. Also make sure your function has internet access through a NAT or service gateway. Without proper routing, you’ll get 404s even with correct OCIDs and permissions.

I hit the same issue with OCI generative AI agents through functions. Turns out it was API versioning and service availability in my region. Even with a valid endpoint OCID, the generative AI agent runtime service might not be fully rolled out in eu-frankfurt-1 yet.

Try switching regions temporarily to test your code. I had luck with us-ashburn-1 and us-phoenix-1 when eu-frankfurt-1 was acting up. Also make sure you’re running the latest Python SDK version - Oracle’s been pushing frequent updates for generative AI services and older versions throw weird 404 errors.

Check if your resource principal has the right service endpoint configured too. Sometimes the SDK hits the wrong service URL even with proper permissions. You can explicitly set the endpoint URL in your client config to force it to the right place.

I’ve hit this exact problem before - it’s usually an endpoint status issue. The OCID looks valid, but Oracle’s generative AI agents have this weird quirk where they show as created in the console but aren’t actually ready for API calls yet.

Add some debug logging to check the endpoint status first. Query the endpoint details using GenerativeAiAgentClient (not runtime) to see if it’s in ACTIVE state:

from oci.generative_ai_agent import GenerativeAiAgentClient

# Check endpoint status
agent_client = GenerativeAiAgentClient(config={}, signer=signer)
endpoint_response = agent_client.get_agent_endpoint(agent_endpoint_id="your-ocid-here")
print(f"Endpoint status: {endpoint_response.data.lifecycle_state}")

If it’s not ACTIVE, wait it out. These endpoints can take 10-15 minutes to fully provision even after creation.

Also check if your function’s subnet has the right egress rules for generative AI service endpoints. I’ve seen cases where the function authenticates fine but can’t reach the service due to network policies.

sounds like the endpoint might be inactive or not properly provisioned yet. did you check if the genai agent endpoint is actually in ‘active’ state in the console? sometimes these take a while to fully deploy even after creation shows as complete.

That 404 ‘Unknown resource’ error usually means the agent endpoint OCID doesn’t exist or you can’t access it from where you’re calling it. I’ve hit this before - it’s often a compartment mismatch between where the endpoint lives and what your IAM policies cover. Make sure your Dynamic Group policies target the exact compartment with the agent endpoint, not just the root compartment. Also double-check that you’ve got generative-ai-agent-runtime in your policy statements. People often add generative-ai-family permissions but forget the runtime-specific access. Could also be the endpoint got created in a different tenancy or region than you think, even if the OCID looks right.