Search code examples
node.jsclarifai

Unable to authenticate using API key


I am trying to use the Apparel detection model with Node.js. I keep running into 2 errors. The first error I receive is:

Invalid API key or Invalid API key/application pair

Created from this code:

const grpc = require("@grpc/grpc-js");

const stub=ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key xxxxxxxxxxxxxxxxxxxxxxxxxxx");

stub.PostModelOutputs(
    {
        model_id: "72c523807f93e18b431676fb9a58e6ad",
        version_id: "1ed35c3d176f45d69d2aa7971e6ab9fe",  // This is optional. Defaults to the latest model version.
        inputs: [
            {data: {image: {url: "https://sc01.alicdn.com/kf/HTB1VxCwKFXXXXXeaXXXq6xXFXXX1.jpg"}}}
        ]
    },
    metadata,
    (err, response) => {
        if (err) {
            throw new Error(err);
        }

        if (response.status.code !== 10000) {
            throw new Error("Post model outputs failed, status: " + response.status.description);
        }

        // Since we have one input, one output will exist here.
        const output = response.outputs[0];

        console.log("Predicted concepts:");
        for (const concept of output.data.concepts) {
            console.log(concept.name + " " + concept.value);
        }
    }
);

The second problem I am running into is when trying to create a workflow for this application. When selecting the Apparel model and clicking create workflow I receive this message:

Your request was blocked. Missing feature flags: [Model Visual Detector]

I receive the same message with different models/ combination of models that I have tried. Sorry for the numerous questions I feel quite lost right now. Thank you for any help.


Solution

  • Using your API key I was able to successfully call the model. I omitted the version_id field however. It looks like this version id is incorrect (if you omit it then it will just get the most recent version of the model).

    const grpc = require("@grpc/grpc-js");
    
    const stub=ClarifaiStub.grpc();
    const metadata = new grpc.Metadata();
    metadata.set("authorization", "Key xxxxxxxxxxxxxxxxxxxxxxxxxxx");
    
    stub.PostModelOutputs(
        {
            model_id: "72c523807f93e18b431676fb9a58e6ad",
            inputs: [
                {data: {image: {url: "https://sc01.alicdn.com/kf/HTB1VxCwKFXXXXXeaXXXq6xXFXXX1.jpg"}}}
            ]
        },
        metadata,
        (err, response) => {
            if (err) {
                throw new Error(err);
            }
    
            if (response.status.code !== 10000) {
                throw new Error("Post model outputs failed, status: " + response.status.description);
            }
    
            // Since we have one input, one output will exist here.
            const output = response.outputs[0];
    
            console.log("Predicted concepts:");
            for (const concept of output.data.concepts) {
                console.log(concept.name + " " + concept.value);
            }
        }
    );
    

    I masked your key (including in the answer) since you generally don't want to share this publicly.