Annotations
Label your data.

Annotations

Annotations (also known as labels) describe your inputs. When you add inputs to your app, we will create an input level annotation for each input. This input level annotation contains any data you provided in POST /inputs call. Models in your default workflow can also write annotations.
Once your input is successfully indexed, you can add additional annotations such as concepts and bounding boxes.

Add Annotations

You can label your inputs by calling the POST /annotations endpoint. For example, you can add concept(s) to an image, draw a bounding box, or label concept(s) in a video frame.
When you add an annotation, the app's default workflow will not run by default. This means that the annotation will not be immediately available for training of your custom model or for visual search. To make the annotation available for AI based search and training, you need to provide embed_model_version_id field. This field specifies how to associate the annotation for your input to one of the embedding models in your default workflow. When associated during patching then we know how to index it for training and visual search, therefore if your use case includes those features it is recommended to provide this field on each add annotation call.
You can add from 1 up to 128 annotations in a single API call.
Each annotation should contain at most one region. If it is a video, each annotation should contain 1 frame. If there are multiple regions in a frame you want to label, you can add multiple annotations for each regoin and each annotation will be contained within the same frame but a different region.

Annotate images with concepts

To annotate a concept present anywhere in an image:
Python
Java
NodeJS
cURL
Javascript (REST)
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_annotations_response = stub.PostAnnotations(
5
service_pb2.PostAnnotationsRequest(
6
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
7
annotations=[
8
resources_pb2.Annotation(
9
input_id="{YOUR_INPUT_ID}",
10
data=resources_pb2.Data(
11
concepts=[
12
resources_pb2.Concept(id="tree", value=1.), # 1 means true, this concept is present.
13
resources_pb2.Concept(id="water", value=0.) # 0 means false, this concept is not present.
14
]
15
),
16
embed_model_version_id="{EMBED_MODEL_VERSION_ID}"
17
)
18
]
19
),
20
metadata=metadata
21
)
22
23
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
24
print("There was an error with your request!")
25
print("\tCode: {}".format(post_annotations_response.outputs[0].status.code))
26
print("\tDescription: {}".format(post_annotations_response.outputs[0].status.description))
27
print("\tDetails: {}".format(post_annotations_response.outputs[0].status.details))
28
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
Copied!
1
import java.util.List;
2
import com.clarifai.grpc.api.*;
3
import com.clarifai.grpc.api.status.*;
4
5
// Insert here the initialization code as outlined on this page:
6
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
7
8
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
9
PostAnnotationsRequest.newBuilder().addAnnotations(
10
Annotation.newBuilder()
11
.setInputId("{YOUR_INPUT_ID}")
12
.setData(
13
Data.newBuilder().addConcepts(
14
Concept.newBuilder()
15
.setId("tree")
16
.setValue(1f) // 1 means true, this concept is present.
17
.build()
18
).addConcepts(
19
Concept.newBuilder()
20
.setId("water")
21
.setValue(0f) // 0 means false, this concept is not present.
22
.build()
23
)
24
).setEmbedModelVersionId("{EMBED_MODEL_VERSION_ID}") // so the concept can be used for custom model training
25
.build()
26
).build()
27
);
28
29
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
30
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
31
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
stub.PostAnnotations(
5
{
6
annotations: [
7
{
8
input_id: "{YOUR_INPUT_ID}",
9
// 1 means true, this concept is present.
10
// 0 means false, this concept is not present.
11
data: {
12
concepts: [
13
{id: "tree", value: 1},
14
{id: "water", value: 0}
15
]
16
},
17
embed_model_version_id: "{EMBED_MODEL_VERSION_ID}"
18
}
19
]
20
},
21
metadata,
22
(err, response) => {
23
if (err) {
24
throw new Error(err);
25
}
26
27
if (response.status.code !== 10000) {
28
throw new Error("Post annotations failed, status: " + response.status.description);
29
}
30
}
31
);
Copied!
1
# Value of 1 means true, this concept is present.
2
# Value of 0 means false, this concept is not present.
3
curl -X POST \
4
-H "Authorization: Key YOUR_API_KEY" \
5
-H "Content-Type: application/json" \
6
-d '
7
{
8
"annotations": [
9
{
10
"input_id": "{YOUR_INPUT_ID}",
11
"data": {
12
"concepts": [
13
{
14
"id": "tree",
15
"value": 1
16
},
17
{
18
"id": "water",
19
"value": 0
20
}
21
]
22
},
23
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
24
}
25
]
26
}'\
27
https://api.clarifai.com/v2/annotations
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"annotations": [
7
{
8
"input_id": "{YOUR_INPUT_ID}",
9
"data": {
10
"concepts": [
11
{
12
"id": "tree",
13
"value": 1
14
},
15
{
16
"id": "water",
17
"value": 0
18
}
19
]
20
},
21
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
22
}
23
]
24
});
25
26
const requestOptions = {
27
method: 'POST',
28
headers: {
29
'Accept': 'application/json',
30
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
31
},
32
body: raw
33
};
34
35
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
36
.then(response => response.text())
37
.then(result => console.log(result))
38
.catch(error => console.log('error', error));
Copied!

Annotate New Bounding Boxes in an Image

You can label a new bounding box by providing bounding box coordinates.
Python
Java
NodeJS
cURL
Javascript (REST)
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_annotations_response = stub.PostAnnotations(
5
service_pb2.PostAnnotationsRequest(
6
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
7
annotations=[
8
resources_pb2.Annotation(
9
input_id="{YOUR_INPUT_ID}",
10
data=resources_pb2.Data(
11
regions=[
12
resources_pb2.Region(
13
region_info=resources_pb2.RegionInfo(
14
bounding_box=resources_pb2.BoundingBox( # draw a bounding box
15
top_row=0,
16
left_col=0,
17
bottom_row=0.5,
18
right_col=0.5
19
)
20
),
21
data=resources_pb2.Data(
22
concepts=[
23
resources_pb2.Concept(id="tree", value=1.), # 1 means true, this concept is present.
24
resources_pb2.Concept(id="water", value=0.) # 0 means false, this concept is not present.
25
]
26
)
27
)
28
]
29
),
30
embed_model_version_id="{EMBED_MODEL_VERSION_ID}"
31
),
32
resources_pb2.Annotation(
33
input_id="{YOUR_INPUT_ID}",
34
data=resources_pb2.Data(
35
regions=[
36
resources_pb2.Region(
37
region_info=resources_pb2.RegionInfo(
38
bounding_box=resources_pb2.BoundingBox( # draw another bounding box
39
top_row=0.6,
40
left_col=0.6,
41
bottom_row=0.8,
42
right_col=0.8
43
)
44
),
45
data=resources_pb2.Data(
46
concepts=[
47
resources_pb2.Concept(id="bike", value=1.), # 1 means true, this concept is present.
48
]
49
)
50
)
51
]
52
),
53
embed_model_version_id="{EMBED_MODEL_VERSION_ID}"
54
)
55
]
56
),
57
metadata=metadata
58
)
59
60
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
61
print("There was an error with your request!")
62
print("\tCode: {}".format(post_annotations_response.outputs[0].status.code))
63
print("\tDescription: {}".format(post_annotations_response.outputs[0].status.description))
64
print("\tDetails: {}".format(post_annotations_response.outputs[0].status.details))
65
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
Copied!
1
import java.util.List;
2
import com.clarifai.grpc.api.*;
3
import com.clarifai.grpc.api.status.*;
4
5
// Insert here the initialization code as outlined on this page:
6
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
7
8
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
9
PostAnnotationsRequest.newBuilder().addAnnotations(
10
Annotation.newBuilder() // label a region in this image
11
.setInputId("{YOUR_INPUT_ID}")
12
.setData(
13
Data.newBuilder().addRegions(
14
Region.newBuilder()
15
.setRegionInfo(
16
RegionInfo.newBuilder()
17
.setBoundingBox( // draw a bounding box
18
BoundingBox.newBuilder()
19
.setTopRow(0f)
20
.setLeftCol(0f)
21
.setBottomRow(0.5f)
22
.setRightCol(0.5f)
23
.build()
24
)
25
.build()
26
)
27
.setData(
28
Data.newBuilder()
29
.addConcepts(
30
Concept.newBuilder()
31
.setId("tree")
32
.setValue(1f) // 1 means true, this concept is present.
33
.build()
34
)
35
.addConcepts(
36
Concept.newBuilder()
37
.setId("water")
38
.setValue(0f) // 0 means false, this concept is not present.
39
.build()
40
)
41
).build()
42
).build()
43
).setEmbedModelVersionId("{EMBED_MODEL_VERSION_ID}") // so the concept can be used for custom model training
44
.build()
45
).addAnnotations( // label another region in this image
46
.setInputId("{YOUR_INPUT_ID}")
47
.setData(
48
Data.newBuilder().addRegions(
49
Region.newBuilder()
50
.setRegionInfo(
51
RegionInfo.newBuilder()
52
.setBoundingBox( // draw another bounding box
53
BoundingBox.newBuilder()
54
.setTopRow(0.6f)
55
.setLeftCol(0.6f)
56
.setBottomRow(0.8f)
57
.setRightCol(0.8f)
58
.build()
59
)
60
.build()
61
)
62
.setData(
63
Data.newBuilder()
64
.addConcepts(
65
Concept.newBuilder()
66
.setId("bike")
67
.setValue(1f) // 1 means true, this concept is present.
68
.build()
69
)
70
).build()
71
).build()
72
).setEmbedModelVersionId("{EMBED_MODEL_VERSION_ID}") // so the concept can be used for custom model training
73
.build()
74
).build()
75
);
76
77
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
78
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
79
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
stub.PostAnnotations(
5
{
6
annotations: [
7
{ // label a region in this image
8
input_id: "{YOUR_INPUT_ID}",
9
data: {
10
regions: [
11
{
12
region_info: {
13
bounding_box: { // draw a bounding box
14
top_row: 0,
15
left_col: 0,
16
bottom_row: 0.5,
17
right_col: 0.5
18
}
19
}
20
// 1 means true, this concept is present.
21
// 0 means false, this concept is not present.
22
data: {
23
concepts: [
24
{id: "tree", value: 1},
25
{id: "water", value: 0}
26
]
27
},
28
}
29
]
30
}
31
embed_model_version_id: "{EMBED_MODEL_VERSION_ID}"
32
}, { // label another region in this image
33
input_id: "{YOUR_INPUT_ID}",
34
data: {
35
regions: [
36
{
37
region_info: {
38
bounding_box: { // draw another bounding box
39
top_row: 0.6,
40
left_col: 0.6,
41
bottom_row: 0.8,
42
right_col: 0.8
43
}
44
}
45
// 1 means true, this concept is present.
46
// 0 means false, this concept is not present.
47
data: {
48
concepts: [
49
{id: "bike", value: 1},
50
]
51
},
52
}
53
]
54
}
55
embed_model_version_id: "{EMBED_MODEL_VERSION_ID}"
56
}
57
]
58
},
59
metadata,
60
(err, response) => {
61
if (err) {
62
throw new Error(err);
63
}
64
65
if (response.status.code !== 10000) {
66
throw new Error("Post annotations failed, status: " + response.status.description);
67
}
68
}
69
);
Copied!
1
# draw 2 bouding boxes in the same region
2
# Value of 1 means true, this concept is present.
3
# Value of 0 means false, this concept is not present.
4
curl -X POST \
5
-H "Authorization: Key YOUR_API_KEY" \
6
-H "Content-Type: application/json" \
7
-d '
8
{
9
"annotations": [
10
{
11
"input_id": "{YOUR_INPUT_ID}",
12
"data": {
13
"regions": [
14
{
15
"region_info": {
16
"bounding_box": {
17
"top_row": 0,
18
"left_col": 0,
19
"bottom_row": 0.5,
20
"right_col": 0.5
21
}
22
},
23
"data": {
24
"concepts": [
25
{
26
"id": "tree",
27
"value": 1
28
},
29
{
30
"id": "water",
31
"value": 0
32
}
33
]
34
}
35
}
36
]
37
},
38
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
39
}, {
40
"input_id": "{YOUR_INPUT_ID}",
41
"data": {
42
"regions": [
43
{
44
"region_info": {
45
"bounding_box": {
46
"top_row": 0.6,
47
"left_col": 0.6,
48
"bottom_row": 0.8,
49
"right_col": 0.8
50
}
51
},
52
"data": {
53
"concepts": [
54
{
55
"id": "bike",
56
"value": 1
57
}
58
]
59
}
60
}
61
]
62
},
63
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
64
}
65
]
66
}'\
67
https://api.clarifai.com/v2/annotations
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"annotations": [
7
{
8
"input_id": "{YOUR_INPUT_ID}",
9
"data": {
10
"regions": [
11
{
12
"region_info": {
13
"bounding_box": {
14
"top_row": 0,
15
"left_col": 0,
16
"bottom_row": 0.5,
17
"right_col": 0.5
18
}
19
},
20
"data": {
21
"concepts": [
22
{
23
"id": "tree",
24
"value": 1
25
},
26
{
27
"id": "water",
28
"value": 0
29
}
30
]
31
}
32
}
33
]
34
},
35
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
36
}, {
37
"input_id": "{YOUR_INPUT_ID}",
38
"data": {
39
"regions": [
40
{
41
"region_info": {
42
"bounding_box": {
43
"top_row": 0.6,
44
"left_col": 0.6,
45
"bottom_row": 0.8,
46
"right_col": 0.8
47
}
48
},
49
"data": {
50
"concepts": [
51
{
52
"id": "bike",
53
"value": 1
54
}
55
]
56
}
57
}
58
]
59
},
60
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
61
}
62
]
63
});
64
65
const requestOptions = {
66
method: 'POST',
67
headers: {
68
'Accept': 'application/json',
69
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
70
},
71
body: raw
72
};
73
74
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
75
.then(response => response.text())
76
.then(result => console.log(result))
77
.catch(error => console.log('error', error));
Copied!

Annotate Existing Regions in an Image

When you add an input, detection models (such as Face Detection or General Detection) will detect regions in your image where there appear to be relevant objects. You can check these detected regions by listing model's annotations. Your labels should be contained within Region.Data. Each annotation can have only 1 region. If you want to label multiple regions, it is possible to label multiple annotations in a single API call.
Python
Java
NodeJS
cURL
Javascript (REST)
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_annotations_response = stub.PostAnnotations(
5
service_pb2.PostAnnotationsRequest(
6
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
7
annotations=[
8
resources_pb2.Annotation( # label a region in this image
9
input_id="{YOUR_INPUT_ID}",
10
data=resources_pb2.Data(
11
regions=[
12
resources_pb2.Region(
13
id="{REGION_ID_1}" , # this should be a region id returned from list annotations call
14
data=resources_pb2.Data(
15
concepts=[
16
resources_pb2.Concept(id="tree", value=1.), # 1 means true, this concept is present.
17
resources_pb2.Concept(id="water", value=0.) # 0 means false, this concept is not present.
18
]
19
)
20
)
21
]
22
),
23
embed_model_version_id="{EMBED_MODEL_VERSION_ID}"
24
),
25
resources_pb2.Annotation( # label another region in this image
26
input_id="{YOUR_INPUT_ID}",
27
data=resources_pb2.Data(
28
regions=[
29
resources_pb2.Region(
30
id="{REGION_ID_2}" , # this should be a region id returned from list annotations call
31
data=resources_pb2.Data(
32
concepts=[
33
resources_pb2.Concept(id="bike", value=1.), # 1 means true, this concept is present.
34
]
35
)
36
)
37
]
38
),
39
embed_model_version_id="{EMBED_MODEL_VERSION_ID}"
40
),
41
]
42
),
43
metadata=metadata
44
)
45
46
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
47
print("There was an error with your request!")
48
print("\tCode: {}".format(post_annotations_response.outputs[0].status.code))
49
print("\tDescription: {}".format(post_annotations_response.outputs[0].status.description))
50
print("\tDetails: {}".format(post_annotations_response.outputs[0].status.details))
51
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
Copied!
1
import java.util.List;
2
import com.clarifai.grpc.api.*;
3
import com.clarifai.grpc.api.status.*;
4
5
// Insert here the initialization code as outlined on this page:
6
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
7
8
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
9
PostAnnotationsRequest.newBuilder().addAnnotations(
10
Annotation.newBuilder() // label a region in this image
11
.setInputId("{YOUR_INPUT_ID}")
12
.setData(
13
Data.newBuilder().addRegions(
14
Region.newBuilder()
15
.setId("{REGION_ID_1}") // this should be a region id returned from list annotations call
16
.setData(
17
Data.newBuilder().addConcepts(
18
Concept.newBuilder()
19
.setId("tree")
20
.setValue(1f) // 1 means true, this concept is present.
21
.build()
22
).addConcepts(
23
Concept.newBuilder()
24
.setId("water")
25
.setValue(0f) // 0 means false, this concept is not present.
26
.build()
27
)
28
).build()
29
).build()
30
).setEmbedModelVersionId("{EMBED_MODEL_VERSION_ID}") // so the concept can be used for custom model training
31
.build()
32
).AddAnnotations(
33
Annotation.newBuilder() // label another region in the same image
34
.setInputId("{YOUR_INPUT_ID}")
35
.setData(
36
Data.newBuilder().addRegions(
37
Region.newBuilder()
38
.setId("{REGION_ID_2}") // this should be a region id returned from list annotations call
39
.setData(
40
Data.newBuilder().addConcepts(
41
Concept.newBuilder()
42
.setId("bike")
43
.setValue(1f) // 1 means true, this concept is present.
44
.build()
45
)
46
).build()
47
).build()
48
).setEmbedModelVersionId("{EMBED_MODEL_VERSION_ID}") // so the concept can be used for custom model training
49
.build()
50
).build()
51
);
52
53
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
54
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
55
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
stub.PostAnnotations(
5
{
6
annotations: [
7
{ // label a region in this image
8
input_id: "{YOUR_INPUT_ID}",
9
data: {
10
regions: [
11
{
12
id: "{REGION_ID_1}" // this should be a region id returned from list annotations call
13
// 1 means true, this concept is present.
14
// 0 means false, this concept is not present.
15
data: {
16
concepts: [
17
{id: "tree", value: 1},
18
{id: "water", value: 0}
19
]
20
},
21
}
22
]
23
}
24
embed_model_version_id: "{EMBED_MODEL_VERSION_ID}"
25
}, { // label another region in this image
26
input_id: "{YOUR_INPUT_ID}",
27
data: {
28
regions: [
29
{
30
id: "{REGION_ID_2}" // this should be a region id returned from list annotations call
31
// 1 means true, this concept is present.
32
// 0 means false, this concept is not present.
33
data: {
34
concepts: [
35
{id: "bike", value: 1},
36
]
37
},
38
}
39
]
40
}
41
embed_model_version_id: "{EMBED_MODEL_VERSION_ID}"
42
}
43
]
44
},
45
metadata,
46
(err, response) => {
47
if (err) {
48
throw new Error(err);
49
}
50
51
if (response.status.code !== 10000) {
52
throw new Error("Post annotations failed, status: " + response.status.description);
53
}
54
}
55
);
Copied!
1
# Value of 1 means true, this concept is present.
2
# Value of 0 means false, this concept is not present.
3
# region id should be a region id returned from list annotations call
4
curl -X POST \
5
-H "Authorization: Key YOUR_API_KEY" \
6
-H "Content-Type: application/json" \
7
-d '
8
{
9
"annotations": [
10
{
11
"input_id": "{YOUR_INPUT_ID}",
12
"data": {
13
"regions": [
14
{
15
"id": "{REGION_ID_1}",
16
"data": {
17
"concepts": [
18
{
19
"id": "tree",
20
"value": 1
21
},
22
{
23
"id": "water",
24
"value": 0
25
}
26
]
27
}
28
}
29
]
30
},
31
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
32
}, {
33
"input_id": "{YOUR_INPUT_ID}",
34
"data": {
35
"regions": [
36
{
37
"id": "{REGION_ID_2}",
38
"data": {
39
"concepts": [
40
{
41
"id": "bike",
42
"value": 1
43
}
44
]
45
}
46
}
47
]
48
},
49
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
50
}
51
]
52
}'\
53
https://api.clarifai.com/v2/annotations
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"annotations": [
7
{
8
"input_id": "{YOUR_INPUT_ID}",
9
"data": {
10
"regions": [
11
{
12
"id": "{REGION_ID_1}",
13
"data": {
14
"concepts": [
15
{
16
"id": "tree",
17
"value": 1
18
},
19
{
20
"id": "water",
21
"value": 0
22
}
23
]
24
}
25
}
26
]
27
},
28
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
29
}, {
30
"input_id": "{YOUR_INPUT_ID}",
31
"data": {
32
"regions": [
33
{
34
"id": "{REGION_ID_2}",
35
"data": {
36
"concepts": [
37
{
38
"id": "bike",
39
"value": 1
40
}
41
]
42
}
43
}
44
]
45
},
46
"embed_model_version_id": "{EMBED_MODEL_VERSION_ID}"
47
}
48
]
49
});
50
51
const requestOptions = {
52
method: 'POST',
53
headers: {
54
'Accept': 'application/json',
55
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
56
},
57
body: raw
58
};
59
60
fetch("https://api.clarifai.com/v2/annotations", requestOptions)
61
.then(response => response.text())
62
.then(result => console.log(result))
63
.catch(error => console.log('error', error));
Copied!

Annotate Images with Different user_id and status.

Each annotation is tied to a user or a model in your workflow. By default, when a user posts an annotation, this user is the owner of the annotation. Sometimes however, you might want to post an annotation as other user, for example, when assigning an image to another user, an annotation can be created with another user_id (and status PENDING).
Note: only the app owner can post an annotation with other user's user_id, collaborators cannot.
Python
Java
NodeJS
cURL
Javascript (REST)
1
# Insert here the initialization code as outlined on this page:
2
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
post_annotations_response = stub.PostAnnotations(
5
service_pb2.PostAnnotationsRequest(
6
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
7
annotations=[
8
resources_pb2.Annotation(
9
input_id="{YOUR_INPUT_ID}",
10
user_id="{USER_ID}", # If empty, it is the user who posts this annotation
11
data=status_pb2.Status(
12
code=status_code_pb2.ANNOTATION_PENDING # annotation pending status. By default success.
13
),
14
)
15
]
16
),
17
metadata=metadata
18
)
19
20
if post_annotations_response.status.code != status_code_pb2.SUCCESS:
21
print("There was an error with your request!")
22
print("\tCode: {}".format(post_annotations_response.outputs[0].status.code))
23
print("\tDescription: {}".format(post_annotations_response.outputs[0].status.description))
24
print("\tDetails: {}".format(post_annotations_response.outputs[0].status.details))
25
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)
Copied!
1
import java.util.List;
2
import com.clarifai.grpc.api.*;
3
import com.clarifai.grpc.api.status.*;
4
5
// Insert here the initialization code as outlined on this page:
6
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
7
8
MultiAnnotationResponse postAnnotationsResponse = stub.postAnnotations(
9
PostAnnotationsRequest.newBuilder().addAnnotations(
10
Annotation.newBuilder()
11
.setInputId("{YOUR_INPUT_ID}")
12
.setUserId("{USER_ID}") // If empty, it is the user who posts this annotation
13
.setStatus(
14
Status.newBuilder()
15
.setCodeValue(StatusCode.ANNOTATION_PENDING_VALUE) // annotation pending status. By default, it's ANNOTATION_SUCCESS_VALUE.
16
.build()
17
)
18
.build()
19
).build()
20
);
21
22
if (postAnnotationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
23
throw new RuntimeException("Post annotations failed, status: " + postAnnotationsResponse.getStatus());
24
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
3
4
stub.PostAnnotations(
5
{
6
annotations: [
7
{
8
input_id: "{YOUR_INPUT_ID}",
9
user_id: "{USER_ID}", // If empty, it is the user who posts this annotation
10
status: {
11
code: 24151 // annotation pending status. By default success.
12
}
13
}
14
]
15
},
16
metadata,
17
(err, response) => {
18
if (err) {
19
throw new Error(err);
20
}
21
22
if (response.status.code !== 10000) {
23
throw new Error("Post annotations failed, status: " + response.status.description);
24
}
25
}
26
);
Copied!
1
curl -X POST \
2
-H "Authorization: Key YOUR_API_KEY" \
3
-H "Content-Type: application/json" \
4
-d '
5
{
6
"annotations": [
7
{
8
"input_id": "{YOUR_INPUT_ID}",
9
"user_id": "{USER_ID}",
10
"status": {
11
"code": "ANNOTATION_PENDING"
12
}
13
}
14
]
15
}'\
16
https://api.clarifai.com/v2/annotations
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"annotations": [
7
{
8
"input_id": "{YOUR_INPUT_ID}",
9
"user_id": "{USER_ID}",
10
"status": {
11
"code": "ANNOTATION_PENDING"
12
}
13
}
14
]
15
});
16
17
const requestOptions = {
18
method: 'POST',