/v1/classifyClassifyThis endpoint makes a prediction about which label fits the specified text inputs best. To make a prediction, Classify uses the provided examples of text + label pairs as a reference. Note: Fine-tuned models trained on classification examples don't require the examples parameter to be passed in explicitly.
Parameters
X-Client-NamestringheaderThe name of the project that is making the request.
Request body
application/json
examplesarray of objectAn array of examples to provide context to the model. Each example is a text string and its associated label/class. Each unique label requires at least 2 examples associated with it; the maximum number of examples is 2500, and each example has a maximum length of 512 tokens. The values should be structured as `{text: "...",label: "..."}`. Note: [Fine-tuned Models](https://docs.cohere.com/docs/classify-fine-tuning) trained on classification examples don't require the `examples` parameter to be passed in explicitly.
Show child attributes
Show array items
labelstringtextstringinputsarray of stringrequiredA list of up to 96 texts to be classified. Each one must be a non-empty string. There is, however, no consistent, universal limit to the length a particular input can be. We perform classification on the first `x` tokens of each input, and `x` varies depending on which underlying model is powering classification. The maximum token length for each model is listed in the "max tokens" column [here](https://docs.cohere.com/docs/models). Note: by default the `truncate` parameter is set to `END`, so tokens exceeding the limit will be automatically dropped. This behavior can be disabled by setting `truncate` to `NONE`, which will result in validation errors for longer texts.
Show child attributes
modelstringID of a [Fine-tuned](https://docs.cohere.com/v2/docs/classify-starting-the-training) Classify model
presetstringThe ID of a custom playground preset. You can create presets in the [playground](https://dashboard.cohere.com/playground). If you use a preset, all other parameters become optional, and any included parameters will override the preset's parameters.
truncatestringOne of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length. Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned.
{
"examples": [
{
"label": "string",
"text": "string"
}
],
"inputs": [
"string"
],
"model": "string",
"preset": "my-preset-a58sbd",
"truncate": "END"
}Responses
Headers
X-API-WarningWarning description for incorrect usage of the API
classificationsarray of objectrequiredShow child attributes
Show array items
classification_typestringrequiredThe type of classification performed
confidencenumber · floatThe confidence score for the top predicted class (only filled for single-label classification)
confidencesarray of number · floatrequiredAn array containing the confidence scores of all the predictions in the same order
Show child attributes
idstringrequiredinputstringThe input text that was classified
labelsobjectrequiredA map containing each label and its confidence score according to the classifier. All the confidence scores add up to 1 for single-label classification. For multi-label classification the label confidences are independent of each other, so they don't have to sum up to 1.
predictionstringThe predicted label for the associated query (only filled for single-label models)
predictionsarray of stringrequiredAn array containing the predicted labels for the associated query (only filled for single-label classification)
Show child attributes
idstringrequiredmetaobjectShow child attributes
api_versionobjectShow child attributes
is_deprecatedbooleanis_experimentalbooleanversionstringrequiredbilled_unitsobjectShow child attributes
classificationsnumberThe number of billed classifications units.
image_tokensnumberThe number of billed image tokens.
imagesnumberThe number of billed images.
input_tokensnumberThe number of billed input tokens.
output_tokensnumberThe number of billed output tokens.
pagesnumberThe number of billed pages parsed.
search_unitsnumberThe number of billed search units.
cached_tokensnumberThe number of prompt tokens that hit the inference cache.
tokensobjectShow child attributes
input_tokensnumberThe number of tokens used as input to the model.
output_tokensnumberThe number of tokens produced by the model.
warningsarray of stringShow child attributes
{
"classifications": [
{
"classification_type": "multi-label",
"confidence": 0,
"confidences": [
0
],
"id": "string",
"input": "string",
"labels": {
"additionalProp1": {
"confidence": 0
}
},
"prediction": "string",
"predictions": [
"string"
]
}
],
"id": "string",
"meta": {
"api_version": {
"is_deprecated": true,
"is_experimental": true,
"version": "string"
},
"billed_units": {
"classifications": 0,
"image_tokens": 0,
"images": 0,
"input_tokens": 0,
"output_tokens": 0,
"pages": 0,
"search_units": 0
},
"cached_tokens": 0,
"tokens": {
"input_tokens": 0,
"output_tokens": 0
},
"warnings": [
"string"
]
}
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}idstringmessagestring{
"id": "string",
"message": "string"
}