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

# TEE Verification

> Check that a TEE-backed response came from an attested gateway and a verified upstream.

## Overview

This guide covers TEE models served through RedPill. Each request requires a verified upstream: if none is available, the request fails with a `503` instead of being served. Other TEE routes, such as Tinfoil and Chutes TEE, don't have these receipts.

RedPill signs a receipt for each response. A receipt records what its gateway received, which upstream it verified and what it returned, with a hash of each body, and is signed with a key the gateway publishes. [The attestation report](#fetch-the-attestation-report) ties that key to the gateway's hardware quote.

Confidentiality and logging outcomes are provider-specific, and plaintext may still exist at gateway or proxy layers outside the enclave.

## Model availability

Choose a model from the [live text-model catalog](https://api.nano-gpt.com/api/v1/models).
TEE routes are withheld while enclave measurements await independent verification.
A model with no available verified route is omitted from the ordinary catalog.
With `?detailed=true`, paused entries remain visible with `available: false`,
`status: "paused"`, `unavailable_reason: "tee_verification"` and `providers: []`.
[Exclude these entries when choosing a model](https://docs.nano-gpt.com/api-reference/endpoint/models.md#choosing-callable-models).
Requests blocked by this verification check return `503` with code
`tee_verification_unavailable`.

As of November 19, 2026, this affects `TEE/glm-5.1`, `TEE/glm-5.1-thinking`,
`TEE/glm-5.2`, `TEE/glm-5.2:thinking`, `TEE/kimi-k2.6`, `TEE/kimi-k3`,
`TEE/deepseek-v3.2` and `TEE/qwen3.6-27b`. This is a temporary availability
restriction, not a model retirement. The routing and attestation descriptions below
apply only when the relevant route is available; a dated observation does not
establish current availability.

## Which replies have a receipt

`TEE/` models don't all answer from the same route, so check `X-TEE-Signature-Available` on each reply.

| Models | Configured route when available | Receipt |
| - | - | - |
| `TEE/glm-5.1`, `TEE/glm-5.1-thinking`, `TEE/glm-5.2`, `TEE/glm-5.2:thinking` | Chutes TEE first, then RedPill if Chutes can't serve the request | Only if RedPill answers |
| `TEE/kimi-k2.6` | Chutes TEE, or RedPill if you send `"provider": "redpill"` | Only if RedPill answers |
| `TEE/gemma4-31b`, `TEE/gemma4-31b:thinking` | Chutes TEE first, then Tinfoil | No |
| `TEE/kimi-k3` | Chutes TEE | No |
| `TEE/glm-5.3`, `TEE/gpt-oss-120b` | RedPill first, then Tinfoil if RedPill can't serve the request | Only if RedPill answers |
| `TEE/gemma-4-31b-it` | RedPill, and NanoGPT rewrites its replies | Yes, but it covers RedPill's bytes rather than the ones you receive |
| Other RedPill `TEE/` models | RedPill | Yes |

## Response headers

| Header | Meaning |
| - | - |
| `X-TEE-Signature-Available` | `true` when the response has a signed receipt. |
| `X-Receipt-Id` | The receipt ID (`rcpt-...`). |
| `X-TEE-Signature-ID` | The same receipt ID. |
| `X-TEE-Completion-ID` | Non-streaming only. The response body `id`, which also finds the receipt. |
| `X-Aci-Version`, `X-Aci-Keyset-Digest` | The receipt format version and the digest of the gateway's signing keys. |
| `X-TEE-Provider` | The route that answered: `redpill`, `chutes-tee` or `tinfoil`. Use it to tell, for example, when a Chutes-first model fell back to Tinfoil. Requests that use your own provider keys don't get it. |
| `X-TEE-Verification-Route` | On models with more than one route, a token naming the route that answered. Send it on the receipt and attestation requests. |

Receipts are available on Chat Completions. Non-streaming Responses API replies don't include one, and the Messages API and streaming Responses API reject these models.

## What a receipt can prove

| Check | Streaming | Non-streaming | Non-streaming in exact mode |
| - | - | - | - |
| The receipt was signed by a key the hardware quote binds, using `report=aci` | Yes | Yes | Yes |
| The upstream was verified | Yes | Yes | Yes |
| `response.returned` matches the bytes you received | Yes | No | Yes |
| `request.received` matches the bytes you sent | No | No | No |

NanoGPT adapts each request before forwarding it, so `request.received` covers the request NanoGPT sent.

`response.returned` doesn't match on `TEE/gemma-4-31b-it`, whose replies NanoGPT always rewrites. Exact mode isn't available for that model or for replies Chutes TEE answers.

Streams that match their receipt reach you unchanged, so they end with a usage frame whose `choices` is empty, even if you didn't ask for usage, and `reasoning.exclude` can't hide their reasoning.

## Exact mode for non-streaming replies

NanoGPT normally rebuilds non-streaming replies, so their bytes differ from what the receipt covers. To get the bytes the receipt covers, send this header on `/v1/chat/completions`:

```bash theme={null}
curl -D headers.txt -o body.json "https://api.nano-gpt.com/api/v1/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-NanoGPT-TEE-Response: exact" \
  -d '{"model":"TEE/glm-5.3-flash","messages":[{"role":"user","content":"Hello"}]}'

shasum -a 256 body.json
```

Check that the response has `X-NanoGPT-TEE-Response: exact`, which only exact replies return. Then compare the hash with `response.returned.body_hash` in the receipt named by `X-Receipt-Id`. If `X-TEE-Signature-Available` is `false`, there's no receipt to compare it with.

The body is what RedPill returned, unchanged, even if it's empty or malformed. This means:

* There's no `x_nanogpt_pricing`. Read the cost from `GET /api/v1/usage/requests/{X-Request-ID}`, which can return a `404` for a few seconds after the reply.
* `model` is the upstream model ID. `X-Requested-Model` holds the one you sent.
* NanoGPT doesn't repair tool calls, filter reasoning or retry empty replies.
* NanoGPT doesn't try another provider. If RedPill can't serve the request, you get an error.

No bytes arrive until the whole reply is finished, so allow a long client timeout. `nano-gpt.com` closes a connection that has received no bytes after about 5 and a half minutes, so use streaming for replies that may take longer.

On Chat Completions, exact mode returns a `400` with code `tee_exact_response_unsupported` for models it doesn't cover, requests that would use your own provider keys, Context Memory, web search, `reasoning.exclude`, PII redaction and more than one choice.

The header has no effect on streaming requests, whose replies already match, on x402 payments or on the Responses, Messages and text completions endpoints. Those replies don't include the `X-NanoGPT-TEE-Response` header.

## Fetch a receipt

Use the `X-Receipt-Id` value or the response body `id`, with the API key of the account that made the request. On `TEE/gemma-4-31b-it` streams the body `id` is NanoGPT's own, so use `X-Receipt-Id`. For streams, fetch it after the stream ends, because the receipt covers the whole stream. A stream that's cut off can't be verified: it usually has no receipt, even if its headers named one, and any receipt it does have won't match the bytes you received.

```bash theme={null}
curl "https://api.nano-gpt.com/api/v1/tee/signature/{receiptId}?model=TEE/glm-5.3-flash" \
  -H "Authorization: Bearer $API_KEY"
```

The response contains:

* `receipt`: the signed receipt. Its `event_log` holds the `request.received`, `response.returned` and `upstream.verified` events, and `signature` is signed over the rest of the receipt.
* `text`, `signature`, `signing_address`, `signing_algo`: an older ECDSA signature over `<request hash>:<response hash>`.

RedPill keeps receipts for a limited time. In our tests they were gone within a day, so fetch and store the receipt as soon as the reply ends. `X-Request-ID` values aren't accepted.

If a chat response has an `X-TEE-Verification-Route` header, also send that header on this request and on the attestation request below. Its value expires after one hour. An expired value doesn't block a receipt lookup, but the attestation request returns a `400`.

## Fetch the attestation report

Send `report=aci` and a fresh nonce of 64 lowercase hex characters.

```bash theme={null}
curl "https://api.nano-gpt.com/api/v1/tee/attestation?model=TEE/glm-5.3-flash&report=aci&nonce=$(openssl rand -hex 32)" \
  -H "Authorization: Bearer $API_KEY"
```

This returns RedPill's gateway report unchanged, with no route token needed. `attestation.workload_keyset` holds the gateway's signing keys and `attestation.evidence.quote` its TDX quote. The quote's report data is the SHA-256 of the canonical JSON `{"keyset_digest":"sha256:...","nonce":"<your nonce>","purpose":"aci.report_data.v1"}`, followed by 32 zero bytes. That binds the keys, including the receipt key, to the quote and to your nonce.

Evidence for the upstream is in the session the receipt names in `upstream.verified.session_id`, at `https://api.redpill.ai/v1/aci/sessions/{session_id}`.

`report=aci` returns a `400` for models with no RedPill route, such as `TEE/kimi-k3`, `TEE/gemma4-31b` and the models Tinfoil serves. Without it, `X-TEE-Provider` on the response names the route the report describes:

* `TEE/deepseek-v3.2` and `TEE/qwen3.6-27b` run on Chutes TEE behind RedPill. With a nonce, which must be 64 hex characters, you get Chutes TEE evidence for your nonce from the deployment RedPill uses. A receipt's upstream session names the instance that served the reply in `channel_binding[].key_id`, and that instance appears in the evidence. Without a nonce, you get RedPill's older report, whose Chutes instances carry a nonce RedPill picked.
* On other models RedPill serves, you get RedPill's older report for that model. Its quote covers the signing address and your nonce, not the receipt keys. Its GPU evidence (`nvidia_payload`) isn't covered by the quote's report data, and the report doesn't say whose GPUs they are, so don't treat it as evidence for the upstream that answered. Use the upstream session instead.
* On the models Chutes TEE answers first, you get Chutes TEE evidence carrying your nonce. If `X-TEE-Verification-Route` names another route, you get that route's evidence instead. For RedPill on `TEE/kimi-k2.6`, `TEE/glm-5.1` and `TEE/glm-5.2`, that's also Chutes TEE evidence for your nonce, because RedPill serves them from the same Chutes deployments.
* On models Tinfoil serves, you get Tinfoil's enclave report, and a nonce returns a `400`. Tinfoil ties its attestation to the enclave's TLS key rather than to a nonce, so check freshness with Tinfoil's own client, or use the `private/` models, which do this for you.

Don't pin `workload_keyset_digest`: it changes when the gateway renews its keys.

Chutes TEE evidence covers every instance of the model and can take up to about a minute. If a provider doesn't finish in time, the request returns a `504` with code `tee_attestation_upstream_timeout`. Retry it with a new nonce.

### What the upstream evidence doesn't cover

The upstream session is RedPill's record of how it verified the upstream. The receipt's `route.selected` event names the upstream that served each reply in `target_route_id`. On Nov 12, RedPill sent `TEE/gpt-oss-120b` and `TEE/gemma-4-31b-it` to Tinfoil, `TEE/qwen3.6-35b-a3b` to NEAR AI, and `TEE/deepseek-v3.2` and `TEE/qwen3.6-27b` to Chutes TEE. RedPill can change these routes.

Gaps to know about:

* For models RedPill serves through Tinfoil, 0G or NEAR AI, the session reports GPU attestation as unknown, and for Tinfoil it holds no hardware evidence. For NEAR AI it covers only NEAR's gateway, not the machine running the model.
* For Chutes TEE, each session covers one instance and is several megabytes, and the receipt doesn't name the instance, so you need the session to find it. The end-to-end encryption key in `channel_binding` comes from Chutes' instance list rather than from the TDX quote.

Replies that Chutes TEE or Tinfoil answer directly aren't signed, so `X-TEE-Provider` and the attestation report are what you can check for them.

## Python example

```bash theme={null}
pip install requests cryptography
NANOGPT_API_KEY=YOUR_API_KEY python3 test_tee.py
```

```python theme={null}
#!/usr/bin/env python3
"""Check a NanoGPT TEE response against its signed receipt."""
import hashlib
import json
import os
import secrets
import time

import requests
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey

BASE_URL = "https://api.nano-gpt.com/api"
MODEL = "TEE/glm-5.3-flash"
HEADERS = {"Authorization": f"Bearer {os.environ['NANOGPT_API_KEY']}"}


def digest(data: bytes) -> str:
    return "sha256:" + hashlib.sha256(data).hexdigest()


def canonical(value) -> bytes:
    # JSON Canonicalization Scheme (RFC 8785), which is this simple here
    # because these documents hold only ASCII keys, strings and integers.
    return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode()


def stream_completion() -> tuple[str, bytes]:
    response = requests.post(
        f"{BASE_URL}/v1/chat/completions",
        headers=HEADERS,
        json={
            "model": MODEL,
            "stream": True,
            "messages": [{"role": "user", "content": "Reply with the single word: ok"}],
        },
        stream=True,
        timeout=120,
    )
    response.raise_for_status()
    receipt_id = response.headers["X-Receipt-Id"]
    # The receipt covers the exact bytes of the stream, so don't reassemble them.
    return receipt_id, b"".join(response.iter_content(chunk_size=None))


def fetch_receipt(receipt_id: str) -> dict:
    # A stream's receipt is complete shortly after the stream ends.
    for _ in range(10):
        response = requests.get(
            f"{BASE_URL}/v1/tee/signature/{receipt_id}",
            headers=HEADERS,
            params={"model": MODEL},
            timeout=30,
        )
        if response.status_code == 200:
            return response.json()["receipt"]
        if response.status_code not in (404, 502, 503):
            response.raise_for_status()
        time.sleep(2)
    raise RuntimeError(f"Receipt {receipt_id} not available: {response.text}")


def fetch_workload_keyset(expected_digest: str) -> dict:
    nonce = secrets.token_hex(32)
    report = requests.get(
        f"{BASE_URL}/v1/tee/attestation",
        headers=HEADERS,
        params={"model": MODEL, "report": "aci", "nonce": nonce},
        timeout=30,
    )
    report.raise_for_status()
    attestation = report.json()["attestation"]
    keyset = attestation["workload_keyset"]
    if digest(canonical(keyset)) != expected_digest:
        raise RuntimeError("The keyset does not match the receipt's workload_keyset_digest")

    # A TDX quote holds its 64 bytes of report data at offset 568.
    bound = hashlib.sha256(canonical({
        "keyset_digest": expected_digest,
        "nonce": nonce,
        "purpose": "aci.report_data.v1",
    })).digest() + bytes(32)
    if bytes.fromhex(attestation["evidence"]["quote"])[568:632] != bound:
        raise RuntimeError("The quote does not bind this keyset and nonce")
    return keyset


def verify_signature(receipt: dict, keyset: dict) -> None:
    unsigned = {key: value for key, value in receipt.items() if key != "signature"}
    key = next(k for k in keyset["receipt_signing_keys"] if k["key_id"] == receipt["key_id"])
    public_key = Ed25519PublicKey.from_public_bytes(bytes.fromhex(key["public_key"].removeprefix("0x")))
    # Raises InvalidSignature when the receipt was not signed by the attested key.
    public_key.verify(bytes.fromhex(receipt["signature"].removeprefix("0x")), canonical(unsigned))


def main() -> None:
    receipt_id, body = stream_completion()
    receipt = fetch_receipt(receipt_id)
    events = {event["type"]: event for event in receipt["event_log"]}

    keyset = fetch_workload_keyset(receipt["workload_keyset_digest"])
    verify_signature(receipt, keyset)
    print("Receipt signature verified against a keyset the quote binds")

    if events["response.returned"]["body_hash"] != digest(body):
        raise RuntimeError("The receipt does not cover the bytes this client received")
    print("Response bytes match the receipt")

    upstream = events["upstream.verified"]
    if upstream["result"] != "verified" or upstream["required"] is not True:
        raise RuntimeError(f"The upstream was not verified: {upstream}")
    print(f"Upstream verified, session {upstream['session_id']}")


if __name__ == "__main__":
    main()
```

## What this example doesn't check

The example checks that the quote's report data binds the keyset and your nonce, but it doesn't verify the quote itself. For a full check, also verify the TDX quote's signature, the release measurements and the upstream session evidence. See [RedPill's verification guide](https://docs.redpill.ai/guides/verify-a-response).


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