Skip to main content
This guide covers different methods for sending requests to vLLM workers on Runpod, including code examples and best practices for Runpod’s native API format. Use this guide to effectively integrate LLMs into your applications while maintaining control over performance and cost.

Requirements

Many of the code samples below will require you to input your endpoint ID. You can find your endpoint ID on the endpoint details page:

Runpod API requests

Runpod’s native API provides additional flexibility and control over your requests. These requests follow Runpod’s standard endpoint operations format.

Python Example

Replace [RUNPOD_API_KEY] with your Runpod API key.

cURL Example

Run the following command in your local terminal, replacing [RUNPOD_API_KEY] with your Runpod API key and [RUNPOD_ENDPOINT_ID] with your vLLM endpoint ID.

Request formats

vLLM workers accept two primary input formats:

Messages format (for chat models)

Prompt format (for text completion)

Request input parameters

vLLM workers support various parameters to control generation behavior. Here are some commonly used parameters: You can find a complete list of request input parameters on the GitHub README.

Error handling

When working with vLLM workers, it’s crucial to implement proper error handling to address potential issues such as network timeouts, rate limiting, worker initialization delays, and model loading errors. Here is an example error handling implementation:

Best practices

Here are some best practices to keep in mind when creating your requests:
  1. Use appropriate timeouts: Set timeouts based on your model size and complexity.
  2. Implement retry logic: Add exponential backoff for failed requests.
  3. Optimize batch size: Adjust request frequency based on model inference speed.
  4. Monitor response times: Track performance to identify optimization opportunities.
  5. Use streaming for long responses: Improve user experience for lengthy content generation.
  6. Cache frequent requests: Reduce redundant API calls for common queries.
  7. Handle rate limits: Implement queuing for high-volume applications.

Next steps