Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Clarifai logo


This API Client is no longer supported.

Please use Clarifai C# gRPC instead, which is faster and more feature-rich.

Clarifai API C# Client

NuGet Build Status Build status


Adding the Clarifai C# library to your project

Within Visual Studio IDE:

Install-Package Clarifai

with the dotnet command line tool:

dotnet add package Clarifai


This library supports .NET Standard 1.3 which means it can be used on the following .NET implementations:

  • .NET Framework 4.6+
  • .NET Core 1.0+
  • Mono 4.6+
  • Xamarin.iOS 10.0+
  • Xamarin.Mac 3.0+
  • Xamarin.Android 7.0+
  • UWP 10.0+

Getting Started

Find complete code samples in the docs.

using System;
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Inputs;

namespace hello_csharp
    internal class Program
        public static async Task Main()
            // With `CLARIFAI_API_KEY` defined as an environment variable
            var client = new ClarifaiClient();
            // When passed in as a string
            var client = new ClarifaiClient("YOUR_CLARIFAI_API_KEY");
            // When using async/await
            var res = await client.PublicModels.GeneralModel
                .Predict(new ClarifaiURLImage(""))
            // When synchronous
            var res = client.PublicModels.GeneralModel
                .Predict(new ClarifaiURLImage(""))

            // Print the concepts
            foreach (var concept in res.Get().Data)
                Console.WriteLine($"{concept.Name}: {concept.Value}");

Public models can easily be used:

var response = await client.PublicModels.GeneralModel.Predict(new ClarifaiURLImage("IMAGE URL"))

As well as custom trained:

var response = await client.Predict<Concept>(
        new ClarifaiURLImage("")

Generics and casting

The library uses generics to specify the type of an output. In the first example using the Predict method, we use Concept to indicate that the model is a concept model. If we'd use a model ID of our public color model, we'd use Color instead of Concept.

Not all methods can however use generics. For example, the GetModels is able to return multiple models and you cannot determine in advance (at compile time) the types of model that will be returned. The request therefore returns a list of IModel objects. You can cast these instances to specific models, if you know its type:

if (models[0].OutputInfo.TypeExt == "concept")
    ConceptModel model = (ConceptModel) models[0];

In a similar way you may cast IPrediction when the actual class type is not known at compile time.

Please see more in the Developer's Guide.


NUnit 3 VS Test Adapter must be installed.

Unit tests

Run all unit tests using .NET Core by running this command in the solution directory:

dotnet test Clarifai.UnitTests/Clarifai.UnitTests.csproj

Integration tests

To successfully run integration tests, you have to have a valid Clarifai API key with all required permissions.

Create a new API key at the API keys page and set it as an environmental variable CLARIFAI_API_KEY.

Warning: The requests made by integration tests are run against the production system and will use your operations.

dotnet test Clarifai.IntegrationTests/Clarifai.IntegrationTests.csproj


This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

You can’t perform that action at this time.