> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeSafe

> Add and configure TypeSafe decision models in TrueFoundry's AI Gateway.

[TypeSafe](https://typesafe.ai/) provides System One models such as **Jev** that evaluate a piece of content against typed questions and return calibrated answers. TrueFoundry connects to TypeSafe natively through the **AI Gateway**.

TypeSafe models use the **decision** model type. Call them on `POST /v1/systemone` (System One body) or `POST /v1/decisions` (OpenAI Decisions body). The AI Gateway translates between the two, so either route works. Full request and response schemas: [Decisions API](/docs/ai-gateway/decisions).

> [!NOTE]
>
> You can also reach TypeSafe through [Custom Endpoints](/docs/ai-gateway/jev). The native integration below provides model access control and cost tracking, with models addressed as `account-name/model-name`. Prefer this page unless you specifically need a transparent proxy.

> [!NOTE]
>
> Jev is also available through [OpenRouter](/docs/ai-gateway/openrouter#decision-system-one), so you can call it with an OpenRouter API key instead of a TypeSafe one. Auto Routing can use a TypeSafe Jev model as its classifier — see [Auto Routing](/docs/ai-gateway/auto-routing).

### Adding Models

This section explains the steps to add TypeSafe models and configure the required access controls.

**1. Navigate to TypeSafe in AI Gateway**

From the TrueFoundry dashboard, navigate to `AI Gateway` > `Models` and select `TypeSafe`.

**2. Add TypeSafe Account Details**

Click `Add TypeSafe Model Account`. Give a unique name to your TypeSafe account and complete the form:

* **API Key**: your TypeSafe API key. It is sent to TypeSafe as an `Authorization: Bearer` token.
* **Base URL** (optional): defaults to `https://api.typesafe.ai`. Point this at a Cloudflare account (`https://api.cloudflare.com/client/v4/accounts/<account_id>`) to serve System One models through [Cloudflare Workers AI](#cloudflare-workers-ai) instead.

Add collaborators to your account, this will give access to the account to other users/teams. Learn more about access control [here](/docs/ai-gateway/gateway-access-control).

Under advanced settings, you can optionally set a **Discount %** that is applied to the upstream list price for this account.

**3. Add Models**

Click `+ Add Model` and fill the form:

* **Display Name**: the name shown in the TrueFoundry UI, for example `jev`.
* **Model ID**: the TypeSafe model identifier, for example `jev-1.13.0` or `jev-latest`. Pin a versioned ID so confidence thresholds stay stable across releases. On a Cloudflare Workers AI base URL, use the Workers AI model name instead (`typesafe/jev`, `@cf/cloudflare/clef`, or `@cf/cloudflare/clef-flash`).
* **Model Types**: **Decision** (default).
* **Cost** (optional): TypeSafe bills input tokens only, so set the output cost to `0`.

### Inference

Call the model with the TrueFoundry model ID in the format `your-typesafe-account/your-model-display-name`. Send the content in `state` and named questions in `questions`. This example asks a yes/no (`noul`) question about a support message.

Set `GATEWAY_BASE_URL` to your gateway base URL without a trailing slash and `TFY_API_KEY` to your TrueFoundry API key.

```python Python lines theme={"dark"}
import os

import requests

gateway_base_url = os.environ["GATEWAY_BASE_URL"].rstrip("/")
response = requests.post(
    f"{gateway_base_url}/v1/systemone",
    headers={"Authorization": f"Bearer {os.environ['TFY_API_KEY']}"},
    json={
        "model": "my-typesafe-account/jev",  # provider account / model display name
        "state": {"message": "My subscription was charged twice this month."},
        "questions": {
            "billing": {
                "type": "noul",
                "instructions": "Does this message describe a billing issue?",
            }
        },
    },
    timeout=60,
)
response.raise_for_status()
print(response.json()["answers"]["billing"])
```

```bash cURL theme={"dark"}
curl --fail-with-body -X POST "${GATEWAY_BASE_URL}/v1/systemone" \
  -H "Authorization: Bearer ${TFY_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "my-typesafe-account/jev",
    "state": {"message": "My subscription was charged twice this month."},
    "questions": {
      "billing": {
        "type": "noul",
        "instructions": "Does this message describe a billing issue?"
      }
    }
  }'
```

The response contains the versioned `model` that served the request, an `answers` object keyed by your question IDs, and `usage` with `input_tokens` and `output_tokens`. The same questions on `POST /v1/decisions` return OpenAI-shaped answers. See [Decisions API](/docs/ai-gateway/decisions) for both routes, question types, and translation limits.

### Cloudflare Workers AI

TypeSafe Jev and Cloudflare Clef also run on [Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/models/clef/). Point the TypeSafe account **Base URL** at your Cloudflare account and use a Workers AI **Model ID**:

| Field | Value |
| - | - |
| **Base URL** | `https://api.cloudflare.com/client/v4/accounts/<account_id>` |
| **API Key** | a Cloudflare API token that can call Workers AI |
| **Model ID** | `typesafe/jev`, `@cf/cloudflare/clef`, or `@cf/cloudflare/clef-flash` |
| **Model Types** | **Decision** |

The AI Gateway unwraps Cloudflare's `{success, result}` envelope so the response has the same `answers` / `usage` shape as `api.typesafe.ai`. Clef accepts an extra `images` field on the System One body; Jev does not.

You still call `{GATEWAY_BASE_URL}/v1/systemone` (or `/v1/decisions`) with the TrueFoundry FQN. Do not call `/ai/run` yourself.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.