{"record":{"id":"6845aaf25cacd42f","repo":"langgenius/dify","slug":"provider-not-initialize-6845aa","errorCode":"provider_not_initialize","errorMessage":"No valid model provider credentials found. Please go to Settings -> Model Provider to complete your provider credentials.","messagePattern":"No valid model provider credentials found\\. Please go to Settings -> Model Provider to complete your provider credentials\\.","errorType":"console","errorClass":"ProviderNotInitializeError","httpStatus":400,"severity":"error","filePath":"api/controllers/console/explore/completion.py","lineNumber":134,"sourceCode":"                session=session,\n                app_model=app_model,\n                user=current_user,\n                args=args,\n                invoke_from=InvokeFrom.EXPLORE,\n                streaming=streaming,\n            )\n\n            # response-contract:ignore compact_generate_response\n            return helper.compact_generate_response(response)\n        except services.errors.conversation.ConversationNotExistsError:\n            raise NotFound(\"Conversation Not Exists.\")\n        except services.errors.conversation.ConversationCompletedError:\n            raise ConversationCompletedError()\n        except services.errors.app_model_config.AppModelConfigBrokenError:\n            logger.exception(\"App model config broken.\")\n            raise AppUnavailableError()\n        except ProviderTokenNotInitError as ex:\n            raise ProviderNotInitializeError(ex.description)\n        except QuotaExceededError:\n            raise ProviderQuotaExceededError()\n        except ModelCurrentlyNotSupportError:\n            raise ProviderModelCurrentlyNotSupportError()\n        except InvokeError as e:\n            raise CompletionRequestError(e.description)\n        except ValueError as e:\n            raise e\n        except Exception:\n            logger.exception(\"internal server error.\")\n            raise InternalServerError()\n\n\n@console_ns.route(\n    \"/installed-apps/<uuid:installed_app_id>/completion-messages/<string:task_id>/stop\",\n    endpoint=\"installed_app_stop_completion\",\n)\nclass CompletionStopApi(InstalledAppResource):","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/explore/completion.py#L116-L152","documentation":"Raised by CompletionApi.post (HTTP 400, error_code 'provider_not_initialize') when core.errors.error.ProviderTokenNotInitError is thrown during generation. The app references a model provider whose API credentials have not been configured (or were cleared) in Settings -> Model Provider. The exception's description is forwarded to the client.","triggerScenarios":"POST /console/installed-apps/<id>/completion-messages where the app's configured model provider has no valid credentials on the tenant. AppGenerateService tries to load the provider credentials and ProviderTokenNotInitError fires before any model call.","commonSituations":"New deployment where no provider keys were added; provider credentials were rotated/expired and removed; the app was installed from a template that uses a provider the tenant never configured; switching from Dify-hosted trial to BYO-key without entering keys.","solutions":["Go to Settings -> Model Provider and add valid API credentials for the provider the app uses.","Identify which provider/model the app needs by opening it in Studio and checking the model node.","If using OpenAI, ensure the key is active and has credit.","After saving credentials, retry the completion request."],"exampleFix":"# before: app uses gpt-4o but no OpenAI key is configured\n# (request fails with provider_not_initialize)\n\n# after: configure the provider, then retry\n# Settings -> Model Provider -> OpenAI -> Add API Key -> Save\n# then re-send the same completion request","handlingStrategy":"validation","validationCode":"// Before posting, confirm the tenant has credentials for the provider the app uses.\nconst providers = await fetch('/console/workspaces/current/model-providers').then(r => r.json());\nconst hasCreds = (providerName) =>\n  providers.data.some(p => p.provider === providerName && p.is_valid);\nif (!hasCreds(appProvider)) { promptConfigureProvider(appProvider); }","typeGuard":"function providerIsConfigured(providerEntry) {\n  return Boolean(providerEntry && providerEntry.is_valid);\n}","tryCatchPattern":"try {\n  await postCompletion(id, payload);\n} catch (err) {\n  if (err.code === 'provider_not_initialize') {\n    // direct user to Settings -> Model Provider; do not blind-retry\n    showProviderSetupUI();\n  } else { throw err; }\n}","preventionTips":["Configure required provider credentials before installing apps that depend on them.","Validate provider credentials after key rotation or expiry.","Surface a pre-flight provider check in onboarding flows for Explore apps."],"tags":["explore","completion","model-provider","credentials","configuration"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}