Ray Clusters are in beta. Features and behavior may change before general availability.
What you’ll learn
In this tutorial, you’ll learn how to:- Create a Ray Cluster with the Ray Inference template.
- Configure the model to serve with environment variables.
- Check that the model has loaded and the API is ready.
- Send requests to the LiteLLM API.
- Connect Claude Code and Pi to your cluster.
- Monitor the cluster and the inference metrics.
Requirements
- A Runpod account with enough credits for a multi-node cluster.
- A Hugging Face access token if the model you serve is gated or private.
- To connect a coding agent: Claude Code or Pi installed on your local machine.
How the inference image works
The inference image is published asrunpod/ray-cluster:VERSION-inference-cu1300-torch2130-ubuntu2404. It’s the supported Ray cluster image plus vLLM and LiteLLM. It keeps the same entrypoint, so Ray starts on every node exactly as it does with the base image. Only the services that run after Ray starts are different:
- Worker nodes join the Ray cluster and run nothing else.
- The head node waits until
NUM_NODESnodes have joined Ray, then starts vLLM on127.0.0.1:8000. vLLM sets tensor parallelism to the number of GPUs per node and pipeline parallelism to the number of nodes, so every node must have the same number of GPUs. - LiteLLM starts on the head node once vLLM has loaded the model, and serves the API on port
4000.
Step 1: Create a Ray Cluster
- Open the Instant Clusters page and click Create Cluster.
- Select Ray as the cluster type.
- Name your cluster, set Pod Count to 2, and select 8x H100 SXM as the GPU configuration for each Pod.
- Optionally, select a network volume to share data across nodes.
-
Select the Ray Inference template. It uses the inference image and exposes the API on port
4000alongside the usual Ray Cluster ports. -
Click Edit Template and add the following environment variables:
VLLM_EXTRA_ARGSturns on tool calling, which coding agents need. See inference environment variables for every option, and the inference variant for an overview. - Click Deploy Cluster.
0 is the Ray head node, and the other Pod is a worker.
Step 2: Check that the model is ready
Each Pod starts Ray as soon as its container starts. The worker waits for the head node, then joins. After every node has joined, the head node starts vLLM, and after vLLM has loaded the model, the head node starts LiteLLM. Each node downloads its own copy of the model weights, and loading a large model across nodes can take several minutes.- On the Instant Clusters page, expand your cluster and select the head Pod (rank
0). - Click Connect and check the status of port
4000. It shows as ready once LiteLLM is serving the model.
4000 is ready, nothing listens on it, and requests to it return a 502 response from the Runpod proxy.
Step 3: Send a request
The head node exposes the LiteLLM API through the Runpod proxy on port4000. Every request needs your LITELLM_MASTER_KEY as a bearer token. If you didn’t set LITELLM_MASTER_KEY, the key is the head Pod’s JUPYTER_PASSWORD.
-
List the models served by the cluster:
-
Send a chat completion request:
HEAD_POD_ID with the ID of the head Pod and LITELLM_MASTER_KEY with your API key. The model name is always the value of MODEL_REPO.
Because the API is OpenAI-compatible, you can also use the OpenAI Python client:
401 response. A request with the wrong key receives a 400 response with the message No connected db., because LiteLLM looks up unknown keys in a database that the image doesn’t run. Both requests are refused.
Step 4: Connect a coding agent
LiteLLM serves the model through an Anthropic-compatible Messages API (/v1/messages) as well as the OpenAI-compatible API, so you can use the model on your cluster as the backend for a coding agent running on your local machine.
Coding agents rely on tool calling and long prompts. Make sure VLLM_EXTRA_ARGS turns on tool calling with a parser that matches your model, and that MAX_MODEL_LENGTH leaves room for the agent’s system prompt and your code. For example, to test the connection quickly and cheaply with a small model such as Qwen/Qwen3-0.6B, set:
A model this small is enough to check that the agent can reach your cluster and call tools, but use a larger model for real coding work.
- Claude Code
- Pi
Claude Code sends requests to the Anthropic API by default. Point it at your cluster by setting these environment variables in your local shell:Run
ANTHROPIC_BASE_URLsends Claude Code’s requests to LiteLLM on your head node. Don’t add/v1, because Claude Code adds it.ANTHROPIC_AUTH_TOKENsends your LiteLLM key as a bearer token.ANTHROPIC_MODELandANTHROPIC_DEFAULT_HAIKU_MODELmake Claude Code use your model for both its main work and its background tasks. The cluster serves only one model, so both must be the value ofMODEL_REPO.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1stops Claude Code from sending Anthropic beta headers that other models don’t support.
/status in Claude Code to confirm that it’s using your cluster’s URL and model.To keep these settings for one project instead of your whole shell, add them to the env block of .claude/settings.local.json in the project. See Claude Code settings for details.Step 5: Monitor the cluster
- Select the head Pod and click Connect.
- Click Ray Dashboard. The console signs you in with the head node’s token.
- Open the Cluster tab to see live CPU, GPU, memory, and disk usage for each node.
- Open the Metrics tab to see historical charts for every node.
Step 6: Clean up
When you’re done, return to the Instant Clusters page and delete your cluster. A running cluster continues to incur charges. If you connected a coding agent, unset the Claude Code environment variables, or run/logout litellm in Pi and remove the litellm block from ~/.pi/agent/models.json, so the agent stops sending requests to the deleted cluster.
Inference environment variables
Set these variables in the template you use for the cluster, in addition to the Ray Cluster environment variables.Troubleshooting
Requests return 502
The model is still loading, or vLLM or LiteLLM didn’t start. Check the head Pod’s logs for [ray-inference] messages. If vLLM or LiteLLM exits, the Pod stays up so you can investigate, and the log names the cause. Fix the cause, then restart the head Pod to serve again. Workers don’t rejoin a restarted head node on their own, so restart the worker Pods after the head node is back.
Requests return 401 or 400 with No connected db.
The request has no API key or the wrong one. Send Authorization: Bearer with your LITELLM_MASTER_KEY, or the head Pod’s JUPYTER_PASSWORD if you didn’t set one.
vLLM doesn’t start
The head node’s log says why. Common causes:MODEL_REPOisn’t set.- Neither
LITELLM_MASTER_KEYnorJUPYTER_PASSWORDis set. VLLM_EXTRA_ARGSincludes--api-key. Remove it, because LiteLLM checks the key instead.- The nodes have different numbers of GPUs, so vLLM can’t split the model into even pipeline stages.
The coding agent fails on tool calls
vLLM is running without tool calling, or with a parser that doesn’t match the model. SetVLLM_EXTRA_ARGS to --enable-auto-tool-choice --tool-call-parser PARSER, using the parser that vLLM’s tool calling documentation lists for your model, then restart the head Pod and the worker Pods.
Next steps
- Learn how Ray Clusters work, including the base image for your own Ray jobs.
- Deploy your first Ray Cluster and run a Ray job across every GPU.
- Attach a network volume to share data across nodes.