Skip to main content

Overview

This guide walks you through the entire flow of getting started with SGLang:
  1. Install SGLang
  2. Launch an inference server
  3. Send requests using cURL, OpenAI Python client, Python requests, or the native SGLang API
By the end, you’ll have a working SGLang server responding to your prompts.

Prerequisites

  • Python: 3.10 or higher
  • GPU: NVIDIA GPU with CUDA support (sm80 and above, e.g., A10, A100, L4, L40S, H100)
  • OS: Linux (recommended)
For other platforms, see the dedicated guides for AMD GPUs, Intel Xeon CPUs, Google TPUs, NVIDIA Jetson, Ascend NPUs, and Intel XPU.

Installation

If you encounter OSError: CUDA_HOME environment variable is not set, set it with:

Launch a Server

Start the SGLang server with a model. Here we use qwen/qwen2.5-0.5b-instruct as a lightweight example:
Wait until you see The server is fired up and ready to roll! in the terminal output.
Once the server is running, API documentation is available at:
  • Swagger UI: http://localhost:30000/docs
  • ReDoc: http://localhost:30000/redoc
  • OpenAPI Spec: http://localhost:30000/openapi.json
The server automatically applies the chat template from the Hugging Face tokenizer. You can override it with --chat-template when launching.

Send Requests

SGLang is fully OpenAI API-compatible, so you can use the same tools and libraries you already know.

Using cURL

Using OpenAI Python Client

Install the OpenAI Python library if you haven’t:
Then send a request:
Example

Streaming

Example

Using Python Requests

Example

Using the Native /generate API

SGLang also provides a native /generate endpoint for more flexibility.
Example

Streaming with /generate

Example

Offline Batch Inference (No Server)

SGLang also supports offline batch inference using the Engine class directly — no HTTP server required.
Example

Common Troubleshooting

Set the CUDA_HOME environment variable to your CUDA install root:
Switch to alternative backends by adding these flags when launching the server: