/v1/classify API endpoint in SGLang, which is compatible with vLLM’s classification API format.
Overview
The classification API allows you to classify text inputs using classification models. This implementation follows the same format as vLLM’s 0.7.0 classification API.API endpoint
Output
Request format
Config
Parameters
The name of the classification model to use.
The text to classify.
User identifier for tracking.
Request ID for tracking.
Request priority.
Response format
Config
Response fields
Unique identifier for the classification request.
Always
"list".Unix timestamp when the request was created.
The model used for classification.
Array of classification results.
Token usage information.
Example usage
- curl
- Python
Command
Supported models
The classification API works with any classification model supported by SGLang, including:- Classification models (multi-class)
- Reward models (single score)
| Model | Type |
|---|---|
LlamaForSequenceClassification | Multi-class classification |
Qwen2ForSequenceClassification | Multi-class classification |
Qwen3ForSequenceClassification | Multi-class classification |
BertForSequenceClassification | Multi-class classification |
Gemma2ForSequenceClassification | Multi-class classification |
The API automatically uses the
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.Error handling
The API returns appropriate HTTP status codes and error messages:| Status code | Meaning |
|---|---|
400 Bad Request | Invalid request format or missing required fields |
500 Internal Server Error | Server-side processing error |
Config
Implementation details
Rust model gateway
Rust model gateway
Handles routing and request/response models in
sgl-model-gateway/src/protocols/spec.rs.Python HTTP server
Python HTTP server
Implements the actual endpoint in
python/sglang/srt/entrypoints/http_server.py.Classification service
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:Compatibility
This implementation is compatible with vLLM’s classification API format,
allowing seamless migration from vLLM to SGLang for classification tasks.
