Using the Deepl plugin in 3rd party Studio applications

Hi,

I'm using the desktop Studio API in a 3rd party application, and I can't make the deepl plugin work. I'm using Studio 2024 with deepl plugin 7.0.9.1 (but also reproducible with 2022 versions as well).

The plugin is installed, we have the API key, it does work in desktop studio UI, segments are translated. 

Using the desktop API (on the same project - so provider options are properly configured), I try to run a pretranslate task on a project like this:

sdlProject.Credentials.AddCredential(new Uri("deepltranslationprovider:///"), APIKEY);

....

var result = sdlProject.RunAutomaticTasks(projectFiles.ToArray(), sdlTaskTemplateIds);

But I keep getting the response:

System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).\r\n at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()\r\n at Sdl.Community.DeepLMTProvider.Client.DeepLTranslationProviderClient.GetSupportedLanguages(String type, String apiKey)

Indeed, if I debug into the code, then I see that the API key is not available. By the time the provider is created, it receives a credential store that is empty:

Code snippet showing the CreateTranslationProvider method with a null credential store and highlighted DeepLTranslationOptions.ApiKey.

Because the credential store (used by the deepl plugin) seems to be created like this (Sdl.ProjectApi.Implementation.Sdl.ProjectApi.Implementation):

Code snippet showing the GetTranslationProviderCredentialStore method returning a null credential store with a count of 0.

which is different from the publicly available credential store of the project.

As you can see on the upper picture, the deepl plugin tries to use the ApiKey of the options object as fallback, but the ApiKey is marked with JsonIgnore, so it cannot be provided through the translation provider state either.

Can you please help how I can solve this? 

thanks!

Tamas



Generated Image Alt-Text
[edited by: RWS Community AI at 6:23 AM (GMT 1) on 29 Jul 2025]
  • Hi  , the problem might be that yr adding credentials directly to the project's credential store, but the DeepL provider needs the API key to be available during provider initialization?

    try this:
    Here's how to properly configure the DeepL provider using the approach from our working project automation code:

    // Create your MemoryResource with DeepL configuration
    var memory = new MemoryResource
    {
        Uri = new Uri("deepltranslationprovider:///"),
        Credential = "YOUR_DEEPL_API_KEY_HERE", // Use the Credential property, not separate username/password
    };
    
    // Then use the AddTranslationProvider method pattern:
    private static void AddTranslationProvider(FileBasedProject project, MemoryResource memory)
    {
        var provider = GetTranslationProviderReference(memory);
        if (provider == null)
        {
            return;
        }
    
        var entry = new TranslationProviderCascadeEntry(provider, false, true, false, 0);
    
        var tpConfig = project.GetTranslationProviderConfiguration();
        
        // Clear existing entries if needed
        tpConfig.Entries.Clear();
        
        tpConfig.Entries.Add(entry);
        project.UpdateTranslationProviderConfiguration(tpConfig);
    
        // Add credentials AFTER configuring the provider
        if (memory.Uri != null && !string.IsNullOrEmpty(memory.Credential))
        {
            project.Credentials.AddCredential(memory.Uri, memory.Credential);
        }
    
        UpdateTranslateSettings(project);
        project.Save();
    }
    
    private static TranslationProviderReference GetTranslationProviderReference(MemoryResource memory)
    {
        TranslationProviderReference provider = null;
        
        if (memory.Uri != null && !string.IsNullOrEmpty(memory.Credential))
        {
            provider = new TranslationProviderReference(memory.Uri, memory.State, true);
        }
    
        return provider;
    }

    Complete Working Example for DeepL:

    // Configure DeepL provider
    var deepLMemory = new MemoryResource
    {
        Uri = new Uri("deepltranslationprovider:///"),
        Credential = "YOUR_DEEPL_API_KEY_HERE"
    };
    
    // Apply to project
    AddTranslationProvider(project, deepLMemory);
    
    // Now run your pretranslate task
    var targetFiles = project.GetTargetLanguageFiles(LanguageRegistryApi.Instance.GetLanguage(targetLanguage));
    var result = project.RunAutomaticTask(
        targetFiles.GetIds(),
        AutomaticTaskTemplateIds.PreTranslateFiles);

    Alternative Approach (if you must add credentials separately):

    // Add credential BEFORE configuring the provider
    sdlProject.Credentials.AddCredential(new Uri("deepltranslationprovider:///"), APIKEY);
    
    // Then configure your translation provider cascade
    var tpConfig = sdlProject.GetTranslationProviderConfiguration();
    var provider = new TranslationProviderReference(new Uri("deepltranslationprovider:///"), null, true);
    var entry = new TranslationProviderCascadeEntry(provider, false, true, false, 0);
    tpConfig.Entries.Add(entry);
    sdlProject.UpdateTranslationProviderConfiguration(tpConfig);
    sdlProject.Save();
    
    // Now run pretranslate
    var result = sdlProject.RunAutomaticTasks(projectFiles.ToArray(), sdlTaskTemplateIds);

    Patrick Andrew Hartnett | RWS Group

  • Hi  , check if you also should also pass state information with the connection when adding the translation provider reference in the cascade entry.  The problem might be related to the API version that is required, associated with your API key.

    What I'd do is
    1. Add the DeepL provider to your project and choose the correct API version 1 or 2
    2. Confirm it works in your project
    3. Save and close your project
    4. Open the project.sdlproj in an editor and recover the state content from the cascade entry.
    5. Pass the state content when adding our translation provider reference to the cascade entry.

    It should look something like: "ApiVersion":"V2 (DeepL Pro API subscription)" or V1 if your API key support V1

    make sense?


    Patrick Andrew Hartnett | RWS Group

  • Hi Patrick,

    thank you for your help! But I have just realized that I made the problem for myself...

    I was tricking with the credential store, because occasionally, I have to reload the project after manipulating the project xml, so I was saving the project credential store object and then restoring with reflection. Which works fine in some cases, but not in this case, because apparently some parts of studio keep referencing the original credential store that remained empty. Without this "hack", the deepl provider works as expected...

    thanks again!

    Tamas