I’m having trouble with Oracle Cloud Infrastructure. I need to call a Generative AI Agent from inside an Oracle Function using Python. My goal is to connect this to Oracle APEX so the agent can run SQL queries against the database.
The problem is that I keep getting a 404 error when trying to hit the chat endpoint. Here’s what the error looks like:
{
"status": "success",
"response": "Failed to reach AI service: {
'service': 'generative_ai_agent_runtime',
'status': 404,
'error_code': '404',
'request_id': '7A91348DE25153670BEFF3C88F2479AD/19596E13EC04969BF05E5A79576352BC/03GH4849BD2CC5F7B9D17F5EBG6G5206',
'error_msg': 'Resource not found 5cf33fc6-ec55-5ge8-c280-ef834bb513bb',
'action': 'chat',
'time': '2025-06-11T10:42:18.442108+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.amaaaaaabumsjqbb4ezfoglewz8nrjyxftlahguznx8hdmco4fwqrjg3amor/actions/chat'
}
}
I’ve double checked everything. The agent and endpoint are created in eu-frankfurt-1 region. The OCIDs are copied straight from the console. I set up Dynamic Groups and IAM policies to give the function access to generative-ai-family resources. The compartment OCID is right and the agent shows as active. Authentication works fine since I’m not getting auth errors.
Anyone know what might be causing this resource not found issue?
Had the same pain with OCI AI Agents and APEX integration last spring. Your error shows the SDK’s hitting the right endpoint but getting back a different resource ID than what you sent. Usually means there’s a mismatch between the agent and endpoint config. Try calling the agent endpoint directly with OCI CLI first - helps you figure out if it’s function-specific or a broader connection issue. Run oci generative-ai-agent-runtime chat --agent-endpoint-id your-ocid --user-message "test" from a machine with proper OCI config. Also check your session_id generation. I switched from uuid4 to a simpler string format and it fixed some weird 404s. OCI AI service is picky about session ID formats even though the docs don’t mention it. One more thing - make sure your function timeout’s long enough. AI agent calls can take 30+ seconds, and if your function times out mid-request, you’ll see these phantom 404 responses.
That resource ID in your error (5cf33fc6-ec55-5ge8-c280-ef834bb513bb) doesn’t match your agent endpoint OCID. Something’s off there.
I hit this same issue last year. OCI was failing on some internal resource mapping.
Create a fresh agent endpoint and use the new OCID. Sometimes endpoints get stuck in a weird state during creation that doesn’t show in the console.
Double-check your IAM policy covers both agents AND endpoints:
allow dynamic-group your-function-group to use generative-ai-agents in compartment your-compartment
allow dynamic-group your-function-group to use generative-ai-agent-endpoints in compartment your-compartment
Lots of people add the agents permission but forget endpoints. The SDK needs both to make chat calls work.
If recreating doesn’t fix it, try calling something simpler first - like getting agent details - to test basic connectivity before hitting the chat endpoint.
I hit this exact issue a few months ago with OCI AI Agents. That 404 usually means the agent endpoint exists but isn’t ready for API calls yet. Even when it shows active in the console, there’s often a delay before you can actually use it. I had to wait 10-15 minutes after it showed active before my API calls worked. Try adding explicit region config to your client setup: ai_client = oci.generative_ai_agent_runtime.GenerativeAiAgentRuntimeClient(config={'region': 'eu-frankfurt-1'}, signer=auth_signer). Sometimes the resource principal signer doesn’t grab the right regional endpoint automatically. Also check if your function’s subnet can actually reach OCI services - I’ve seen network security rules block outbound HTTPS calls to AI endpoints.
The 404 error you are facing often indicates that the agent endpoint is either not correctly deployed or is unreachable. I encountered a similar issue with OCI AI services. First, attempt to connect directly to the agent endpoint through the OCI console or CLI, utilizing the same credentials, as endpoints can appear ‘active’ while still being unavailable. Next, confirm your region configuration. Although you’ve stated everything is set to eu-frankfurt-1, ensure your function explicitly specifies this region when instantiating the client; sometimes the function runtime does not automatically select the appropriate region. Additionally, check that your Dynamic Group allows access for the compartment in which your function is operating, not just where the AI resources are located. The resource principal needs proper permissions from the compartment of the function to access the AI service compartment. Since your OCID seems correct, this is likely a deployment or permissions issue rather than a configuration problem.
check your function’s memory allocation - i’ve seen oci ai agents throw 404s when there isn’t enough memory to initialize the client connection. that endpoint ocid looks really long too, double-check you copied the whole thing without trailing spaces. adding a simple health check call first helped me verify the connection.