langgenius/dify · error · CompletionRequestError

completion_request_error

completion_request_error

Error message

Completion request failed.

What it means

HTTP 400 with error_code completion_request_error, raised when generate_more_like_this raises an InvokeError from the model runtime. The provider was reached and credentials are valid, but the actual completion invocation failed.

Source

Thrown at api/controllers/console/explore/message.py:191

                user=current_user,
                message_id=message_id_str,
                invoke_from=InvokeFrom.EXPLORE,
                streaming=streaming,
            )
            # response-contract:ignore compact_generate_response
            return helper.compact_generate_response(response)
        except MessageNotExistsError:
            raise NotFound("Message Not Exists.")
        except MoreLikeThisDisabledError:
            raise AppMoreLikeThisDisabledError()
        except ProviderTokenNotInitError as ex:
            raise ProviderNotInitializeError(ex.description)
        except QuotaExceededError:
            raise ProviderQuotaExceededError()
        except ModelCurrentlyNotSupportError:
            raise ProviderModelCurrentlyNotSupportError()
        except InvokeError as e:
            raise CompletionRequestError(e.description)
        except ValueError as e:
            raise e
        except Exception:
            logger.exception("internal server error.")
            raise InternalServerError()


@console_ns.route(
    "/installed-apps/<uuid:installed_app_id>/messages/<uuid:message_id>/suggested-questions",
    endpoint="installed_app_suggested_question",
)
class MessageSuggestedQuestionApi(InstalledAppResource):
    @console_ns.response(200, "Success", console_ns.models[SuggestedQuestionsResponse.__name__])
    @with_current_user
    def get(self, current_user: Account, installed_app: InstalledApp, message_id: UUID):
        app_model = installed_app.app_with_session(session=db.session())
        if app_model is None:
            raise AppUnavailableError()

View on GitHub (pinned to ef8544b173)

Solutions

  1. Retry once with backoff for transient provider errors.
  2. Reduce input length (trim the source message/context) to fit the model window.
  3. Inspect ex.description (logged server-side) to distinguish content-policy vs. token-limit vs. provider-5xx.
  4. Switch to a fallback model/provider if the primary keeps failing.
  5. Verify the provider's own dashboard shows the request reaching it.

Example fix

# before: single shot, no retry
resp = get(more_like_this_url(id, mid))

# after: bounded retry with backoff, then fallback model
for attempt in range(3):
    try:
        resp = get(more_like_this_url(id, mid)); break
    except CompletionRequestError:
        sleep(2 ** attempt)
else:
    switch_model(); resp = get(more_like_this_url(id, mid))
Defensive patterns

Strategy: retry

Validate before calling

// No purely client-side validation prevents provider invoke failures;
// preflight only checks credentials/quota/model (errors 755-757)
if (!providerConfigured(app, providers)) return; // avoids 755, not 758

Try / catch

for (let attempt = 0; attempt < 3; attempt++) {
  try {
    return await get(moreLikeThisUrl(id, mid));
  } catch (e) {
    if (e.code === 'completion_request_error' && attempt < 2) {
      await sleep(2 ** attempt * 500); // backoff for transient provider errors
      continue;
    }
    if (e.code === 'completion_request_error') {
      await switchToFallbackModel(id);
      return get(moreLikeThisUrl(id, mid));
    }
    throw e;
  }
}

Prevention

When it happens

Trigger: GET more-like-this where the underlying provider invoke() raised InvokeError — network error mid-call, provider 4xx/5xx, malformed request, content-policy rejection, or context-length exceeded. The controller maps InvokeError.description to CompletionRequestError(400).

Common situations: Provider outage or transient error; prompt+context exceeding the model's token limit; content filter rejection; rate limit (provider-side, distinct from hosted quota); model deprecation.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/222c16c382b1c662. Report an issue: GitHub.