Receiving a 404 error for unknown resource when attempting to access OCI AI Agent via Oracle Function

I need assistance with an issue in Oracle Cloud Infrastructure. I’m trying to access a Generative AI Agent from an Oracle Function, but I keep encountering a 404 error indicating that the resource cannot be found.

My goal is to link this functionality to Oracle Apex so it can perform SQL searches on my database. However, I must first get the agent call to work correctly.

Here is the error message that I receive:

{
  "status": "error",
  "response": "Unable to reach AI service: {
    'service_name': 'generative_ai_agent_runtime',
    'http_status': 404,
    'error_code': '404',
    'request_id': '123456789ABCDEF/ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ/99999999999999999999999999999',
    'error_message': 'Resource not found example-1234-abcd',
    'api_call': 'send_message',
    'created_at': '2025-06-11T10:42:48.342108+00:00',
    'sdk_version': 'Oracle-PythonSDK/2.154.1',
    'api_url': 'POST https://agent-runtime.generativeai.eu-frankfurt-1.oci.oraclecloud.com/20240531/agentEndpoints/example-endpoint-id/actions/chat'
  }
}

The Python code I’m using is as follows:

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

def call_ai_service(input_message):
    try:
        # Configuring resource principal authentication
        signer = get_resource_principals_signer()

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

        session_uuid = str(uuid.uuid4())

        result = ai_agent_client.chat(
            agent_endpoint_id="example-endpoint-id",
            chat_details=oci.generative_ai_agent_runtime.models.ChatDetails(
                user_message=input_message,
                session_id=session_uuid
            )
        )

        return result.data

    except Exception as e:
        return f"Unable to reach AI service: {str(e)}"

I’ve confirmed that the agent endpoint is available in the correct region and I verified the OCID is accurate. Additionally, my IAM policies appear to be set correctly, and the function has the necessary permissions for accessing generative AI services. Since there are no authentication errors, the setup seems valid.

Does anyone have insights on what might be causing this issue?

That 404 error is super common with OCI’s AI Agent setup. I’ve hit this wall before.

Your endpoint ID “example-1234-abcd” looks like a placeholder. Double-check you’re using the real agent endpoint OCID from your console.

Try adding the region explicitly:

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

Honestly though? OCI’s API quirks and Oracle Functions make this way harder than it should be. You’re connecting AI agents to Oracle Apex for SQL searches - I’ve done similar stuff with Latenode and it’s so much cleaner.

No wrestling with resource principals or SDK versions. Just drag-and-drop your workflow from AI processing to database queries. Takes minutes instead of hours debugging.

The visual builder handles errors and retries automatically too, which you’ll need for production.

Check it out: https://latenode.com

I had this exact same issue with OCI AI Agents. Turns out my agent endpoint wasn’t actually running - it showed as available in the console but wasn’t in a running state to accept API calls. First, check your agent endpoint’s lifecycle state in the OCI console under AI Services. If it’s showing inactive or creating, start it first. Also double-check you’re using the chat method right - the OCI docs have some inconsistent examples with different method signatures. Try adding explicit region config to your client initialization too, even if the region looks correct from the endpoint URL. The SDK sometimes doesn’t pick up the region properly from resource principals.

Been there multiple times with Oracle Functions and AI agents. Usually it’s the agent endpoint not being deployed properly or missing API access.

Here’s what worked for me:

Check your AI Agent console deployment tab first. Your agent might be created but not actually deployed to that endpoint. Deploy it explicitly.

Your chat method call is missing required parameters. Try this:

result = ai_agent_client.chat(
    agent_endpoint_id="your-actual-endpoint-id",
    chat_details=oci.generative_ai_agent_runtime.models.ChatDetails(
        user_message=input_message,
        session_id=session_uuid,
        should_stream=False
    )
)

Make sure your function’s dynamic group has this specific policy:

allow dynamic-group your-fn-dynamic-group to use generative-ai-agent-endpoint in compartment your-compartment

General AI permissions aren’t enough - the agent endpoint needs its own access.

Still getting 404s? Try calling the endpoint directly with curl first. Oracle Function environments sometimes have weird networking issues that don’t show up in error messages.

That region mismatch thing is real too. Frankfurt doesn’t have full AI agent support yet from what I’ve seen.

Check if your agent endpoint OCID has the compartment info included. I hit the same 404 errors when my endpoint wasn’t fully qualified with compartment details. Also verify you’re using the right service endpoint URL - the generative AI agent runtime isn’t available in all regions yet, even if regular generative AI is. Try switching to us-ashburn-1 temporarily to test it out. You might also have a version mismatch between your Python SDK and the API version you’re calling. That 20240531 API version in your URL means you need a recent SDK version. Finally, make sure your Oracle Function’s resource principal has the specific generative-ai-agent-endpoint permissions, not just general AI service permissions.