Typesafe pass-through
The /typesafe route forwards Typesafe API paths, such as /v1/systemone, to Typesafe unchanged. System One is Typesafe's native format for asking typed questions about a piece of text and getting back answers with probabilities. The gateway holds the Typesafe key, checks the virtual key and records each call with its cost. To send the same decisions in the OpenAI Decisions format and switch between decision providers freely, use the unified decisions endpoint instead.
A real-world scenario
A trust and safety team already has tooling that speaks System One and wants to keep it while moving the Typesafe key out of the tool. They point the tool at /typesafe/v1/systemone on the gateway with a virtual key. Nothing changes in the tool, and every decision call is attributed and budgeted.
Before you start
The gateway needs a Typesafe credential. It looks first for a model_list deployment of provider TypeSafe with use_in_pass_through: true, then for the environment below.
| Variable | Purpose |
|---|---|
TYPESAFE_API_KEY | The Typesafe key the gateway sends upstream. |
TYPESAFE_API_BASE | Optional. Changes the upstream address from https://api.typesafe.ai. |
Steps
-
Give the gateway the credential. Open
/ui/models-and-endpoints, on the Add Model tab pick TypeSafe under Provider, pick a model, open Advanced Settings, turn on Use in pass through routes and click Add Model. Or setTYPESAFE_API_KEYand restart the gateway. -
Issue a virtual key on
/ui/api-keyswith + Create New Key, then Create Key. -
Send a System One request through the gateway.
curl -X POST http://localhost:4000/typesafe/v1/systemone \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"model": "jev-latest", "state": "Customer wrote: I was charged twice for order #4411 and want one charge refunded today.", "questions": {"is_refund_request": {"type": "noul", "instructions": "Is the customer asking for a refund?"}, "urgency": {"type": "choice", "instructions": "How urgent is this?", "criteria": {"low": "can wait a week", "high": "needs action today"}}}}' -
Open
/ui/logsand click the newest row to see the request, the key and its cost.
Expected result
Typesafe's own response, with its status code and headers.
{
"model": "jev-latest",
"answers": {
"is_refund_request": {"type": "noul", "value": true, "probability": 0.97},
"urgency": {"type": "choice", "value": "high", "probabilities": {"low": 0.08, "high": 0.92}}
}
}
The spend log row carries the key, team and user and the cost from the bundled Typesafe prices.
Errors
| Status | Message | What it means and how to fix it |
|---|---|---|
401 | Authentication Error, Invalid proxy server token passed | The virtual key is missing, wrong, expired or blocked. |
403 | Key/team denied access to passthrough route /typesafe/... | The key or team lists the route in denied_passthrough_routes. The message goes on with Matched <pattern> in denied_passthrough_routes, naming the pattern to remove from the key or team. |
401 from Typesafe | Typesafe's authentication error | The gateway forwarded the call with no usable Typesafe key. Add a deployment with Use in pass through routes on, or set TYPESAFE_API_KEY. |
| Any other | Typesafe's own error body | Typesafe refused the request. The message is returned unchanged. |
Related
Pass-through endpoints lists every built-in route. The Decisions API is the unified alternative that accepts both formats and any decision model. Laya pass-through and Bespoke Nimble pass-through cover self-hosted System One servers.