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="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(resource:GetLanguagesResource.TranslateText);
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:"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=VoiceSourceMediaContentType.AudioPcm_encoding_s16le_rate_16000,SourceLanguage=VoiceSourceLanguage.En,TargetLanguages=[VoiceTargetLanguage.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.CreateStyleRuleListAsync(name:"SDK Test Rules",language:StyleRuleLanguage.En);// ## List style rule lists// Retrieve all style rule lists:varlists=awaitclient.GetStyleRuleListsAsync(detailed:true);// ## Update configured rules// Configure specific rule categories (7 available: DatesAndTimes,// Formatting, Numbers, Punctuation, SpellingAndGrammar,// StyleAndTone, Vocabulary):varupdated=awaitclient.UpdateStyleRuleConfiguredRulesAsync(styleId:created.StyleId.ToString(),punctuation:newConfiguredRulesPunctuation());// ## Clean upawaitclient.DeleteStyleRuleListAsync(styleId:created.StyleId.ToString());
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.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.CreateCustomInstructionAsync(styleId:styleRule.StyleId.ToString(),label:"Currency formatting",prompt:"Always place the currency symbol before the number (e.g. $100, €50).");// ## Retrieve the instructionvarretrieved=awaitclient.GetCustomInstructionAsync(styleId:styleRule.StyleId.ToString(),instructionId:instruction.Id);// ## Add a source-language-specific instruction// You can optionally restrict an instruction to a specific// source language:vardeInstruction=awaitclient.CreateCustomInstructionAsync(styleId:styleRule.StyleId.ToString(),label:"German compound nouns",prompt:"Keep German compound nouns as a single word in the translation.",sourceLanguage:"de");// ## Clean upawaitclient.DeleteCustomInstructionAsync(styleId:styleRule.StyleId.ToString(),instructionId:deInstruction.Id);awaitclient.DeleteCustomInstructionAsync(styleId:styleRule.StyleId.ToString(),instructionId:instruction.Id);awaitclient.DeleteStyleRuleListAsync(styleId:styleRule.StyleId.ToString());
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");
Ecosystem maintenance
This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.
Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.
Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.