How to Deploy an Open-Source LLM with vLLM and an Affordable Cloud GPU
Artificial intelligence development no longer requires purchasing an expensive workstation or committing to a long-term enterprise cloud contract. Developers can rent a GPU when they need one, deploy an open-source large language model, and expose it through an API that works with many existing AI applications.
One practical approach combines a rented GPU from Vast.ai with vLLM, a high-performance inference engine for serving large language models. This setup is useful for prototyping AI applications, testing different models, building private assistants, and learning how production AI infrastructure works.
In this guide, we will walk through the basic architecture, select an appropriate GPU, launch an instance, start a model with vLLM, and access it through an OpenAI-compatible API.
Why deploy your own AI model?
Hosted AI APIs are convenient, but self-hosting an open-source model offers several important advantages.
Greater control
You choose the model, inference software, GPU, operating environment, and generation settings. This makes it easier to optimize the system for a particular application.
Improved data privacy
Prompts can remain within infrastructure you control. This can be valuable when experimenting with internal documents, source code, customer records, or other sensitive data. Self-hosting alone does not guarantee privacy, however. You must still secure the server, network, credentials, logs, and application.
Predictable experimentation
A dedicated instance allows you to run repeated tests without sharing an external API’s rate limits. You can also compare models and quantization formats under consistent conditions.
Access to a broader model ecosystem
Open-source model repositories contain models designed for coding, reasoning, document analysis, chat, vision, and many specialized tasks. Developers can select a model based on licensing, memory requirements, context length, and expected performance.
What is vLLM?
vLLM is an open-source inference and serving engine designed for large language models. It includes features such as continuous batching, prefix caching, quantization support, streaming responses, and efficient management of the model’s attention memory.
One of its most useful features for application developers is its OpenAI-compatible HTTP server. Applications written for common API formats can often be pointed at a vLLM server by changing the base URL and credentials rather than rewriting the entire integration.
Current vLLM documentation lists compatible interfaces for chat completions, text completions, responses, embeddings, transcription, translation, and other model-dependent operations. Not every model supports every endpoint, so always check the selected model’s capabilities. See the official vLLM serving documentation for current compatibility information.
Why use Vast.ai for AI development?
Vast.ai provides a marketplace where developers can rent GPU-equipped machines from different providers. This makes it possible to compare available GPU models, memory, storage, reliability, location, and pricing.
Instances run in Linux Docker containers, and each active instance receives exclusive access to its assigned GPU or GPUs. CPU and system memory allocations generally correspond to the fraction of the host’s GPUs assigned to the instance. The Vast.ai Docker environment documentation explains these resource and container behaviors in more detail.
Marketplace pricing and availability change continuously. Check the complete offer, including storage and bandwidth charges, instead of selecting a machine based only on its advertised hourly GPU price.
Ready to experiment with your own model?
Browse available GPUs on Vast.ai and select an instance that fits your model’s memory requirements.
Understanding GPU memory requirements
GPU memory, or VRAM, is one of the biggest constraints when deploying a language model. The required capacity depends on several factors:
- Model parameter count
- Numeric precision or quantization format
- Context length
- Number of simultaneous requests
- KV-cache usage
- Inference engine configuration
- Additional memory consumed by CUDA and supporting software
A model’s parameter count is not the same as its final VRAM requirement. For example, loading weights in 16-bit precision requires roughly two bytes per parameter before accounting for runtime overhead. Quantized formats can significantly reduce weight memory, but the context window and concurrent workload still consume additional VRAM.
For a first deployment, select a smaller instruction-tuned model that comfortably fits the GPU. Leaving some unused VRAM is preferable to selecting a configuration that barely loads and fails as soon as a longer request arrives.
Step 1: Select a model
Choose a model that:
- Permits your intended use under its license.
- Is supported by your installed version of vLLM.
- Fits the available GPU memory.
- Has an appropriate instruction or chat template.
- Provides the quality and context length your application requires.
For an initial test, a smaller instruct model is usually easier and less expensive to deploy than a large reasoning model. Record the model repository identifier because you will pass it to vLLM when starting the server. In the examples below, replace MODEL_REPOSITORY with the repository identifier for the model you have selected (e.g., facebook/opt-125m for a tiny test).
Step 2: Rent a GPU instance
Create a Vast.ai account and search for an available GPU. The official Vast.ai quick-start guide covers account creation, account funding, and launching the first instance.
When comparing offers, consider:
- Available GPU VRAM
- Number and type of GPUs
- Host reliability
- Download and upload speeds
- CPU and system RAM
- Storage capacity and price
- Geographic location
- Maximum rental duration
- Interruptible versus more stable availability
Use a recent CUDA-compatible PyTorch or vLLM template when possible. Starting from a suitable container image avoids much of the dependency work associated with manually installing CUDA libraries. Do not expose the model API to the public internet without authentication and network restrictions.
Step 3: Connect to the instance
After the instance becomes available, use the SSH command provided by the marketplace. The exact hostname, username, and port will vary:
ssh -p SSH_PORT root@INSTANCE_ADDRESS
Confirm that the GPU is visible:
nvidia-smi
The command should display the assigned GPU, driver information, utilization, and available memory. If it fails, verify that the selected instance and container configuration provide GPU access before installing additional software.
Step 4: Install vLLM
If the selected image does not already include vLLM, create an isolated Python environment and install it:
python3 -m venv /opt/vllm-env
source /opt/vllm-env/bin/activate
python -m pip install --upgrade pip
python -m pip install vllm
GPU frameworks have strict compatibility requirements involving the NVIDIA driver, CUDA runtime, Python version, PyTorch, and compiled packages. A prebuilt vLLM image or template is often more reliable than assembling the complete software stack manually.
Confirm that the command is available:
vllm --help
Step 5: Start the model server
Set an API key rather than running an unauthenticated public endpoint:
export VLLM_API_KEY="replace-with-a-long-random-secret"
Start the server:
vllm serve MODEL_REPOSITORY \
--host 0.0.0.0 \
--port 8000 \
--api-key "$VLLM_API_KEY" \
--gpu-memory-utilization 0.90
The first launch may take time because the model files must be downloaded and loaded into GPU memory. The --gpu-memory-utilization value controls how much GPU memory vLLM is allowed to use. A higher number can provide more room for model execution and the KV cache, but it also increases the possibility of out-of-memory failures. Treat 0.90 as a starting point, not a universal setting.
Step 6: Test the API locally
Before exposing the service through any external port, test it from inside the instance:
curl http://127.0.0.1:8000/v1/models \
-H "Authorization: Bearer $VLLM_API_KEY"
Then send a chat request:
curl http://127.0.0.1:8000/v1/chat/completions \
-H "Authorization: Bearer $VLLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_REPOSITORY",
"messages": [
{
"role": "user",
"content": "Explain continuous batching in plain language."
}
],
"temperature": 0.2,
"max_tokens": 250
}'
The response should contain generated text and usage information. If the model does not have a valid chat template, use a compatible template or select a model designed for chat and instruction-following.
Step 7: Connect a Python application
Install the OpenAI Python package on the client:
python -m pip install openai
Use the vLLM server as the application’s API endpoint:
from openai import OpenAI
client = OpenAI(
base_url="https://YOUR_SECURE_ENDPOINT/v1",
api_key="YOUR_VLLM_API_KEY",
)
response = client.chat.completions.create(
model="MODEL_REPOSITORY",
messages=[
{
"role": "system",
"content": "You are a concise technical assistant.",
},
{
"role": "user",
"content": "Give me three uses for a privately hosted LLM.",
},
],
temperature=0.2,
max_tokens=300,
)
print(response.choices[0].message.content)
Secure the deployment
A functioning endpoint is not automatically a production-ready endpoint. At minimum:
- Require a strong API key.
- Restrict inbound traffic with firewall rules.
- Put the service behind HTTPS.
- Avoid directly exposing port 8000.
- Apply request-size and rate limits.
- Store secrets outside source code.
- Review logs for sensitive prompt content.
- Keep the container and Python packages updated.
- Run the service with the least privilege possible.
- Stop or destroy unused instances.
- Back up only the data that must persist.
Reduce inference costs
GPU cost is affected by more than the hourly rental price. An inefficient configuration can waste money even when the underlying GPU is inexpensive.
Right-size the model
Use the smallest model that consistently meets the application’s quality requirements. A larger model may produce better results, but it also requires more memory and can reduce throughput.
Consider quantization
Supported quantization formats can reduce memory consumption and sometimes improve serving efficiency. They may also affect output quality or require particular hardware and kernels. vLLM currently supports multiple quantization approaches, but compatibility varies by model and GPU.
Common deployment problems
CUDA out-of-memory error
The model or runtime workload exceeds available VRAM. Try a smaller or quantized model, reduce the maximum context length, decrease concurrency, or rent a GPU with more memory.
Model download is unauthorized
The repository may be gated. Accept its license terms and provide the appropriate access token through a secure environment variable.
From experiment to production
The deployment described here is an excellent starting point for development, internal tools, and proof-of-concept systems. A production AI service requires additional engineering including health checks, automatic restarts, and load testing. Comparing GPUs can help you find the right balance of performance and cost for production.
Vast.ai also offers serverless endpoint controls, including minimum and maximum workers and scaling-related settings. Consult the Vast.ai serverless scaling documentation before selecting values.
Final thoughts
Self-hosting an open-source LLM provides a hands-on way to understand the infrastructure behind modern AI applications. By combining an appropriately sized GPU with vLLM, developers can create a private, OpenAI-compatible model endpoint without purchasing dedicated hardware.
Start building your AI development environment:
Compare available cloud GPUs on Vast.ai and select a machine that meets your model’s VRAM requirements.