{"record":{"id":"633d393df9030313","repo":"langgenius/dify","slug":"not-chat-app","errorCode":"not_chat_app","errorMessage":"App mode is invalid.","messagePattern":"App mode is invalid\\.","errorType":"console","errorClass":"NotChatAppError","httpStatus":400,"severity":"error","filePath":"api/controllers/console/explore/completion.py","lineNumber":189,"sourceCode":"\n\n@console_ns.route(\n    \"/installed-apps/<uuid:installed_app_id>/chat-messages\",\n    endpoint=\"installed_app_chat_completion\",\n)\nclass ChatApi(InstalledAppResource):\n    @console_ns.expect(console_ns.models[ChatMessagePayload.__name__])\n    @console_ns.response(200, \"Success\")\n    @with_current_user\n    @with_session\n    @model_validate(ChatMessagePayload)\n    def post(self, req_data: ChatMessagePayload, session: Session, current_user: Account, installed_app: InstalledApp):\n        app_model = installed_app.app_with_session(session=session)\n        if app_model is None:\n            raise AppUnavailableError()\n        app_mode = AppMode.value_of(app_model.mode)\n        if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:\n            raise NotChatAppError()\n\n        args = req_data.model_dump(exclude_none=True)\n\n        args[\"auto_generate_name\"] = False\n\n        installed_app.last_used_at = naive_utc_now()\n        db.session.commit()\n\n        try:\n            # Eagerly validate conversation to avoid hanging on invalid conversation_id\n            if req_data.conversation_id:\n                ConversationService.get_conversation(\n                    app_model=app_model,\n                    conversation_id=req_data.conversation_id,\n                    user=current_user,\n                    session=session,\n                )\n","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/explore/completion.py#L171-L207","documentation":"Raised by ChatApi.post when AppMode.value_of(app_model.mode) is not in {CHAT, AGENT_CHAT, ADVANCED_CHAT}. The chat-messages endpoint only serves chat-family apps; completion, workflow, and generator apps must use their own endpoints. Returns HTTP 400 with error_code 'not_chat_app' with description 'App mode is invalid.'","triggerScenarios":"POST /console/installed-apps/<id>/chat-messages against an installed app whose mode is COMPLETION, WORKFLOW, or GENERATOR. Happens when the client routes a non-chat installed app to the chat endpoint.","commonSituations":"Frontend assumes every installed app is a chat app; user installed a completion-template app but the UI sends to chat-messages; app mode was changed in Studio after the client cached the type.","solutions":["Use /console/installed-apps/<id>/completion-messages for completion (text-generation) apps.","Inspect the installed app's mode and branch the endpoint before calling.","Confirm the app's intended mode in Studio.","If you need a chat experience, install a chat-template app instead."],"exampleFix":"// before: always uses chat-messages\nconst url = `/installed-apps/${id}/chat-messages`\n\n// after: route by mode\nconst url = ['chat','agent-chat','advanced-chat'].includes(appMode)\n  ? `/installed-apps/${id}/chat-messages`\n  : `/installed-apps/${id}/completion-messages`","handlingStrategy":"validation","validationCode":"// Route by app mode before posting to chat-messages.\nfunction isChatMode(mode) {\n  return ['chat','agent-chat','advanced-chat'].includes(mode);\n}\nif (!isChatMode(installedApp.app_mode)) { redirectToCompletionEndpoint(installedApp); }","typeGuard":"function isChatApp(entry) {\n  return ['chat','agent-chat','advanced-chat'].includes(entry?.app_mode);\n}","tryCatchPattern":"try {\n  await postChat(id, payload);\n} catch (err) {\n  if (err.code === 'not_chat_app') {\n    await postCompletion(id, payload);\n  } else { throw err; }\n}","preventionTips":["Use a single routing helper that maps app_mode to the correct endpoint for both send and stop.","Re-read app_mode after the user switches installed apps.","Default new clients to inspecting mode rather than assuming chat."],"tags":["explore","app-mode","chat","routing"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}