Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix authorization for OpenAI-compatible agent completions (#19817)

Mahshooq Zubair20180790e1a8
diff --git a/api/apps/restful_apis/agent_api.py b/api/apps/restful_apis/agent_api.py
index b1798010b4..a59264b3fa 100644
--- a/api/apps/restful_apis/agent_api.py
+++ b/api/apps/restful_apis/agent_api.py
@@ -1486,6 +1486,14 @@ async def agent_chat_completion(tenant_id, agent_id=None):
if workflow_session:
workflow_conv = conv.to_dict()
+ if not session_id:
+ if not UserCanvasService.accessible(agent_id, tenant_id):
+ return get_json_result(
+ data=False,
+ message="Make sure you have permission to access the agent.",
+ code=RetCode.OPERATING_ERROR,
+ )
+
if openai_compatible:
# OpenAI-compatible mode uses a different wire format, keep it separate from regular agent events.
messages = req.get("messages", [])
@@ -1582,13 +1590,6 @@ async def agent_chat_completion(tenant_id, agent_id=None):
)
if not session_id:
- if not UserCanvasService.accessible(agent_id, tenant_id):
- return get_json_result(
- data=False,
- message="Make sure you have permission to access the agent.",
- code=RetCode.OPERATING_ERROR,
- )
-
# Load the caller's runtime replica as the workflow template. Session-owned
# history and execution state are reset after Canvas instantiation below.
query = req.get("query", "") or req.get("question", "")