# Classification Model Integration

## Install the Client Library

Install the Mindee Client Library for your language or framework of choice

{% tabs %}
{% tab title="Python" %}
Requires Python ≥ 3.9.\
Python ≥ 3.11 is highly recommended.

Simply install the [PyPi package](https://pypi.org/project/mindee/) using pip:

```sh
pip install -U mindee~=4.35
```

{% endtab %}

{% tab title="Node.js" %}
Requires Node.js ≥ 20.\
Node.js ≥ 22 is recommended.

Simply install the [NPM package](https://www.npmjs.com/package/mindee):

```sh
npm install mindee@^5.1.1
```

{% endtab %}

{% tab title="PHP" %}
Requires PHP ≥ 8.1.\
PHP ≥ 8.3 is recommended.

Simply install the [Packagist package](https://packagist.org/packages/mindee/mindee) using [composer](https://getcomposer.org/):

```sh
php composer.phar require "mindee/mindee:>=2.7"
```

{% endtab %}

{% tab title="Ruby" %}
Requires Ruby ≥ 3.0.\
Simply install the [gem](https://rubygems.org/gems/mindee) using:

```shell
gem install mindee -v '~> 4.13'
```

{% endtab %}

{% tab title="Java" %}
Requires Java ≥ 11.\
Java ≥ 17 is recommended.

Group ID: `com.mindee.sdk`\
Artifact ID: `mindee-api-java`\
Version: ![](https://img.shields.io/maven-central/v/com.mindee.sdk/mindee-api-java?style=flat-square\&label=%20)

There are various installation methods, Maven, Gradle, etc:

[Installation Details](https://central.sonatype.com/artifact/com.mindee.sdk/mindee-api-java)
{% endtab %}

{% tab title=".NET" %}
.NET ≥ 8.0 is recommended.

Simply install the [NuGet package](https://www.nuget.org/packages/Mindee) using .NET CLI:

```sh
dotnet add package Mindee --version 4.0
```

{% endtab %}
{% endtabs %}

Don't see support for your favorite language or framework? [Make a feature request!](https://feedback.mindee.com/?b=682f69c9e2404756e7e68d1c)

## Send a File and Poll

Use the client library to send the file to your Classification Model and return the result.

{% tabs %}
{% tab title="Python" %}
Requires Python ≥ 3.9. Python ≥ 3.10 is highly recommended.\
Requires the [Mindee Python client library](https://pypi.org/project/mindee/) version **4.35.1** or greater.

{% code lineNumbers="true" %}

```python
from mindee import (
    ClientV2,
    PathInput,
    ClassificationParameters,
    ClassificationResponse,
)

input_path = "/path/to/the/file.ext"
api_key = "MY_API_KEY"
model_id = "MY_MODEL_ID"

# Init a new client
mindee_client = ClientV2(api_key)

# Set parameters
params = ClassificationParameters(
    # ID of the model, required.
    model_id=model_id,
)

# Load a file from disk
input_source = PathInput(input_path)

# Send for processing using polling
response = mindee_client.enqueue_and_get_result(
    ClassificationResponse,
    input_source,
    params,
)

# Print a brief summary of the parsed data
print(response.inference)

# Access the classification result
classification: str = response.inference.result.classification.document_type
```

{% endcode %}
{% endtab %}

{% tab title="Node.js" %}
Requires Node.js ≥ 20. Node.js ≥ 22 is recommended.\
Requires the [Mindee Node.js client library](https://www.npmjs.com/package/mindee/) version **5.0.0** or greater.

{% code lineNumbers="true" %}

```javascript
import * as mindee from "mindee";
// If you're on CommonJS:
// const mindee = require("mindee");

const apiKey = "MY_API_KEY";
const filePath = "/path/to/the/file.ext";
const modelId = "MY_MODEL_ID";

// Init a new client
const mindeeClient = new mindee.Client(
  { apiKey: apiKey }
);

// Set product parameters
const params = {
  modelId: modelId,
};

// Load a file from disk
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
  mindee.product.Classification,
  inputSource,
  params,
);

// print a string summary
console.log(response.inference.toString());

// Access the classification result
const classification = response.inference.result.classification;
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
Requires PHP ≥ 8.1\
Requires the [Mindee PHP client library](https://packagist.org/packages/mindee/mindee) version **2.7.1** or greater.

{% code lineNumbers="true" %}

```php
<?php

use Mindee\ClientV2;
use Mindee\Input\InferenceParameters;
use Mindee\Input\PathInput;
use Mindee\Error\MindeeException;

$apiKey = "MY_API_KEY";
$filePath = "/path/to/the/file.ext";
$modelId = "MY_MODEL_ID";

// Init a new client
$mindeeClient = new ClientV2($apiKey);

// Set inference parameters
$inferenceParams = new InferenceParameters(
    // ID of the model, required.
    $modelId,

    // Options: set to `true` or `false` to override defaults

    // Enhance extraction accuracy with Retrieval-Augmented Generation.
    rag: null,
    // Extract the full text content from the document as strings.
    rawText: null,
    // Calculate bounding box polygons for all fields.
    polygon: null,
    // Boost the precision and accuracy of all extractions.
    // Calculate confidence scores for all fields.
    confidence: null
);

// Load a file from disk
$inputSource = new PathInput($filePath);

// Send for processing using polling
$response = $mindeeClient->enqueueAndGetInference(
    $inputSource,
    $inferenceParams
);

// Print a summary of the response
echo strval($response->inference);

// Access the result fields
$fields = $response->inference->result->fields;
```

{% endcode %}

Also take a look at the [Processing Results](https://docs.mindee.com/integrations/client-libraries-sdk/quick-start#processing-the-results) documentation.
{% endtab %}

{% tab title="Ruby" %}
Requires Ruby ≥ 3.0.\
Requires the [Mindee Ruby client library](https://rubygems.org/gems/mindee) version **4.13.0** or greater.

{% code lineNumbers="true" %}

```ruby
require 'mindee'
require 'mindee/v2/product'

input_path = '/path/to/the/file.ext'
api_key = 'MY_API_KEY'
model_id = 'MY_MODEL_ID'

# Init a new client
mindee_client = Mindee::ClientV2.new(api_key: api_key)

# Set inference parameters
classification_params = {
    # ID of the model, required.
    model_id: model_id,
}

# Load a file from disk
input_source = Mindee::Input::Source::PathInputSource.new(input_path)

# Send for processing
response = mindee_client.enqueue_and_get_result(
    Mindee::V2::Product::Classification::Classification,
    input_source,
    classification_params
)

# Access the classification result
puts response.inference.result.classification
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
Requires Java ≥ 8. Java ≥ 11 recommended.\
Requires the [Mindee Java client library](https://central.sonatype.com/artifact/com.mindee.sdk/mindee-api-java) version **4.43.0** or greater.

{% code lineNumbers="true" %}

```java
import com.mindee.MindeeClientV2;
import com.mindee.input.LocalInputSource;
import com.mindee.v2.product.classification.ClassificationClassifier;
import com.mindee.v2.product.classification.ClassificationResponse;
import com.mindee.v2.product.classification.ClassificationResult;
import com.mindee.v2.product.classification.params.ClassificationParameters;
import java.io.IOException;

public class SimpleMindeeClientV2 {

  public static void main(String[] args)
      throws IOException, InterruptedException
  {
    String apiKey = "MY_API_KEY";
    String filePath = "/path/to/the/file.ext";
    String modelId = "MY_MODEL_ID";

    // Init a new client
    MindeeClientV2 mindeeClient = new MindeeClientV2(apiKey);

    // Set inference parameters
    // Note: modelId is mandatory.
    ClassificationParameters classificationParams = ClassificationParameters
        // ID of the model, required.
        .builder(modelId)
        .build();

    // Load a file from disk
    LocalInputSource inputSource = new LocalInputSource(filePath);

    // Send for processing using polling
    ClassificationResponse response = mindeeClient.enqueueAndGetResult(
        ClassificationResponse.class,
        inputSource,
        classificationParams
    );

    // Print a summary of the response
    System.out.println(response.getInference().toString());

    // Access the classification result
    ClassificationResult result = response.getInference().getResult();
    ClassificationClassifier classification = result.getClassification();
  }
}

```

{% endcode %}
{% endtab %}

{% tab title=".NET" %}
.NET ≥ 8.0 is recommended.\
Requires the [Mindee .NET client library](https://www.nuget.org/packages/Mindee) version **4.0.0** or greater.

{% code lineNumbers="true" %}

```csharp
using Mindee;
using Mindee.Input;
using Mindee.V2;
using Mindee.V2.Product.Classification;
using Mindee.V2.Product.Classification.Params;

string filePath = "/path/to/the/file.ext";
string apiKey = "MY_API_KEY";
string modelId = "MY_MODEL_ID";

// Construct a new client
Client mindeeClient = new Client(apiKey);

// Set inference parameters
var productParams = new ClassificationParameters(
    modelId: modelId
);

// Load a file from disk
var inputSource = new LocalInputSource(filePath);

// Upload the file
var response = await mindeeClient.EnqueueAndGetResultAsync<ClassificationResponse>(
    inputSource, productParams);

// Print a summary of the response
System.Console.WriteLine(response.Inference.ToString());

// Access the classification results
var classification = response.Inference.Result.Classification;
```

{% endcode %}
{% endtab %}
{% endtabs %}
