SubtitleEdit/subtitleedit · error · Exception

Baidu API credentials not configured. Please set App ID and

Error message

Baidu API credentials not configured. Please set App ID and Secret Key.

What it means

Thrown by BaiduTranslate.Translate when either the App ID (_appId) or Secret Key (_secretKey) is empty at call time. These are parsed from Configuration.Settings.Tools.BaiduApiKey in the format 'appId|secretKey' during Initialize(); if the key is missing or not pipe-separated into two parts, both fields stay empty and Translate refuses to run.

Source

Thrown at src/libuilogic/AutoTranslate/BaiduTranslate.cs:78

            }
        }

        public List<TranslationPair> GetSupportedSourceLanguages()
        {
            return ListLanguages();
        }

        public List<TranslationPair> GetSupportedTargetLanguages()
        {
            return ListLanguages();
        }

        public async Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(_appId) || string.IsNullOrEmpty(_secretKey))
            {
                Error = "Baidu API credentials not configured. Please set App ID and Secret Key.";
                throw new Exception(Error);
            }

            // Generate random salt and sign
            var salt = new Random().Next(100000, 999999).ToString();
            var sign = CalculateMd5Hash(_appId + text + salt + _secretKey);

            // Build request URL with parameters
            var fromLang = ConvertLanguageCode(sourceLanguageCode);
            var toLang = ConvertLanguageCode(targetLanguageCode);

            var url = $"/api/trans/vip/translate?q={Uri.EscapeDataString(text)}&from={fromLang}&to={toLang}&appid={_appId}&salt={salt}&sign={sign}";

            var result = await _httpClient.GetAsync(url, cancellationToken);
            var bytes = await result.Content.ReadAsByteArrayAsync(cancellationToken);
            var json = Encoding.UTF8.GetString(bytes).Trim();

            if (!result.IsSuccessStatusCode)
            {

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Open Auto-Translate settings and set BaiduApiKey to 'YourAppId|YourSecretKey' with a literal pipe.
  2. Verify both halves are non-empty after the split.
  3. Ensure Initialize() was called before Translate().
  4. Obtain valid credentials from the Baidu Translate developer console (fanyi-api.baidu.com).

Example fix

// before
Configuration.Settings.Tools.BaiduApiKey = "12345";
// after
Configuration.Settings.Tools.BaiduApiKey = "12345|mySecretKey"
Defensive patterns

Strategy: validation

Validate before calling

// Ensure BaiduApiKey is set as 'appId|secretKey' before translating
var key = Configuration.Settings.Tools.BaiduApiKey;
var parts = key?.Split('|');
if (parts == null || parts.Length != 2 || string.IsNullOrWhiteSpace(parts[0]) || string.IsNullOrWhiteSpace(parts[1]))
{
    Console.WriteLine("Set BaiduApiKey to 'appId|secretKey' before calling Translate.");
    return;
}

Try / catch

try
{
    var result = await translator.Translate(text, src, tgt, ct);
}
catch (Exception ex) when (ex.Message.Contains("credentials not configured"))
{
    // prompt user to enter credentials in settings
    logger.Error(ex.Message);
}

Prevention

When it happens

Trigger: Calling Translate without having configured BaiduApiKey, or with a BaiduApiKey that has no '|' separator (so it is treated as appId-only and secretKey stays empty), or before calling Initialize(). Also if the settings were reset.

Common situations: User forgot to enter Baidu credentials in the Auto-Translate settings UI; entered only the App ID without the Secret Key; used a different separator (colon, space) instead of '|'; or a fresh install with no configuration.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/450843135879ae45. Report an issue: GitHub.