languagetool-org/languagetool · error · BadRequestException

You specified 'autodetect' but automatic language detection

Error message

You specified 'autodetect' but automatic language detection is now activated with 'language=auto' in v2 of the API

What it means

In v2, automatic language detection is activated with language=auto; the v1 boolean 'autodetect' parameter was removed. V2TextChecker.checkParams() rejects 'autodetect' to force migration to the new mechanism.

Source

Thrown at languagetool-server/src/main/java/org/languagetool/server/V2TextChecker.java:110

  }

  @Override
  protected void checkParams(Map<String, String> parameters) {
    super.checkParams(parameters);
    if (StringTools.isEmpty(parameters.get("language"))) {
      throw new BadRequestException("Missing 'language' parameter, e.g. 'language=en-US' for American English or 'language=fr' for French");
    }
    if (parameters.get("enabled") != null) {
      throw new BadRequestException("You specified 'enabled' but the parameter is now called 'enabledRules' in v2 of the API");
    }
    if (parameters.get("disabled") != null) {
      throw new BadRequestException("You specified 'disabled' but the parameter is now called 'disabledRules' in v2 of the API");
    }
    if (parameters.get("preferredvariants") != null) {
      throw new BadRequestException("You specified 'preferredvariants' but the parameter is now called 'preferredVariants' (uppercase 'V') in v2 of the API");
    }
    if (parameters.get("autodetect") != null) {
      throw new BadRequestException("You specified 'autodetect' but automatic language detection is now activated with 'language=auto' in v2 of the API");
    }
  }
  
  @Override
  @NotNull
  protected DetectedLanguage getLanguage(String text, Map<String, String> parameters, List<String> preferredVariants,
                                         List<String> noopLangs, List<String> preferredLangs, boolean testMode) {
    String langParam = parameters.get("language");
    boolean forcePreferredLanguages = "true".equals(parameters.get("forcePreferredLanguages"));
    DetectedLanguage detectedLang = detectLanguageOfString(text, null, preferredVariants, noopLangs, preferredLangs, forcePreferredLanguages);
    Language givenLang;
    if (getLanguageAutoDetect(parameters)) {
      givenLang = detectedLang.getDetectedLanguage();
    } else {
      givenLang = parseLanguage(langParam);
    }
    return new DetectedLanguage(givenLang, detectedLang.getDetectedLanguage(), detectedLang.getDetectionConfidence(),
      detectedLang.getDetectionSource());

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Remove autodetect and set language=auto instead
  2. If a concrete language is known, set language to its code and drop autodetection
  3. Update wrapper libraries/SDKs to v2 parameter names
  4. Combine language=auto with preferredVariants to bias detection if needed

Example fix

// before
params.put("autodetect", "true");
// after
params.put("language", "auto");
Defensive patterns

Strategy: validation

Validate before calling

if ('autodetect' in params) { delete params.autodetect; params.language = 'auto'; }

Try / catch

try { await check(params); } catch (e) { if (/language=auto/.test(e.message)) { /* replace autodetect with language=auto */ } throw e; }

Prevention

When it happens

Trigger: Calling /v2/check with autodetect=true (or any value) — HTTP 400 immediately, regardless of other parameters.

Common situations: v1-to-v2 migration; request builders shared between API versions; old client libraries predating v2.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/f49c04b09dc78dbd. Report an issue: GitHub.