[Python] OCI Generative AI Agent API returns "Unknown resource" 404 error when invoked from...

Discussão em 'Python' iniciado por Stack, Junho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with Oracle Cloud Infrastructure and trying to invoke a Generative AI Agent from an Oracle Function using the Python SDK. Everything seems correctly set up, but I'm getting a 404 Unknown resource error when I call the /actions/chat endpoint. I want to call the agent from oracle Apex, so it can use the SQL tool for searching in the DB.

    Here’s the response I get:

    { "status": "success",
    "ai_response": "Error calling AI agent: {
    'target_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' }" }


    This is my python 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 calling AI agent: {str(e)}"


    Created the Generative AI agent and agent endpoint in the correct region (eu-frankfurt-1) and verified their OCIDs.

    Configured a Dynamic Group for the Oracle Function and assigned IAM policies granting it access to generative-ai-family in the appropriate compartment.

    The Function uses resource principal authentication and signs the request correctly (no auth error).

    I made sure the OCIDs (for both agent and agent endpoint) are copied directly and match what’s shown in the Console.

    The compartment OCID is correct and the agent is active.

    I’m using OCI CLI version 3.54.5, but oci gen-ai commands are missing, and I believe the Cloud Shell version doesn't have the plugin installed.

    The call is made from inside an Oracle Function using the Python SDK.

    Continue reading...

Compartilhe esta Página