Skip to main content

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.

VariablePurpose
TYPESAFE_API_KEYThe Typesafe key the gateway sends upstream.
TYPESAFE_API_BASEOptional. Changes the upstream address from https://api.typesafe.ai.

Steps​

  1. 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 set TYPESAFE_API_KEY and restart the gateway.

  2. Issue a virtual key on /ui/api-keys with + Create New Key, then Create Key.

  3. 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"}}}}'
  4. Open /ui/logs and 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​

StatusMessageWhat it means and how to fix it
401Authentication Error, Invalid proxy server token passedThe virtual key is missing, wrong, expired or blocked.
403Key/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 TypesafeTypesafe's authentication errorThe 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 otherTypesafe's own error bodyTypesafe refused the request. The message is returned unchanged.

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.