Skip to main content
Runpod’s vLLM workers implement OpenAI API compatibility, allowing you to use familiar OpenAI client libraries with your deployed models. This guide explains how to leverage this compatibility to integrate your models with existing OpenAI-based applications.

Endpoint structure

You can make OpenAI-compatible API requests to your vLLM workers by sending requests to this base URL pattern:

Supported APIs

vLLM workers support these core OpenAI API endpoints:

Model naming

The MODEL_NAME environment variable is essential for all OpenAI-compatible API requests. This variable corresponds to either:
  1. The Hugging Face model you’ve deployed (e.g., mistralai/Mistral-7B-Instruct-v0.2).
  2. A custom name if you’ve set OPENAI_SERVED_MODEL_NAME_OVERRIDE as an environment variable.
This model name is used in chat and text completion API requests to identify which model should process your request.

Initialize the OpenAI client

Before you can send API requests, set up an OpenAI client with your Runpod API key and endpoint URL:

Send requests

You can use Runpod’s OpenAI-compatible API to send requests to your Runpod endpoint, enabling you to use the same client libraries and code that you use with OpenAI’s services. You only need to change the base URL to point to your Runpod endpoint.
You can also send requests using Runpod’s native API, which provides additional flexibility and control.

Chat completions

The /chat/completions endpoint is designed for instruction-tuned LLMs that follow a chat format.

Non-streaming request

Here’s how you can make a basic chat completion request:

Response format

The API returns responses in this JSON format:

Streaming request

Streaming allows you to receive the model’s output incrementally as it’s generated, rather than waiting for the complete response. This real-time delivery enhances responsiveness, making it ideal for interactive applications like chatbots or for monitoring the progress of lengthy generation tasks.

Text completions

The /completions endpoint is designed for base LLMs and text completion tasks.

Non-streaming request

Here’s how you can make a text completion request:

Response format

The API returns responses in this JSON format:

Streaming request

List available models

The /models endpoint allows you to get a list of available models on your endpoint:

Response format

Chat completion parameters

Here are all available parameters for the /chat/completions endpoint:

Additional vLLM parameters

vLLM supports additional parameters beyond the standard OpenAI API:

Text completion parameters

Here are all available parameters for the /completions endpoint: Text completions support the same additional vLLM parameters as chat completions (see the Additional vLLM parameters section above).

Environment variables

Use these environment variables to customize the OpenAI compatibility: For a complete list of all vLLM environment variables, see the vLLM environment variables reference.

Client libraries

The OpenAI-compatible API works with standard OpenAI client libraries:

Python

JavaScript

Implementation differences

While the vLLM worker aims for high compatibility, there are some differences from OpenAI’s implementation: Token counting may differ slightly from OpenAI models due to different tokenizers. Streaming format follows OpenAI’s Server-Sent Events (SSE) format, but the exact chunking of streaming responses may vary. Error responses follow a similar but not identical format to OpenAI’s error responses. Rate limits follow Runpod’s endpoint policies rather than OpenAI’s rate limiting structure.

Current limitations

The vLLM worker has a few limitations:
  • Function and tool calling APIs are not currently supported.
  • Some OpenAI-specific features like moderation endpoints are not available.
  • Vision models and multimodal capabilities depend on the underlying model support in vLLM.

Troubleshooting

Common issues and their solutions:

Next steps