Setting Up Mesh Workflows

Manage your Mesh Workflows.

Create

To create a new custom workflow, specify a list of model IDs that are to be included in the workflow. Each model ID also requires a specific model version ID, since a model can have several versions.

Java
NodeJS
Python
cURL
Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiWorkflowResponse postWorkflowsResponse = stub.postWorkflows(
PostWorkflowsRequest.newBuilder().addWorkflows(
Workflow.newBuilder()
.setId("my-custom-workflow")
.addNodes(
WorkflowNode.newBuilder()
.setId("food-concepts")
.setModel(
Model.newBuilder()
.setId("bd367be194cf45149e75f01d59f77ba7")
.setModelVersion(ModelVersion.newBuilder().setId("dfebc169854e429086aceb8368662641"))
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId("general-concepts")
.setModel(
Model.newBuilder()
.setId("aaa03c23b3724a16a56b629203edc62c")
.setModelVersion(ModelVersion.newBuilder().setId("aa9ca48295b37401f8af92ad1af0d91d"))
)
)
).build()
);
if (postWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post workflows failed, status: " + postWorkflowsResponse.getStatus());
}
NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PostWorkflows(
{
workflows: [
{
id: "my-custom-workflow",
nodes: [
{
id: "food-concepts",
model: {
id: "bd367be194cf45149e75f01d59f77ba7",
model_version: {
id: "dfebc169854e429086aceb8368662641"
}
}
},
{
id: "general-concepts",
model: {
id: "aaa03c23b3724a16a56b629203edc62c",
model_version: {
id: "aa9ca48295b37401f8af92ad1af0d91d"
}
}
},
]
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post workflows failed, status: " + response.status.description);
}
}
);
Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
post_workflows_response = stub.PostWorkflows(
service_pb2.PostWorkflowsRequest(
workflows=[
resources_pb2.Workflow(
id="my-custom-workflow",
nodes=[
resources_pb2.WorkflowNode(
id="food-concepts",
model=resources_pb2.Model(
id="bd367be194cf45149e75f01d59f77ba7",
model_version=resources_pb2.ModelVersion(
id="dfebc169854e429086aceb8368662641"
)
)
),
resources_pb2.WorkflowNode(
id="general-concepts",
model=resources_pb2.Model(
id="aaa03c23b3724a16a56b629203edc62c",
model_version=resources_pb2.ModelVersion(
id="aa9ca48295b37401f8af92ad1af0d91d"
)
)
),
]
)
]
),
metadata=metadata
)
if post_workflows_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post workflows failed, status: " + post_workflows_response.status.description)
cURL
# The first model is the Clarifai's Food model, and the second the Clarifai's General model.
curl -X POST 'https://api.clarifai.com/v2/workflows' \
-H 'Content-Type: application/json' \
-H 'Authorization: Key YOUR_API_KEY' \
--data-raw '{
"workflows": [{
"id": "my-custom-workflow",
"nodes": [
{
"id": "food-concepts",
"model": {
"id": "bd367be194cf45149e75f01d59f77ba7",
"model_version": {
"id": "dfebc169854e429086aceb8368662641"
}
}
},
{
"id": "general-concepts",
"model": {
"id": "aaa03c23b3724a16a56b629203edc62c",
"model_version": {
"id": "aa9ca48295b37401f8af92ad1af0d91d"
}
}
}
]
}]
}'

Workflow Predict

Predict using a workflow. The response will contain the predictions each model in the workflow returns for the input.

Java
NodeJS
Python
cURL
Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
PostWorkflowResultsResponse postWorkflowResultsResponse = stub.postWorkflowResults(
PostWorkflowResultsRequest.newBuilder()
.setWorkflowId("{YOUR_WORKFLOW_ID}")
.addInputs(
Input.newBuilder().setData(
Data.newBuilder().setImage(
Image.newBuilder().setUrl(
"https://samples.clarifai.com/metro-north.jpg"
)
)
)
)
.build()
);
if (postWorkflowResultsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post workflow results failed, status: " + postWorkflowResultsResponse.getStatus());
}
// We'll get one WorkflowResult for each input we used above. Because of one input, we have here
// one WorkflowResult.
WorkflowResult results = postWorkflowResultsResponse.getResults(0);
// Each model we have in the workflow will produce one output.
for (Output output : results.getOutputsList()) {
Model model = output.getModel();
System.out.println("Predicted concepts for the model `" + model.getName() + "`:");
for (Concept concept : output.getData().getConceptsList()) {
System.out.printf("\t%s %.2f%n", concept.getName(), concept.getValue());
}
}
NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PostWorkflowResults(
{
workflow_id: "{YOUR_WORKFLOW_ID}",
inputs: [
{data: {image: {url: "https://samples.clarifai.com/metro-north.jpg"}}}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post workflow results failed, status: " + response.status.description);
}
// We'll get one WorkflowResult for each input we used above. Because of one input, we have here
// one WorkflowResult.
const results = response.results[0];
// Each model we have in the workflow will produce one output.
for (const output of results.outputs) {
const model = output.model;
console.log("Predicted concepts for the model `" + model.name + "`:");
for (const concept of output.data.concepts) {
console.log("\t" + concept.name + " " + concept.value);
}
}
}
);
Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
post_workflow_results_response = stub.PostWorkflowResults(
service_pb2.PostWorkflowResultsRequest(
workflow_id="{YOUR_WORKFLOW_ID}",
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url="https://samples.clarifai.com/metro-north.jpg"
)
)
)
]
),
metadata=metadata
)
if post_workflow_results_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post workflow results failed, status: " + post_workflow_results_response.status.description)
# We'll get one WorkflowResult for each input we used above. Because of one input, we have here
# one WorkflowResult.
results = post_workflow_results_response.results[0]
# Each model we have in the workflow will produce one output.
for output in results.outputs:
model = output.model
print("Predicted concepts for the model `%s`" % model.name)
for concept in output.data.concepts:
print("\t%s %.2f" % (concept.name, concept.value))
cURL
curl -X POST \
-H 'authorization: Key YOUR_API_KEY' \
-H 'content-type: application/json' \
-d '{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
}
}
]
}'\
https://api.clarifai.com/v2/workflows/{YOUR_WORKFLOW_ID}/results

Get

Get all workflows in an app

Return all custom workflows in your app.

Java
NodeJS
Python
cURL
Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiWorkflowResponse listWorkflowsResponse = stub.listWorkflows(ListWorkflowsRequest.newBuilder().build());
if (listWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List workflows failed, status: " + listWorkflowsResponse.getStatus());
}
for (Workflow workflow : listWorkflowsResponse.getWorkflowsList()) {
System.out.println("The workflow " + workflow.getId() + " consists of these models:");
for (WorkflowNode workflowNode : workflow.getNodesList()) {
Model model = workflowNode.getModel();
System.out.println(model.getId());
}
System.out.println();
}
NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.ListWorkflows(
{},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List workflows failed, status: " + response.status.description);
}
for (const workflow of response.workflows) {
console.log("The workflow " + workflow.id + " consists of these models:");
for (const workflowNode of workflow.nodes) {
const model = workflowNode.model;
console.log(model.id);
}
console.log();
}
}
);
Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
list_workflows_response = stub.ListWorkflows(
service_pb2.ListWorkflowsRequest(),
metadata=metadata
)
if list_workflows_response.status.code != status_code_pb2.SUCCESS:
raise Exception("List workflows failed, status: " + list_workflows_response.status.description)
for workflow in list_workflows_response.workflows:
print(f"The workflow {workflow.id} consists of these models:")
for workflow_node in workflow.nodes:
model = workflow_node.model
print(model.id)
print()
cURL
curl -X GET 'https://api.clarifai.com/v2/workflows' \
-H 'Content-Type: application/json' \
-H 'Authorization: Key YOUR_API_KEY'

Get a workflow by a specific ID

Returns information about a specific workflow.

Java
NodeJS
Python
cURL
Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
SingleWorkflowResponse getWorkflowResponse = stub.getWorkflow(
GetWorkflowRequest.newBuilder()
.setWorkflowId("food-and-general")
.build()
);
if (getWorkflowResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get workflow failed, status: " + getWorkflowResponse.getStatus());
}
Workflow workflow = getWorkflowResponse.getWorkflow();
System.out.println("The workflow consists of these models:");
for (WorkflowNode workflowNode : workflow.getNodesList()) {
Model model = workflowNode.getModel();
System.out.println(model.getId());
}
NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.GetWorkflow(
{
workflow_id: "my-custom-workflow"
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Get workflow failed, status: " + response.status.description);
}
const workflow = response.workflow;
console.log("The workflow consists of these models:");
for (const workflowNode of workflow.nodes) {
const model = workflowNode.model;
console.log(model.id);
}
}
);
Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
get_workflow_response = stub.GetWorkflow(
service_pb2.GetWorkflowRequest(
workflow_id="my-custom-workflow"
),
metadata=metadata
)
if get_workflow_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Get workflow failed, status: " + get_workflow_response.status.description)
workflow = get_workflow_response.workflow
print(f"The workflow consists of these models:")
for workflow_node in workflow.nodes:
model = workflow_node.model
print(model.id)
cURL
curl -X GET 'https://api.clarifai.com/v2/workflows/my-custom-workflow' \
-H 'Content-Type: application/json' \
-H 'Authorization: Key YOUR_API_KEY'

Creating new workflow versions

Patch workflow

"PatchWorkflow" will create a new version of a workflow.

Java
NodeJS
Python
cURL
Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiWorkflowResponse patchWorkflowsResponse = stub.patchWorkflows(
PatchWorkflowsRequest.newBuilder()
.setAction("overwrite")
.addWorkflows(
Workflow.newBuilder()
.setId("my-custom-workflow")
.addNodes(
WorkflowNode.newBuilder()
.setId("general-concept2")
.setModel(
Model.newBuilder()
.setId("aaa03c23b3724a16a56b629203edc62c")
.setModelVersion(ModelVersion.newBuilder().setId("aa7f35c01e0642fda5cf400f543e7c40"))
)
)
).build()
);
if (patchWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch workflows failed, status: " + patchWorkflowsResponse.getStatus());
}
NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PatchWorkflows(
{
action: "overwrite",
workflows: [
{
id: "my-custom-workflow",
nodes: [
{
id: "general-concept2",
model: {
id: "aaa03c23b3724a16a56b629203edc62c",
model_version: {
id: "aa7f35c01e0642fda5cf400f543e7c40"
}
}
}
]
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Patch workflows failed, status: " + response.status.description);
}
}
);
Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
patch_workflows_response = stub.PatchWorkflows(
service_pb2.PatchWorkflowsRequest(
action="overwrite",
workflows=[
resources_pb2.Workflow(
id="my-custom-workflow",
nodes=[
resources_pb2.WorkflowNode(
id="general-concept2",
model=resources_pb2.Model(
id="aaa03c23b3724a16a56b629203edc62c",
model_version=resources_pb2.ModelVersion(
id="aa7f35c01e0642fda5cf400f543e7c40"
)
)
),
]
)
]
),
metadata=metadata
)
if patch_workflows_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Patch workflows failed, status: " + patch_workflows_response.status.description)
cURL
curl --location -g --request PATCH 'api-dev.clarifai.com/v2/users/{{user_id}}/apps/{{app_id}}/workflows' \
--header 'Content-Type: application/json' \
--header 'Authorization: Key {YOUR API KEY HERE}' \
--data-raw '{
"workflows": [
{
"id": "{{workflow_id}}",
"nodes": [
{
"id": "general-concept2",
"model": {
"id": "aaa03c23b3724a16a56b629203edc62c",
"model_version": {
"id": "aa7f35c01e0642fda5cf400f543e7c40"
}
}
}
]
}
],
"action": "overwrite"
}'

Delete

Delete workflow by ID

Delete a specific workflow.

Java
NodeJS
Python
cURL
Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
BaseResponse deleteWorkflowResponse = stub.deleteWorkflow(
DeleteWorkflowRequest.newBuilder()
.setWorkflowId("my-custom-workflow")
.build()
);
if (deleteWorkflowResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete workflow failed, status: " + deleteWorkflowResponse.getStatus());
}
NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.DeleteWorkflow(
{
workflow_id: "my-custom-workflow",
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete workflow failed, status: " + response.status.description);
}
}
);
Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
delete_workflow_response = stub.DeleteWorkflow(
service_pb2.DeleteWorkflowRequest(
workflow_id="my-custom-workflow"
),
metadata=metadata
)
if delete_workflow_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Delete workflow failed, status: " + delete_workflow_response.status.description)
cURL
curl -X DELETE 'https://api.clarifai.com/v2/workflows/my-custom-workflow \
-H 'Content-Type: application/json' \
-H 'Authorization: Key YOUR_API_KEY'

Delete all workflows

Deletes all custom workflows.

Note: instead of "delete_all" it's possible to specify a list of workflow IDs to be deleted, using the ids field.

Java
NodeJS
Python
cURL
Java
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
BaseResponse deleteWorkflowsResponse = stub.deleteWorkflows(
DeleteWorkflowsRequest.newBuilder()
.setDeleteAll(true)
.build()
);
if (deleteWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete workflows failed, status: " + deleteWorkflowsResponse.getStatus());
}
NodeJS
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.DeleteWorkflows(
{
delete_all: true
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete workflows failed, status: " + response.status.description);
}
}
);
Python
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
delete_workflows_response = stub.DeleteWorkflows(
service_pb2.DeleteWorkflowsRequest(
delete_all=True
),
metadata=metadata
)
if delete_workflows_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Delete workflows failed, status: " + delete_workflows_response.status.description)
cURL
curl -X DELETE 'https://api.clarifai.com/v2/workflows' \
-H 'Content-Type: application/json' \
-H 'Authorization: Key YOUR_API_KEY' \
--data-raw '{
"delete_all": true
}'