For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
  • Cohere API
    • About
    • Teams and Roles
    • Errors
    • Migrating From API v1 to API v2
    • Using the OpenAI SDK
  • Endpoints
  • Deprecated
      • POSTClassify
LogoLogodocs
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
Deprecatedv1/classify

Classify

Deprecated
POST
https://api.cohere.com/v1/classify
POST
/v1/classify
1import cohere
2from cohere import ClassifyExample
3
4co = cohere.Client()
5examples = [
6 ClassifyExample(text="Dermatologists don't like her!", label="Spam"),
7 ClassifyExample(text="'Hello, open to this?'", label="Spam"),
8 ClassifyExample(text="I need help please wire me $1000 right now", label="Spam"),
9 ClassifyExample(text="Nice to know you ;)", label="Spam"),
10 ClassifyExample(text="Please help me?", label="Spam"),
11 ClassifyExample(text="Your parcel will be delivered today", label="Not spam"),
12 ClassifyExample(
13 text="Review changes to our Terms and Conditions", label="Not spam"
14 ),
15 ClassifyExample(text="Weekly sync notes", label="Not spam"),
16 ClassifyExample(text="'Re: Follow up from today's meeting'", label="Not spam"),
17 ClassifyExample(text="Pre-read for tomorrow", label="Not spam"),
18]
19inputs = [
20 "Confirm your email address",
21 "hey i need u to send some $",
22]
23response = co.classify(
24 model="<YOUR-FINE-TUNED-MODEL-ID>",
25 inputs=inputs,
26 examples=examples,
27)
28print(response)
1{
2 "id": "86886163-b3f3-4e36-8554-60eca7696216",
3 "classifications": [
4 {
5 "id": "842d12fe-934b-4b71-82c2-c581eca00718",
6 "predictions": [
7 "Not spam"
8 ],
9 "confidences": [
10 0.5661598
11 ],
12 "labels": {
13 "Not spam": {
14 "confidence": 0.5661598
15 },
16 "Spam": {
17 "confidence": 0.43384025
18 }
19 },
20 "classification_type": "single-label",
21 "input": "Confirm your email address",
22 "prediction": "Not spam",
23 "confidence": 0.5661598
24 },
25 {
26 "id": "e1a39b3e-1ecd-41d2-be75-90ed726f7b9e",
27 "predictions": [
28 "Spam"
29 ],
30 "confidences": [
31 0.9909811
32 ],
33 "labels": {
34 "Not spam": {
35 "confidence": 0.009018883
36 },
37 "Spam": {
38 "confidence": 0.9909811
39 }
40 },
41 "classification_type": "single-label",
42 "input": "hey i need u to send some $",
43 "prediction": "Spam",
44 "confidence": 0.9909811
45 }
46 ],
47 "meta": {
48 "api_version": {
49 "version": "1"
50 },
51 "billed_units": {
52 "classifications": 2
53 }
54 }
55}
This 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](https://docs.cohere.com/docs/classify-fine-tuning) trained on classification examples don't require the `examples` parameter to be passed in explicitly.
Was this page helpful?
Previous

List Connectors

Next
Built with

This 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.

Authentication

AuthorizationBearer

Bearer authentication of the form Bearer <token>, where token is your auth token.

Headers

X-Client-NamestringOptional
The name of the project that is making the request.

Request

inputslist of stringsRequired
A 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.
exampleslist of objectsOptional
An 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.
modelstringOptional
ID of a [Fine-tuned](https://docs.cohere.com/v2/docs/classify-starting-the-training) Classify model
truncateenumOptionalDefaults to END
One 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.
Allowed values:
presetstringOptionalDeprecated
The 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.

Response headers

X-API-Warningstring
Warning description for incorrect usage of the API

Response

OK
idstring
classificationslist of objects
metaobject

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
404
Not Found Error
422
Unprocessable Entity Error
429
Too Many Requests Error
498
Invalid Token Error
499
Client Closed Request Error
500
Internal Server Error
501
Not Implemented Error
503
Service Unavailable Error
504
Gateway Timeout Error

A 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. 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.

An 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 trained on classification examples don’t require the examples parameter to be passed in explicitly.

ID of a Fine-tuned Classify model

One 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.

The ID of a custom playground preset. You can create presets in the playground. If you use a preset, all other parameters become optional, and any included parameters will override the preset’s parameters.