Skip to content

Commit d7fe056

Browse files
authored
Fix DeepL API auth to use Authorization header instead of legacy query/body params (#815)
DeepL deprecated passing auth_key as URL query parameter and POST body parameter in November 2025. Migrate to the required Authorization header method (DeepL-Auth-Key) per official API documentation.
1 parent e663dba commit d7fe056

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Translators/DeepLTranslate.ExtProtocol/ExtDeepLTranslateLegitimate.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Common.ExtProtocol;
1+
using Common.ExtProtocol;
22
using Common.ExtProtocol.Utilities;
33
using Newtonsoft.Json;
44
using SimpleJSON;
@@ -53,7 +53,7 @@ static ExtDeepLTranslateLegitimate()
5353
| SecurityProtocolType.Tls12;
5454
}
5555

56-
private string _httpsServicePointTemplateUrl = "https://api.deepl.com/v2/translate?auth_key={0}";
56+
private string _httpsServicePointTemplateUrl = "https://api.deepl.com/v2/translate";
5757

5858
private HttpClient _client;
5959
private HttpClientHandler _handler;
@@ -73,11 +73,11 @@ public void Initialize( string config )
7373
var free = parts[ 1 ];
7474
if(string.Equals(free, "true", StringComparison.OrdinalIgnoreCase))
7575
{
76-
_httpsServicePointTemplateUrl = "https://api-free.deepl.com/v2/translate?auth_key={0}";
76+
_httpsServicePointTemplateUrl = "https://api-free.deepl.com/v2/translate";
7777
}
7878
else
7979
{
80-
_httpsServicePointTemplateUrl = "https://api.deepl.com/v2/translate?auth_key={0}";
80+
_httpsServicePointTemplateUrl = "https://api.deepl.com/v2/translate";
8181
}
8282
}
8383

@@ -114,7 +114,6 @@ public async Task Translate( ITranslationContext context )
114114
List<UntranslatedTextInfo> untranslatedTextInfos = new List<UntranslatedTextInfo>();
115115

116116
var parameters = new List<KeyValuePair<string, string>>();
117-
parameters.Add( new KeyValuePair<string, string>( "auth_key", _apiKey ) );
118117
if( !string.Equals(context.SourceLanguage, "auto", StringComparison.OrdinalIgnoreCase) ) {
119118
parameters.Add( new KeyValuePair<string, string>( "source_lang", FixLanguage( context.SourceLanguage ).ToUpperInvariant() ) );
120119
}
@@ -130,9 +129,10 @@ public async Task Translate( ITranslationContext context )
130129
var form = new FormUrlEncodedContent( parameters );
131130

132131
using var request = new HttpRequestMessage( HttpMethod.Post, _httpsServicePointTemplateUrl );
132+
request.Headers.Add( "Authorization", "DeepL-Auth-Key " + _apiKey );
133+
request.Content = form;
133134

134-
// create request
135-
using var response = await _client.PostAsync( string.Format( _httpsServicePointTemplateUrl, _apiKey ), form );
135+
using var response = await _client.SendAsync( request );
136136
response.ThrowIfBlocked();
137137
response.EnsureSuccessStatusCode();
138138

0 commit comments

Comments
 (0)