Modal
Get an LLM serving on Modal, either as your own vLLM Server or a managed Endpoint, reachable by OpenAI-compatible clients and your gateway, with scaling caps and budgets set and everything stopped when done.
Scope: the modal CLI and Python SDK, vLLM on Modal (@app.server, web functions), Modal Endpoints (Shared and Dedicated), proxy auth tokens, Volumes and Secrets, autoscaling, GPUs, billing controls and teardown.
Out of scope: choosing between providers (cloud-llms, choosing-llm-hosting), gateway routing and keys (llm-gateway, litellm), vLLM engine tuning (vllm), GPU sizing (choosing-hardware), training recipes (fine-tuning-llms, unsloth), image or video models (self-hosted-genmedia).
Work through the steps in order. Load a reference only when a step names it.
Discover first
Read-only. Print variable names, never values.
command -v modal || python3 -m modal --version
env | cut -d= -f1 | grep -E '^(MODAL|HF|OPENAI|LITELLM)_' || echo "no matching env vars"
ls -l ~/.modal.toml ~/.config/modal 2>&1 # permissions only; want 0600 and 0700
modal token info
modal app list
modal endpoint list
modal volume list
modal secret list
modal environment list
Learn which workspace and environment are active and what is already running before proposing anything. If modal is missing or unauthenticated, go to workflow 1.
Decision flow
- Just want a hosted model with no code? Use Shared Endpoints (per token) or a Dedicated Endpoint (GPU time, scale to zero) (
references/endpoints.md). - Custom model, flags, LoRA or weights, or a private deployment? Write a vLLM Server with
@app.server(references/scaling-and-volumes.md). - Need an arbitrary web API or older Function style? Use a web function (
@modal.web_server, ASGI) (references/scaling-and-volumes.md). - Large weights or compile caches? Put them in Volumes (
references/scaling-and-volumes.md). - Latency or cost tuning?
references/scaling-and-volumes.md. - Clients and gateway:
references/litellm-and-clients.md. - Something broke:
references/troubleshooting.md. - Done or pausing:
references/teardown.md.
Rules
- Ask before anything billable.
modal deploy,modal runwith a GPU, Dedicated Endpoints andmin_containerscost money. State GPU, count,max_containers, region and a stop time, then wait for approval. - Secrets stay secret. Tokens come from
0600files, stdin (modal token set --token-id - --token-secret -) or environment variables; never print, commit or paste them. Use Modal Secrets forHF_TOKEN. - Private by default. Servers and Endpoints need proxy auth. Never set
unauthenticated=Trueor--unauthenticated, or skiprequires_proxy_auth=Trueon web functions, without explicit approval. - Pin versions.
modal==<version>,vllm==<version>, the CUDA base image and the Hugging Face model revision. - Budget controls before traffic. Set
max_containers, a shortscaledown_window,min_containers=0, a workspace budget or spend limit, and clientmax_tokens. - Always tear down.
modal app stopandmodal endpoint stopare permanent; Volumes bill until deleted. Finish every session with workflow 8. - Do not hardcode prices or quotas. Read them with
modal billing ratesor the pricing page.
Workflows
1. Account and auth
- Modal account exists with a payment method (human step).
-
python3 -m venv .venv && pip install "modal==1.6.1";modal --version. - Human runs
modal setup, or an agent uses a token from a0600file (seereferences/setup-and-auth.md);modal token infoworks. - Hugging Face token stored as
modal secret create huggingface-secret HF_TOKEN=...for gated models.
2. Deploy a vLLM Server
- Pick model, pinned revision and GPU (
choosing-hardware; Modal suggests starting withL40S). - Write the
@app.serverapp fromreferences/vllm-server.mdwithmax_containers=1, Volumes for caches, and nounauthenticated. - After approval:
modal deploy file.py; note the printed URL. - Create a proxy token (
modal workspace proxy-tokens create) and save it to a0600file. - Poll
/health(expect503until ready), thenGET /v1/modelsand onemax_tokens: 8request.
3. Create a managed Endpoint
-
modal endpoint create --name ... --model ...after approval; inspect withmodal endpoint info. - Use the endpoint name as
model; testGET /v1/modelswith the proxy token.
4. Connect to LiteLLM and clients
- Add a
model_listentry (hosted_vllm/<served-name>oropenai/<endpoint-name>,api_baseending/v1,api_key: os.environ/MODAL_PROXY_TOKEN) fromreferences/litellm-and-clients.md. - Set
num_retriesand a longtimeoutfor503cold starts; add a fallback.
5. Scale
- Tune
target_concurrency,scaledown_window,max_containers,buffer_containers;min_containers=1only when latency needs it. - Use
update_autoscaler()for quick experiments (reverts on the next deploy).
6. Monitor cost
-
modal billing summary,modal billing report(Team or Enterprise), tag apps,modal server stats,modal endpoint stats. - Use
llm-observabilityfor request-level tracing andllm-evalsbefore swapping models.
7. Update
- Bump pinned versions in code,
modal deploy --strategy rolling, smoke test, and usemodal app historyif you need to compare versions. - Rolling back needs a Team or Enterprise plan (
modal app rollback).
8. Tear down
- Follow
references/teardown.md: stop apps and Endpoints, delete Volumes, Secrets and proxy tokens, remove gateway entries. - Verify
modal app list,modal endpoint listandmodal volume listare as expected.
9. Troubleshoot
- Logs first (
modal app logs,modal deploy --stream-logs), thenreferences/troubleshooting.md.
Reference index
| File | Load when |
|---|---|
references/setup-and-auth.md |
Install, tokens, environments, Secrets, plan and billing prerequisites |
references/vllm-server.md |
@app.server vLLM example, deploy, update and roll back, web functions |
references/endpoints.md |
Shared and Dedicated Endpoints, proxy tokens, Claude Code, Codex and OpenCode setup |
references/scaling-and-volumes.md |
Autoscaling, cold starts, GPUs, Volumes, budgets, billing CLI, limits |
references/litellm-and-clients.md |
LiteLLM entries, OpenAI SDK and curl, health checks |
references/teardown.md |
Stopping every billable resource and verifying |
references/troubleshooting.md |
Symptom to cause to fix, with real error strings |
Companion skills
cloud-llms:npx skills add ScaleDockHQ/llm-skills --skill cloud-llms(compare providers, hybrid setups)llm-gateway:npx skills add ScaleDockHQ/llm-skills --skill llm-gateway(one endpoint, keys, budgets)choosing-llm-hosting:npx skills add ScaleDockHQ/llm-skills --skill choosing-llm-hostingself-hosted-llms:npx skills add ScaleDockHQ/llm-skills --skill self-hosted-llmsllm-clients:npx skills add ScaleDockHQ/llm-skills --skill llm-clientsllm-observability:npx skills add ScaleDockHQ/llm-skills --skill llm-observabilityllm-evals:npx skills add ScaleDockHQ/llm-skills --skill llm-evalsfine-tuning-llms:npx skills add ScaleDockHQ/llm-skills --skill fine-tuning-llmsmodel-quantization:npx skills add ScaleDockHQ/llm-skills --skill model-quantizationvllm:npx skills add ScaleDockHQ/llm-skills --skill vllm