Skip to main content

Request inspector

Before you ship a new prompt, a new key or a new policy, you often want to know what the gateway will do with a request. Which model will it really use, can this key call it, which guardrails will look at the prompt and would any of them block it, is the answer already cached, how much will it cost and is there enough budget left. The request inspector answers all of that in one call. You send the same body you would send to /v1/chat/completions, with the same key, to POST /v1/inspect, and the gateway walks the request through routing, policies and limits without calling the model.

Nothing changes because of an inspect call. No model is called, no spend is recorded and no budget or rate limit counter moves. Guardrails do run on a copy of the messages, in audit mode, so their verdicts are real. A guardrail that calls an outside service is billed by that service as usual.

Because guardrails really run, the inspector has its own safety limits. Each key may make 60 inspect calls per minute, or fewer when the key's own rpm_limit is lower, and the gateway answers 429 once that allowance is used up. Operators change the allowance with the INSPECT_RPM_LIMIT environment variable. Guardrails run and the response cache is checked only when the key may call the model, so a key cannot use the inspector to probe models it has no access to. Only proxy admins see the guardrail detail text, other keys see the verdict alone. Every inspect call writes an invoked row to the audit log with the resolved model and each guardrail's verdict, never the messages.

A real-world scenario​

A developer on the support team gets blocked responses from a new prompt and does not know why. They send the same body to /v1/inspect with their key. The answer says the model resolves to gpt-4o through the team's routing preset, that one of the two deployments is in cooldown, that the pii-strict policy matched through the team and that its ssn-block guardrail returns block with the message ssn found. It also shows that the key has 1.20 USD of budget left and the request would cost about 0.003 USD. The developer removes the ticket number that looked like a social security number and the request goes through.

Inspect a request​

  1. Take the body of the request you want to check and send it to /v1/inspect with the same key.

    curl -X POST http://localhost:4000/v1/inspect \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Summarise ticket 4411"}], "max_tokens": 300}'
  2. Read the answer.

    {
    "model": "gpt-4o",
    "resolved_model": "gpt-4o",
    "preset": null,
    "model_allowed": true,
    "model_denied_reason": null,
    "candidates": [{"deployment_id": "d-1", "model": "openai/gpt-4o", "skip_reason": null}],
    "policies": [{"policy_name": "pii", "matched_via": "team:support", "mode": "audit"}],
    "guardrails": [{"guardrail_name": "pii-mask", "mode": "audit", "verdict": "redact", "duration_seconds": 0.004, "detail": null}],
    "cache_status": "miss",
    "estimated_prompt_tokens": 12,
    "estimated_completion_tokens": 300,
    "estimated_cost_usd": 0.00303,
    "budgets": [{"scope": "key", "spend": 4.2, "max_budget": 10.0, "remaining": 5.8, "would_exceed": false}],
    "limits": [{"scope": "key", "rpm_limit": 60, "tpm_limit": null, "max_parallel_requests": 4}]
    }
  3. To check only which policies match, without running any guardrail, open /ui/policies, click the Policy Simulator tab, keep Policy match selected, set the team, key, model and tags and click Simulate.

Dry run as another key from the Admin UI​

Proxy admins can run the same dry run for any key without holding that key. This is the quickest way to answer "why is this team's request being blocked" from the Admin UI. The dry run uses that key's model access, team, policies, budgets and limits, so the answer is what the key's real request would get. When the key is blocked, its team is blocked or the key has expired, the real request would be refused with 401, so the dry run says model_allowed is false, gives the reason in model_denied_reason and runs no guardrail.

  1. Sign in to the Admin UI as a proxy admin and open /ui/policies.
  2. Click the Policy Simulator tab, then click Full dry run.
  3. In Key, type part of the key alias or the full key id and pick the key from the list. The list asks the gateway for matching keys as you type, so every key can be found, however many keys the gateway holds.
  4. In Model, pick or type the model the request names.
  5. Type the User message, and optionally a System message, the Tags (optional) the request carries and the Max output tokens (optional) to price.
  6. Click Run dry run. The page shows the resolved model, whether the key may call it, each deployment with its skip reason, the matching policies, each guardrail's verdict, latency and message, the cache status, the estimated tokens and cost, and the key, team and user budgets and limits.

The same dry run through the API names the key in inspect_as_key, with the key id (the hashed token shown as Key ID on the Virtual Keys page).

curl -X POST http://localhost:4000/v1/inspect \
-H "Authorization: Bearer $SPANWAY_ADMIN_KEY" -H "Content-Type: application/json" \
-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Summarise ticket 4411"}], "inspect_as_key": "88dc28d0f030c55ed4ab77ed8faf098196cb1c05df778539800c9f1243fe6b4b"}'

Only proxy admins may set inspect_as_key. Any other caller, including an admin viewer, gets 403 and nothing runs. A dry run on behalf of a key counts against the admin's own 60 dry runs per minute, not the key's, so an admin cannot get around the allowance by switching keys and cannot use up a key's own dry runs. Each one writes an invoked row to the audit log by the admin, with the key id and key alias in inspect_as_key and inspect_as_key_alias, the resolved model and the guardrail verdicts, never the messages.

MethodPathSummary
POST/v1/inspectDry run a chat completion

What each field means​

FieldMeaning
resolved_modelThe model group the router would serve after a routing preset and model aliases.
presetThe preset that applies, with its version, the model it picked, the fallbacks it adds and the request fields it fills in.
model_allowed, model_denied_reasonWhether the key may call the resolved model, and the reason when it may not.
candidatesThe deployments of the model group. skip_reason is cooldown for a deployment in cooldown and context_window when the prompt is longer than its max_input_tokens. These use the same names as the routing decision headers.
policiesThe policies that match, why, and whether they enforce or only audit.
guardrailsEach guardrail that would run: the policies' guardrails, the guardrails named on the key, team or project, the ones the body names in guardrails or metadata.guardrails, and the default_on ones. verdict is pass, block, redact, error, or not_run for a guardrail that only runs on responses, is not loaded, when the body has no messages or when the key may not call the model. detail is the guardrail's message when it blocked or failed, shown to proxy admins only.
cache_statusdisabled when no response cache is set up, not_used when the cache would skip this request or the key may not call the model, otherwise hit or miss for the same model and messages.
estimated_prompt_tokens, estimated_completion_tokens, estimated_cost_usdTokens counted on the messages, max_tokens as the output, and the price from the same calculation as /cost/estimate. The cost is null for a model without a price.
budgetsThe key, team and user budgets with spend, the budget and what is left, and would_exceed when the estimate is more than what is left.
limitsThe key, team and user rate limits the request counts against.

Expected result​

The call answers 200 with the fields above for any valid key, and for a proxy admin dry running as another key it answers with that key's view. The key's spend, the team's spend and every rate limit counter are the same after the call as before it. Inspecting a model the key may not call still answers 200, with model_allowed: false and the reason, so you can see why the real request would be refused. In that case no guardrail runs and the cache is not checked.

Errors​

StatusErrorMeaningCauseFix
400'@preset/<name>' is not a valid preset referenceThe model names a preset in the wrong format.Preset names use lowercase letters, digits, ., _ and -.Fix the preset name.
400Preset '<name>' lists no models, so the request must name one, for example 'my-model@preset/<name>'The preset has no models of its own and the request named only the preset.A request body with model: "@preset/<name>" for a preset that leaves the model to the caller.Put a model in front of the preset, for example my-model@preset/<name>, or add models to the preset.
401Authentication ErrorThe key is missing or not valid.No Authorization header, or a revoked key.Send a valid virtual key.
403Only proxy admins may inspect as another keyThe body names inspect_as_key and the caller is not a proxy admin.A team admin, internal user, admin viewer or a plain virtual key set the field.Leave inspect_as_key out to dry run as your own key, or ask a proxy admin.
404No routing preset '@preset/<name>'The preset does not exist for this team.A typo, or the preset belongs to another team.Check the presets on the Routing Presets page.
404No key with id '<id>'inspect_as_key names no key.A typo, a deleted key, or a key alias sent instead of the key id.Copy the Key ID from the Virtual Keys page, or pick the key in Full dry run.
500Inspecting as another key needs a connected databaseThe gateway has no database, so it cannot look the key up.DATABASE_URL is not set.Connect a database, see virtual keys.
500Routing presets need a connected databaseThe request names a routing preset and the gateway has no database to read presets from.DATABASE_URL is not set.Connect a database, or send the request without a preset.
422Validation errorThe body is not a request.model is missing, or max_tokens is below 1.Send a chat completion body.
429Inspect rate limit reached: <n> dry runs per minute for this keyThe key used up its inspect allowance for this minute.More than INSPECT_RPM_LIMIT (60 by default) inspect calls in a minute, or more than the key's rpm_limit when that is lower.Wait for the time in the retry-after header, or raise INSPECT_RPM_LIMIT. A dry run as another key counts against the admin who sent it.

Logs​

LevelLineMeaningAction
DEBUGInspect: <model> resolved to <group> for a dry runAn inspect call ran.None. Set SPANWAY_LOG=DEBUG to see it.
ERRORPipeline: unexpected error from guardrail '<name>': ...A guardrail failed during the dry run. Its verdict is error.Check the guardrail's provider and credentials.

Audit mode and policy replay explains how guardrails run without blocking. Routing decision headers explains skip reasons on real requests. Guardrail policies explains how policies match, and routing presets explains the preset field.