Integrate
Agents (MCP)
Connect Claude Code, Codex or Cursor to GPU Router's MCP server and let your agent route and run GPU jobs.
The MCP server exposes the same capabilities as the REST API as 39 tools. Reading is free; three tools start paid compute and need a budget or cap you agree to.
Transport and auth#
| Hosted (HTTP) | Local (stdio) | |
|---|---|---|
| Endpoint | https://gpu-router.com/mcp | gpu-router-mcp command |
| Transport | Streamable HTTP, stateless, JSON responses | stdio |
| Auth | Authorization: Bearer gr_... on every request | GPU_ROUTER_API_KEY environment variable |
| Server | The one you connect to | GPU_ROUTER_URL, default http://localhost:8000 |
The HTTP endpoint accepts a bearer key only, not the browser session; without one it answers 401 UNAUTHENTICATED. Create a key on the Developer access page.
Add the server#
Claude Code#
claude mcp add --transport http gpu-router https://gpu-router.com/mcp --header "Authorization: Bearer <your key>"Start claude and type /mcp: gpu-router shows as connected. If you added it before, run claude mcp remove gpu-router first.
Codex#
codex mcp add gpu-router --url https://gpu-router.com/mcp --bearer-token-env-var GPU_ROUTER_API_KEY
export GPU_ROUTER_API_KEY=<your key>Export the key in the shell that starts codex; Codex sends it as the bearer token.
Cursor#
Add this to .cursor/mcp.json:
{
"mcpServers": {
"gpu-router": {
"url": "https://gpu-router.com/mcp",
"headers": {"Authorization": "Bearer <your key>"}
}
}
}Any client over stdio#
GPU_ROUTER_API_KEY=gr_... GPU_ROUTER_URL=https://gpu-router.com \
uvx --from git+https://github.com/sofiabod/gpu-router.git gpu-router-mcpTry it#
| Prompt | Cost |
|---|---|
list gpu-router samples | Free |
compare GPU prices for H100 | Free |
route the lora sample with a $1 budget | Free, picks a GPU only |
run the lora sample with a $1 budget and wait | Simulated for regular accounts; real jobs run in your Modal account |
Paid and free tools#
Three tools start compute in your Modal account. The server's instructions tell the agent to confirm the budget or cap with you first.
| Tool | What it starts | Guard |
|---|---|---|
run_job | Benchmark runs and the full run | budget_usd caps GPU spend for the whole job |
start_benchmark | 2 or 3 GPUs of capped probe runs | max_cost_usd at least the quoted cap_usd, and confirm=true |
start_run | One full run of a route | None beyond the route's timeout; confirm first |
Every other tool is free. route_job answers which GPU and why without launching anything.
Tool list#
| Group | Tools |
|---|---|
| Samples | list_samples, get_sample_spec |
| Prices | compare_gpus |
| Routes | route_job, get_route, list_routes, get_route_evidence, get_route_prices |
| Benchmarks | quote_benchmark, start_benchmark, get_benchmark |
| Jobs | run_job, wait_for_job, get_job, get_job_event, list_jobs |
| Runs | start_run, get_run, list_runs, cancel_run, get_verification, list_measurements, list_outputs, download_output |
| Connections | list_providers, list_connections, get_connection, connect_provider, recheck_connection, replace_connection, disconnect_provider |
| Webhooks | create_webhook, list_webhooks, get_webhook, update_webhook, delete_webhook, test_webhook, list_webhook_deliveries, retry_webhook_delivery |
API keys cannot be created over MCP; they are minted in the browser only.
Job specs from tools#
route_job and run_job take either image (an immutable container reference) and command (an argv list), or sample=true with a sample_id from list_samples (default lora). Custom jobs default to 2 CPU cores, 8 GB of memory, a 1800 second timeout, min_vram_gb 16 and output_dir /outputs. Env values are secret and never echoed.
Waiting for a job#
run_job returns at once with the job in routing or benchmarking. With wait=true it blocks like wait_for_job.
wait_for_job polls every 5 seconds for at most 50 seconds per call. When the job is done or failed it returns the job's event: the same payload a webhook gets, with stats and agent_prompt. On timeout it returns timed_out: true with the current state; call it again to keep waiting.
{"job_id": "c0c2e4aa09cf4b45a329c4f724df34a8", "state": "benchmarking", "timed_out": true, "agent_prompt": "The job is still benchmarking after 50 s. Call wait_for_job again to keep waiting, or get_job for its steps."}Compact results#
route_job, compare_gpus and get_route_prices return a compact form so they fit in an agent's context:
- Null fields are omitted.
- Price rows keep the cheapest rate per provider and tier.
source_urlandpricing_urlare indexes into a top-levelsourceslist instead of repeated URLs.- Per-row unit notes are dropped; Modal rates are USD per GPU-second as listed, billed per second.
compare_gpus history has one point per day, the day's last value.
Retrying safely#
run_job, start_benchmark, start_run, create_webhook and test_webhook take an idempotency_key. When omitted, a new key is generated per call, so a retried call starts compute again. Pass the same key on a retry to get the first result back. See Idempotency.
Errors#
A tool error is the API envelope in text form: the first line is CODE: message, then one indented line per validation detail, and the last line is the JSON envelope to branch on.
JOB_OVER_BUDGET: Benchmarking T4 and L4 can cost up to USD 0.231600, above half the USD 0.2 budget. Raise the budget or shortlist one GPU.
{"error": {"code": "JOB_OVER_BUDGET", "message": "...", "request_id": "...", "retryable": false, "details": []}}Every code is listed in Errors.
Next steps#
- Quickstart
- Webhooks: the same event, pushed to your agent server.