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

# Pi

> Connect Pi to Prem API with the Prem provider extension.

Pi is a coding agent that runs in your terminal. The `@premai/api-extension-pi` extension registers a `prem-api` provider inside Pi. By default the extension encrypts model requests inside the Pi process, so you do not need the local Confidential Proxy.

> [!WARNING]
>
> Use extension **0.1.1** or later.

> [tab] Confidential API
>
> Use the extension's built-in encryption for sensitive model traffic. [Go to the confidential setup](#confidential-api-setup).

> [tab] ZDR
>
> Use Zero Data Retention (ZDR) for OpenAI-compatible inference with non-sensitive data. [Go to the ZDR setup](#zdr-setup).

## Confidential API setup

This path encrypts your prompts end-to-end before they leave your machine.

## How the connection works

```mermaid theme={"system"}
flowchart TB
    subgraph Local["Your machine: plaintext is available"]
        P["Pi"] --> X["Prem extension<br/>attest and encrypt"]
        T["Terminal, files, and tools"] <--> P
    end

    X -->|"Encrypt before network egress"| G["Prem API Gateway<br/>ciphertext and metadata"]
    G -->|"Encrypted request"| E["Prem confidential runtime<br/>decrypt, infer, encrypt"]
    E -.->|"Encrypted response"| X
```

## Before you start

You need:

* **Pi**, installed. See the [Pi install guide](https://pi.dev/docs/latest/install).
* **A Prem API key.** See [API Keys](https://docs.prem.io/api-keys.md).
* **A 32-byte client KEK** encoded as 64 hexadecimal characters. Optional, see below.
* **An enabled confidential chat model.** See [Models & Pricing](https://docs.prem.io/models-and-pricing.md).

## 1. Set your environment

Set these variables in the terminal that runs Pi:

```bash theme={"system"}
export PREM_API_KEY="your-prem-api-key"
export CLIENT_KEK="your-64-character-hex-kek"
```

Generate the KEK once if you do not have one:

```bash theme={"system"}
openssl rand -hex 32
```

The extension reads `PREM_API_KEY` at request time. Without `CLIENT_KEK`, the extension generates an ephemeral KEK for each Pi process. Leave `ENABLE_ZDR` unset for this path.

## 2. Install the extension

Add the extension and default provider to your Pi `settings.json`:

```json theme={"system"}
{
  "packages": ["npm:@premai/api-extension-pi@0.1.1"],
  "defaultProvider": "prem-api"
}
```

The extension registers the provider when Pi starts. It refreshes the available chat models from `GET /rvenc/models` and sends encrypted requests to `/rvenc/chat/completions`. Pi picks a model from the returned catalog; set `defaultModel` if you want a specific enabled model, for example `qwen38-27b`.

## 3. Start Pi

Start Pi from the folder containing your settings:

```bash theme={"system"}
pi
```

Send a short prompt using an enabled confidential model.

## Configuration

| Variable | Required | Value |
| - | - | - |
| `PREM_API_KEY` | Yes | Your Prem API key |
| `CLIENT_KEK` | No | 64 hexadecimal characters. Defaults to an ephemeral key per process |
| `PROXY_URL` | No | Defaults to `https://gateway.prem.io` |
| `ENCLAVE_URL` | No | Defaults to `https://conf-engine.prem.io` |
| `ENABLE_ZDR` | No | Leave unset. `true` switches to the [ZDR setup](#zdr-setup) |

## Security boundary

| Component | Plaintext access | Notes |
| - | - | - |
| Pi and the extension | Yes, locally | Read prompts, workspace data and tool results. The extension encrypts model requests and decrypts responses |
| Prem API Gateway | No content access | Receives ciphertext and operational metadata |
| Prem confidential runtime | Yes, inside the protected runtime | Runs inference and encrypts the result |
| Shell, plugins and MCP servers | Depends on the integration | Remain outside the Prem confidential boundary |

Tool calls run on your machine or on the external services you configure. Model-path confidentiality does not protect local files, shell commands, plugins or MCP servers. Review the data each tool receives and the permissions it has.

## Usage and concurrency

All API keys in your organization share one Confidential [concurrency limit](https://docs.prem.io/tiers.md#concurrent-requests). Additional Pi sessions or API keys do not increase it. Above it, new requests return `429`. See [Agents & Automation](https://docs.prem.io/agents.md).

## Troubleshooting

> [accordion] Pi does not show the prem-api provider
>
> Check that the extension is in the `packages` array. Restart Pi after changing `settings.json`.

> [accordion] The provider returns 401
>
> Check that `PREM_API_KEY` is correct and active in the terminal running Pi.

> [accordion] The API says model not found
>
> Select a model returned by the catalog for your mode: `GET /rvenc/models` for the Confidential API, `GET /openai/models` for ZDR. Restart Pi after changing `ENABLE_ZDR`.

> [accordion] Attestation fails
>
> Check that `settings.json` pins extension `0.1.1` or later, then restart Pi. If you set `PROXY_URL` or `ENCLAVE_URL`, confirm they point at the current Prem endpoints.

> [accordion] Pi warns that CLIENT\_KEK is not set
>
> The extension generated an ephemeral KEK for this process. Export `CLIENT_KEK` before starting Pi to reuse one key across runs.

> [accordion] The API returns 429
>
> Wait for active requests to finish and reduce parallel work. Follow `Retry-After` when present. See [Rate limits](https://docs.prem.io/rate-limits.md).

## ZDR setup

> [!WARNING]
>
> ZDR is not confidential. It does not provide client-side encryption or attestation. Use this path only for non-sensitive prompts, workspace context and tool results.

Pi uses [ZDR](https://docs.prem.io/zdr/overview.md) through the same extension and `settings.json`.

## 1. Set your environment

```bash theme={"system"}
export PREM_API_KEY="your-prem-api-key"
export ENABLE_ZDR=true
```

ZDR requires no client KEK. Do not reuse the client KEK for ZDR.

## 2. Start Pi

```bash theme={"system"}
pi
```

With `ENABLE_ZDR=true`, the extension refreshes chat models from `GET /openai/models` and sends requests to `/openai/chat/completions`. Send a short prompt using an enabled ZDR model. See [Models & Pricing](https://docs.prem.io/models-and-pricing.md).

ZDR requests travel over HTTPS, but the Prem API Gateway and inference partner process plaintext content. Retention is governed by the ZDR agreement and operational controls. See [ZDR security boundary](https://docs.prem.io/zdr/security-boundary.md).

All API keys share the organization's ZDR request, concurrency and token allowances. See [Tiers](https://docs.prem.io/tiers.md).

## Related

> [card] [Attestation](https://docs.prem.io/attestation.md)
>
> Understand what the client verifies before it encrypts a request.

> [card] [ZDR overview](https://docs.prem.io/zdr/overview.md)
>
> Understand the ZDR API and its data-handling contract.

> [card] [Models & Pricing](https://docs.prem.io/models-and-pricing.md)
>
> Find models available to your API key and inference mode.

> [card] [Agents & Automation](https://docs.prem.io/agents.md)
>
> Review concurrency, retries, reasoning and error controls.


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