Updated and supported automatically if there are no breaking changes
All modern .NET features - nullability, trimming, NativeAOT, etc.
Support .Net Framework/.Net Standard 2.0
Usage
123
usingDeepL;usingvarclient=newDeepLClient(apiKey);
Translate Text
Shows how to translate text between languages using the DeepL API.
123456789
usingvarclient=newDeepLClient(apiKey);// Translate text from English to German using the DeepL API.varresponse=awaitclient.TranslateText.TranslateTextAsync(request:newTranslateTextRequest{Text=["Hello, world!"],TargetLang=TargetLanguage.De,});
Rephrase Text
Shows how to use the DeepL Write API to rephrase text.
123456789
usingvarclient=newDeepLClient(apiKey);// Use the DeepL Write API to rephrase text for improved style and clarity.varresponse=awaitclient.RephraseText.RephraseTextAsync(request:newRephraseTextRequest{Text=["The weather is very nice today and I think we should go outside."],TargetLang=TargetLanguageWrite.EnUs,});
Get Usage
Shows how to retrieve account usage information.
1234
usingvarclient=newDeepLClient(apiKey);// Retrieve your DeepL account usage (character count and limits).varresponse=awaitclient.MetaInformation.GetUsageAsync();
List Languages
Shows how to list supported languages.
1234
usingvarclient=newDeepLClient(apiKey);// List all supported source and target languages.varlanguages=awaitclient.MetaInformation.GetLanguagesAsync();
Translate Document
Shows how to translate a document using the upload-poll-download workflow.
usingvarclient=newDeepLClient(apiKey);// DeepL's document translation follows a three-step workflow:// 1. Upload the document and specify the target language// 2. Poll for translation status until complete// 3. Download the translated document// Step 1: Upload a text file for translation.varcontent="Hello, world! This is a test document for translation."u8.ToArray();varuploadResponse=awaitclient.TranslateDocuments.TranslateDocumentAsync(targetLang:TargetLanguage.De,file:content,filename:"test.txt");// Step 2: Poll until the document translation is complete.GetDocumentStatusResponsestatus;do{awaitTask.Delay(1000);status=awaitclient.TranslateDocuments.GetDocumentStatusAsync(documentId:uploadResponse.DocumentId!,documentKey1:uploadResponse.DocumentKey!);}while(status.StatusisGetDocumentStatusResponseStatus.QueuedorGetDocumentStatusResponseStatus.Translating);// Step 3: Download the translated document (one-time download).vartranslatedBytes=awaitclient.TranslateDocuments.DownloadDocumentAsync(documentId:uploadResponse.DocumentId!,documentKey1:uploadResponse.DocumentKey!);vartranslatedText=System.Text.Encoding.UTF8.GetString(translatedBytes);
Voice Streaming
Shows how to initiate a voice streaming session for real-time translation.
1 2 3 4 5 6 7 8 910111213141516
usingvarclient=newDeepLClient(apiKey);// The DeepL Voice API provides real-time speech translation via WebSocket.// Step 1: Call the REST endpoint to get an ephemeral WebSocket URL and token.varresponse=awaitclient.VoiceAPI.GetVoiceStreamingUrlAsync(request:newGetVoiceStreamingUrlRequest{SourceMediaContentType=VoiceMediaContentType.AudioPcm_Encoding_s16le_Rate_16000,SourceLanguage=VoiceSourceLanguage.En,TargetLanguages=["de"],});// Step 2: Connect to the WebSocket URL (`response.StreamingUrl`)// and stream audio bytes for real-time transcription and translation.// This example only verifies the REST setup endpoint;// actual WebSocket streaming requires a separate WebSocket client.
Style Rules
Demonstrates how to create, configure, and manage style rule lists for
consistent translation output.
varclient=newDeepLClient(apiKey);// Style rules let you enforce terminology, formatting, and tone// preferences across translations. They are configured per language.// ## Create a style rule list// Create a new style rule list for English with punctuation rules:varcreated=awaitclient.StyleRules.CreateStyleRuleListAsync(name:"SDK Test Rules",language:StyleRuleLanguage.En);// ## List style rule lists// Retrieve all style rule lists:varlists=awaitclient.StyleRules.GetStyleRuleListsAsync(detailed:true);// ## Update configured rules// Configure specific rule categories (7 available: DatesAndTimes,// Formatting, Numbers, Punctuation, SpellingAndGrammar,// StyleAndTone, Vocabulary):varupdated=awaitclient.StyleRules.UpdateStyleRuleConfiguredRulesAsync(styleId:created.StyleId,punctuation:newConfiguredRulesPunctuation());// ## Clean upawaitclient.StyleRules.DeleteStyleRuleListAsync(styleId:created.StyleId);
Custom Instructions
Shows how to add free-text custom instructions to a style rule list
for fine-grained control over translation output.
varclient=newDeepLClient(apiKey);// Custom instructions let you provide free-text rules that// DeepL applies during translation — for example, enforcing// terminology conventions or formatting preferences.// ## Create a style rule listvarstyleRule=awaitclient.StyleRules.CreateStyleRuleListAsync(name:"Custom Instruction Demo",language:StyleRuleLanguage.En);// ## Add a custom instruction// Each instruction has a label and a prompt describing the rule:varinstruction=awaitclient.StyleRules.CreateCustomInstructionAsync(styleId:styleRule.StyleId,label:"Currency formatting",prompt:"Always place the currency symbol before the number (e.g. $100, €50).");// ## Retrieve the instructionvarretrieved=awaitclient.StyleRules.GetCustomInstructionAsync(styleId:styleRule.StyleId,instructionId:instruction.Id);// ## Add a source-language-specific instruction// You can optionally restrict an instruction to a specific// source language:vardeInstruction=awaitclient.StyleRules.CreateCustomInstructionAsync(styleId:styleRule.StyleId,label:"German compound nouns",prompt:"Keep German compound nouns as a single word in the translation.",sourceLanguage:"de");// ## Clean upawaitclient.StyleRules.DeleteCustomInstructionAsync(styleId:styleRule.StyleId,instructionId:deInstruction.Id);awaitclient.StyleRules.DeleteCustomInstructionAsync(styleId:styleRule.StyleId,instructionId:instruction.Id);awaitclient.StyleRules.DeleteStyleRuleListAsync(styleId:styleRule.StyleId);
Free API Endpoint
Shows how to use the DeepL Free API endpoint instead of the Pro endpoint.
1 2 3 4 5 6 7 8 91011
// DeepL offers two API tiers with different base URLs:// - Pro: https://api.deepl.com (default)// - Free: https://api-free.deepl.com//// To use the Free API, pass the base URL to the constructor.usingvarfreeClient=newDeepLClient(apiKey:"test-key",baseUri:newSystem.Uri("https://api-free.deepl.com"));// The Pro API is the default — no base URL needed.usingvarproClient=newDeepLClient(apiKey:"test-key");