/v1/classify API endpoint in SGLang.
Overview
The classification API allows you to classify text inputs using classification models.API Endpoint
Output
Request Format
Config
Parameters
model(string, optional): The name of the classification model to use. Defaults todefaultinput(string, list of strings, or list of token IDs, required): The text to classify, a batch of texts, or the token IDs of one inputuser(string, optional): User identifier for trackingrid(string, optional): Request ID for trackingpriority(integer, optional): Request priority
Response Format
Config
Response Fields
id: Unique identifier for the classification requestobject: Always “list”created: Unix timestamp when the request was createdmodel: The model used for classificationdata: Array of classification resultsindex: Index of the resultlabel: Predicted class label, or one label per input token for token classifiersprobs: Array of probabilities for each class, or one such array per input token for token classifiersnum_classes: Total number of classes
usage: Token usage informationprompt_tokens: Number of input tokenstotal_tokens: Total number of tokenscompletion_tokens: Number of completion tokens (always 0 for classification)prompt_tokens_details: Additional token details (optional)
Multi-label classification
When the model’sconfig.json sets "problem_type": "multi_label_classification", /v1/classify applies an elementwise sigmoid to the logits and returns an independent probability for each class in probs. These probabilities do not need to sum to one. For example, logits [2.0, 2.0] produce approximately [0.880797, 0.880797], so both classes can be positive.
label remains the top-scoring class for response compatibility. To select multiple labels, apply your chosen thresholds to the complete probs vector. Models with another or unspecified problem_type continue to use softmax.
Token classification
When every declared architecture ends inForTokenClassification, the checkpoint is treated as a token classifier. If the served model returns one row of class scores per input token, /v1/classify returns one prediction per token:
probshas shape[num_tokens, num_classes], with one row per input token, including special tokens added by the tokenizer, and one column per label inid2label. Each row uses softmax, or an elementwise sigmoid for multi-label models as described above.labellists the top-scoring class for each token. For multi-label models, apply your thresholds to each row ofprobs.
Config
reflection/Iris-Content-Guard) uses the native BeamForTokenClassification head, which is available in the lmsysorg/sglang:project-iris Docker image and the iris branch until it reaches a release. Send one list of token IDs as input to /v1/classify. Each row in data[0].probs contains 28 independent probabilities, in the checkpoint’s id2label order. The first 14 score the request and the next 14 score the response.
On B300 the default launch uses breakable prefill CUDA graphs. For full prefill graphs, add --cuda-graph-backend-prefill full --attention-backend fa4. Both return only real token rows, even when a graph pads the batch.
The Transformers backend does not load token classification heads, and other token classification checkpoints need --is-embedding at launch. Without it, they are served as generation models and /v1/classify returns 400 Bad Request. In embedding mode, scores without one row per input token and one column per label return 500 Internal Server Error instead of a result for the whole input.
Example Usage
Using curl
Command
Using Python
Example
Supported Models
The classification API works with any classification model supported by SGLang, including:Classification Models (Multi-class)
LlamaForSequenceClassification- Multi-class classificationQwen2ForSequenceClassification- Multi-class classificationQwen3ForSequenceClassification- Multi-class classificationBertForSequenceClassification- Multi-class classificationGemma2ForSequenceClassification- Multi-class classification
id2label mapping from the model’s config.json file to provide meaningful label names instead of generic class names. If id2label is not available, it falls back to LABEL_0, LABEL_1, etc., or Class_0, Class_1 as a last resort.
Token Classification Models
BeamForTokenClassification- Per-token classification, such as the multi-labelreflection/Iris-Content-Guard
Reward Models (Single score)
InternLM2ForRewardModel- Single reward scoreQwen2ForRewardModel- Single reward scoreLlamaForSequenceClassificationWithNormal_Weights- Special reward model
/classify endpoint in SGLang was originally designed for reward models but now supports all non-generative models. Our /v1/classify endpoint provides a standardized interface for classification tasks.
Error Handling
The API returns appropriate HTTP status codes and error messages:400 Bad Request: Invalid request format or missing required fields500 Internal Server Error: Server-side processing error, including model scores that do not match the model’s classification task or itsid2labellabels
Config
Implementation Details
The classification API is implemented using:- Python HTTP Server: Implements the actual endpoint in
python/sglang/srt/entrypoints/http_server.py - Classification Service: Handles the classification logic in
python/sglang/srt/entrypoints/openai/serving_classify.py
Testing
Use the provided test script to verify the implementation:Command
