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 will help you understand how to leverage this compatibility to integrate your models seamlessly with existing OpenAI-based applications.

Endpoint structure

When using the OpenAI-compatible API with Runpod, your requests will be directed to this base URL pattern:
Replace [ENDPOINT_ID] with your Serverless endpoint ID.

Supported APIs

The vLLM worker implements 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/text completion API requests to identify which model should process your request.

Initilization

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

Send a request

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 example

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

Response format

The API returns responses in this JSON format:

Streaming request example

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 example

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

Response format

The API returns responses in this JSON format:

Streaming request example

List available models

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

Response format

Request input parameters

vLLM workers support various parameters to control generation behavior. You can find a complete list of OpenAI request input parameters on the GitHub README.

Environment variables

Use these environment variables to customize the OpenAI compatibility: You can find a complete list of vLLM environment variables on the GitHub README.

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:
  1. Token counting: Token counts may differ slightly from OpenAI models.
  2. Streaming format: The exact chunking of streaming responses may vary.
  3. Error format: Error responses follow a similar but not identical format.
  4. Rate limits: Rate limits follow Runpod’s endpoint policies rather than OpenAI’s.
The vLLM worker also currently has a few limitations:
  • The function and tool 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.

Troubleshooting

Common issues and their solutions:

Next steps