# Pi

> Route Pi through sference: one command, a sference provider in ~/.pi/agent/models.json, and a model picker scoped to the sference catalog.

Source: https://sference.com/docs/sference-code/pi

[Pi](https://github.com/badlogic/pi-mono) reads providers from `~/.pi/agent/models.json`. The sference launcher writes a `sference` provider block there and starts Pi with it selected.

## Launch

```bash
curl -fsSL https://raw.githubusercontent.com/s-ference/sference/main/install.sh | sh
sference auth login --api-key 'sk_...'
sference launch pi
```

Pi starts with sference as the active provider and the full catalog in the model picker.

## What the launcher writes

A `sference` provider in `~/.pi/agent/models.json`, using Pi's `openai-responses` API against sference's `/v1/responses`:

```json
{
  "providers": {
    "sference": {
      "api": "openai-responses",
      "baseUrl": "https://api.sference.com/v1",
      "apiKey": "sk_...",
      "models": [
        { "id": "zai-org/GLM-5.3", "name": "GLM 5.3", "reasoning": true, "input": ["text"] },
        { "id": "moonshotai/Kimi-K3", "name": "Kimi K3", "reasoning": true, "input": ["text", "image"] }
      ]
    }
  }
}
```

The model list is fetched live from `GET /v1/models`, so the picker mirrors your catalog exactly — including vision capability and context window per model.

## Options

| Flag | Effect |
| --- | --- |
| `--model zai-org/GLM-5.3` | Select the active model (default: `zai-org/GLM-5.2` or `SFERENCE_MODEL`) |
| `--base-url <url>` | Point at a different API base (default `https://api.sference.com`) |
| `--dry-run` | Print the provider config and command without launching |
| `sference launch pi -- /path/to/project` | Forward arguments after `--` to Pi |

The launcher scopes Pi's picker to sference models by default (`--models sference/**`), so other providers you have configured stay hidden until you widen it. `**` is required because sference model ids contain a slash.

## Choosing a model

| Model | Input / output per 1M | Use for |
| --- | --- | --- |
| `zai-org/GLM-5.3-Flash` | 0.20 / 0.60 | Fast edits, formatting, small refactors |
| `zai-org/GLM-5.3` | 1.20 / 4.20 | General coding turns |
| `deepseek-ai/DeepSeek-V4.1-Flash` | 0.50 / 1.50 | Long-context work at low cost |
| `moonshotai/Kimi-K3` | 3.00 / 15.00 | Hard planning turns |

## Cost control

- **Prefix caching.** Pi resends the system prompt and tool definitions every turn. Keep them stable and first so they bill at the cached rate — see [Prompt caching](https://sference.com/docs/guides/prompt-caching).
- **Cheap default, strong escalation.** Set `GLM-5.3-Flash` as the active model and switch to `Kimi-K3` for planning turns.
- **Per-engineer attribution.** Each engineer's key shows up separately in `GET /control/v1/usage/by-key`. See [Usage & analytics](https://sference.com/docs/usage).

> **It is a compatibility layer**
>
> Open models plan differently and call tools less reliably than frontier closed models on long repo work. Validate on your own repository before committing a workflow. See [SferenceCode](https://sference.com/docs/sference-code) for what to expect.

- [SferenceCode](https://sference.com/docs/sference-code): All harnesses, model choices, and what to expect.
- [Claude Code](https://sference.com/docs/sference-code/claude-code): Proxy mode with hybrid routing.
- [opencode](https://sference.com/docs/sference-code/opencode): sference provider in opencode.json.
