© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
SWEETPONY

✅ api response 401

hey, I'm trying to use nlpcloud to translate text
there is curl example:
curl "https://api.nlpcloud.io/v1/nllb-200-3-3b/translation" \
  -H "Authorization: Token <token>" \
  -H "Content-Type: application/json" \
  -X POST -d '{
    "text":"John Doe has been working for Microsoft in Seattle since 1999.",
    "source":"en",
    "target":"fr"
  }'
curl "https://api.nlpcloud.io/v1/nllb-200-3-3b/translation" \
  -H "Authorization: Token <token>" \
  -H "Content-Type: application/json" \
  -X POST -d '{
    "text":"John Doe has been working for Microsoft in Seattle since 1999.",
    "source":"en",
    "target":"fr"
  }'


I wrote following
nlpclient
nlpclient
:
public class NlpTranslationClient
{
    private readonly string _apiKey;
    private readonly Uri _uri = new("https://api.nlpcloud.io/v1/nllb-200-3-3b/translation");

    public NlpTranslationClient(string apiKey)
        => _apiKey = apiKey;

    public async Task Translate(
        string text,
        string source,
        string target)
    {
        using var client = new HttpClient();
        
        client.DefaultRequestHeaders.Add("Authorization", _apiKey);
        
        var translationObject = new TranslationObj
        {
            Text = text,
            Source = source,
            Target = target
        };

        var payload = new StringContent(
            translationObject.ToJson(),
            Encoding.UTF8,
            "application/json");

        var res = await client.PostAsync(_uri, payload); // just for testing
    }
}
public class NlpTranslationClient
{
    private readonly string _apiKey;
    private readonly Uri _uri = new("https://api.nlpcloud.io/v1/nllb-200-3-3b/translation");

    public NlpTranslationClient(string apiKey)
        => _apiKey = apiKey;

    public async Task Translate(
        string text,
        string source,
        string target)
    {
        using var client = new HttpClient();
        
        client.DefaultRequestHeaders.Add("Authorization", _apiKey);
        
        var translationObject = new TranslationObj
        {
            Text = text,
            Source = source,
            Target = target
        };

        var payload = new StringContent(
            translationObject.ToJson(),
            Encoding.UTF8,
            "application/json");

        var res = await client.PostAsync(_uri, payload); // just for testing
    }
}


everything should be good but I get 401 in
res
res

whats wrong with my code?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

swagger Error: response status is 401
C#CC# / help
2y ago
❔ Sharepoint REST API 401 Error
C#CC# / help
3y ago
✅ Web API Controller Response JObject
C#CC# / help
2y ago
✅ Web API format for error response
C#CC# / help
2y ago