# Trace: Adding AI Models via User's Gateway Service

Agent: pi | Model: GPT-5.3 Codex | Project: C:\Users\Daniel.Esuga\PI\pi-mono\packages\pi-ui-server

---

## User

/model

## Assistant

## Assistant

If you want to change the active model, tell me which one to use (or I can list common options and recommend one by task).

If you meant the **`/model` slash command behavior in pi**, say that and I’ll check the exact implementation/docs in this repo.

## User

I want to add models via my ai gateway.
https://ai-gateway.isw.la/ 
Key: [REDACTED]

## Assistant

## Assistant

## Assistant

## Assistant

## Assistant

## Assistant

## Assistant

## Assistant

## Assistant

## Assistant

Perfect — you can do this **without code changes** using `~/.pi/agent/models.json`.

Also: since you pasted a live key here, rotate it after setup.

### 1) Set your gateway key as env var
Use any variable name, e.g.:

```bash
export ISW_AI_GATEWAY_KEY=[REDACTED]
```

### 2) Add provider + models in `~/.pi/agent/models.json`

```json
{
  "providers": {
    "isw-gateway": {
      "baseUrl": "https://ai-gateway.isw.la/v1",
      "api": "openai-completions",
      "apiKey": "ISW_AI_GATEWAY_KEY",
      "models": [
        {
          "id": "openai/gpt-4o-mini",
          "name": "GPT-4o Mini (ISW Gateway)",
          "reasoning": false,
          "input": ["text", "image"],
          "contextWindow": 128000,
          "maxTokens": 16384,
          "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 }
        }
      ]
    }
  }
}
```

Use the exact model IDs your gateway exposes (from its `/v1/models`).

### 3) Select it
- In pi CLI: `/model` → provider `isw-gateway`
- In pi-ui app: open model selector (same underlying registry)

If your gateway is not fully OpenAI-compatible, add `compat` flags per model (e.g. `maxTokensField`, `supportsUsageInStreaming`).

If you want, I can generate a ready-to-paste `models.json` from the exact model IDs you have.

## User

Go ahead. I want to use gpt-5-codex

## Assistant

## Assistant

## Assistant

## Assistant

Done.

Created:

- `C:\Users\Daniel.Esuga\.pi\agent\models.json`

with provider `isw-gateway` and model `gpt-5-codex`.

Next, set your key env var (PowerShell):

```powershell
$env:ISW_AI_GATEWAY_KEY=[REDACTED]
```

Persist it for future terminals:

```powershell
setx ISW_AI_GATEWAY_KEY "sk-..."
```

Then restart pi (or pi-ui server) and run `/model`, select:

- Provider: `isw-gateway`
- Model: `GPT-5 Codex (ISW Gateway)`
