{"record":{"id":"450843135879ae45","repo":"SubtitleEdit/subtitleedit","slug":"baidu-api-credentials-not-configured-please-set-a","errorCode":null,"errorMessage":"Baidu API credentials not configured. Please set App ID and Secret Key.","messagePattern":"Baidu API credentials not configured\\. Please set App ID and Secret Key\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/libuilogic/AutoTranslate/BaiduTranslate.cs","lineNumber":78,"sourceCode":"            }\n        }\n\n        public List<TranslationPair> GetSupportedSourceLanguages()\n        {\n            return ListLanguages();\n        }\n\n        public List<TranslationPair> GetSupportedTargetLanguages()\n        {\n            return ListLanguages();\n        }\n\n        public async Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken)\n        {\n            if (string.IsNullOrEmpty(_appId) || string.IsNullOrEmpty(_secretKey))\n            {\n                Error = \"Baidu API credentials not configured. Please set App ID and Secret Key.\";\n                throw new Exception(Error);\n            }\n\n            // Generate random salt and sign\n            var salt = new Random().Next(100000, 999999).ToString();\n            var sign = CalculateMd5Hash(_appId + text + salt + _secretKey);\n\n            // Build request URL with parameters\n            var fromLang = ConvertLanguageCode(sourceLanguageCode);\n            var toLang = ConvertLanguageCode(targetLanguageCode);\n\n            var url = $\"/api/trans/vip/translate?q={Uri.EscapeDataString(text)}&from={fromLang}&to={toLang}&appid={_appId}&salt={salt}&sign={sign}\";\n\n            var result = await _httpClient.GetAsync(url, cancellationToken);\n            var bytes = await result.Content.ReadAsByteArrayAsync(cancellationToken);\n            var json = Encoding.UTF8.GetString(bytes).Trim();\n\n            if (!result.IsSuccessStatusCode)\n            {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libuilogic/AutoTranslate/BaiduTranslate.cs#L60-L96","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open Auto-Translate settings and set BaiduApiKey to 'YourAppId|YourSecretKey' with a literal pipe.","Verify both halves are non-empty after the split.","Ensure Initialize() was called before Translate().","Obtain valid credentials from the Baidu Translate developer console (fanyi-api.baidu.com)."],"exampleFix":"// before\nConfiguration.Settings.Tools.BaiduApiKey = \"12345\";\n// after\nConfiguration.Settings.Tools.BaiduApiKey = \"12345|mySecretKey\"","handlingStrategy":"validation","validationCode":"// Ensure BaiduApiKey is set as 'appId|secretKey' before translating\nvar key = Configuration.Settings.Tools.BaiduApiKey;\nvar parts = key?.Split('|');\nif (parts == null || parts.Length != 2 || string.IsNullOrWhiteSpace(parts[0]) || string.IsNullOrWhiteSpace(parts[1]))\n{\n    Console.WriteLine(\"Set BaiduApiKey to 'appId|secretKey' before calling Translate.\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = await translator.Translate(text, src, tgt, ct);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"credentials not configured\"))\n{\n    // prompt user to enter credentials in settings\n    logger.Error(ex.Message);\n}","preventionTips":["Store BaiduApiKey in 'appId|secretKey' format with a literal pipe.","Call Initialize() after setting credentials.","Validate the key format in a settings UI before enabling the provider."],"tags":["auto-translate","baidu","credentials","configuration"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}