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

# pi (Beta)

> Use models on Concentrate with the pi coding agent

<Info>
  pi integration is currently in **beta**. Some features may not work, some may only work with certain models.
</Info>

## Why Use Concentrate with pi?

[pi](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent) is an open-source coding agent for the terminal that accepts any OpenAI- or Anthropic-compatible API as a custom provider. By routing pi through Concentrate, you use models from every provider in our [catalog](https://concentrate.ai/models) with one API key, and get centralized visibility and control over your team's usage: spend tracking, budget limits, and everything visible in your Concentrate dashboard in real time.

## What Works

| Feature | Status | Notes |
| - | - | - |
| **Chat and coding** | Supported | All models on Concentrate |
| **Tool calls** | Supported | Including several tool calls at once. Needs a model that supports tool use |
| **Thinking levels** | Supported | Unsupported levels use the closest supported one (see [Tips](#tips)) |
| **Images** | Supported | Pasted images and images read by tools. Needs a model that accepts images |
| **Sessions** | Supported | Resume with `pi -c` or `pi -r` |
| **Compaction** | Supported | `/compact` and automatic compaction |
| **Switching models** | Supported | Switch with `/model` mid-session, including across providers |
| **Cost display** | Supported | The setup script adds each model's price. The dashboard shows billed spend |

## Prerequisites

* A Concentrate AI account with an active API key (starts with `sk-cn`)
* [pi](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent) installed (`npm install -g @mariozechner/pi-coding-agent`)

## Quick Setup

```bash Bash theme={null}
curl -fsSL https://concentrate.ai/scripts/setup-pi.sh | bash
```

The script saves your API key to your shell profile as `CONCENTRATE_PI_API_KEY`, so pi can use a different key from your other tools. If you already have `CONCENTRATE_API_KEY` set, it asks whether to reuse it. It also adds every model on Concentrate to `~/.pi/agent/models.json`, with its price, context window, image support and thinking levels. Other providers in that file are kept. Re-run it to pick up new models and prices.

Then restart your terminal (or `source` your shell profile) and start pi in a project directory:

```bash theme={null}
pi --model concentrate/openai/gpt-6-luna
```

## Manual Setup

If you prefer to configure pi manually or the script doesn't work for your environment:

<Steps>
  <Step title="Set your API key">
    Add the following to your shell profile (`~/.bashrc`, `~/.zshrc`, etc.):

    ```bash theme={null}
    export CONCENTRATE_PI_API_KEY="sk-cn-v1-..."
    ```

    Then reload your shell:

    ```bash theme={null}
    source ~/.bashrc  # or ~/.zshrc
    ```
  </Step>

  <Step title="Add Concentrate to ~/.pi/agent/models.json">
    Create or edit `~/.pi/agent/models.json`. The `apiKey` value is the name of the environment variable, not the key itself:

    ```json theme={null}
    {
      "providers": {
        "concentrate": {
          "baseUrl": "https://api.concentrate.ai/v1",
          "api": "openai-responses",
          "apiKey": "CONCENTRATE_PI_API_KEY",
          "models": [
            { "id": "openai/gpt-6-luna", "name": "GPT-6 Luna", "reasoning": true, "input": ["text", "image"] },
            { "id": "anthropic/claude-haiku-4-5", "name": "Claude Haiku 4.5", "reasoning": true, "input": ["text", "image"] },
            { "id": "ai-studio/gemini-3.8-flash", "name": "Gemini 3.8 Flash", "reasoning": true, "input": ["text", "image"] },
            { "id": "deepseek/deepseek-v4-1-flash", "name": "DeepSeek V4.1 Flash", "reasoning": true }
          ]
        }
      }
    }
    ```

    Add any model from the [supported models](/docs/api-reference/endpoint/supported-models) page using its `provider/model` ID. Set `"reasoning": true` for models that think, `"input": ["text", "image"]` for models that accept images, and `"cost"` (per million tokens) to see prices in pi.
  </Step>

  <Step title="Verify the connection">
    Check that pi sees the models, then start it in a project directory:

    ```bash theme={null}
    pi --list-models concentrate
    cd /path/to/project
    pi --model concentrate/openai/gpt-6-luna
    ```

    Switch models at any time with `/model`.
  </Step>
</Steps>

## Other API formats

We recommend the Responses API (`openai-responses`) shown above. pi can also use our Chat Completions and Messages APIs, which are in beta. Add them as extra providers in the same file:

```json theme={null}
"concentrate-chat": {
  "baseUrl": "https://api.concentrate.ai/v1",
  "api": "openai-completions",
  "apiKey": "CONCENTRATE_PI_API_KEY",
  "models": [{ "id": "openai/gpt-6-luna", "reasoning": true, "input": ["text", "image"] }]
},
"concentrate-messages": {
  "baseUrl": "https://api.concentrate.ai",
  "api": "anthropic-messages",
  "apiKey": "CONCENTRATE_PI_API_KEY",
  "models": [{ "id": "anthropic/claude-haiku-4-5", "reasoning": true, "input": ["text", "image"] }]
}
```

<Warning>
  For `anthropic-messages`, leave `/v1` off the `baseUrl`. pi adds `/v1/messages` itself.
</Warning>

## Tips

* **Thinking levels.** pi's thinking levels map to `reasoning.effort`. The setup script hides levels a model doesn't support. In a manual config, Concentrate uses the [closest supported level](/docs/api-reference/endpoint/request-parameters) instead. For example, Gemini 3.8 Flash can't turn thinking off, so "off" runs at `low`.
* **`xhigh`.** pi sends `xhigh` as `high` by default. The setup script sends `xhigh` for models that support it. In a manual config, add `"thinkingLevelMap": { "xhigh": "xhigh" }` to the model entry.
* **Costs.** pi's cost uses the standard price. Peak-hour, long-context and priority pricing are billed at their own rates, so the Concentrate dashboard is the source of truth for spend.
* **After pressing Esc.** pi drops the interrupted turn from history. If the model keeps going back to the old task, say so explicitly or start a new session.

## Remove Concentrate AI

```bash Bash theme={null}
curl -fsSL https://concentrate.ai/scripts/uninstall-pi.sh | bash
```

This removes the API key from your shell profile and the `concentrate` provider from `models.json`. Other providers are kept.

## Troubleshooting

<AccordionGroup>
  <Accordion title="401 Invalid API key" icon="key">
    1. Check the variable is set: `echo $CONCENTRATE_PI_API_KEY`
    2. Check `apiKey` in `models.json` is the variable's name (`"CONCENTRATE_PI_API_KEY"`), not `$CONCENTRATE_PI_API_KEY`.
  </Accordion>

  <Accordion title="400 Invalid request: model" icon="circle-exclamation">
    The model ID isn't one Concentrate knows. Use the exact `provider/model` ID from the [supported models](/docs/api-reference/endpoint/supported-models) page.
  </Accordion>

  <Accordion title="402 Insufficient funds" icon="wallet">
    Your balance is empty. Add funds on the [billing page](https://concentrate.ai/personal/billing).
  </Accordion>

  <Accordion title="Model doesn't appear in /model" icon="list">
    pi re-reads `models.json` each time you open `/model`. Check the file is valid JSON and the model is under the `concentrate` provider.
  </Accordion>

  <Accordion title="Setup says &#x22;pi could not load the Concentrate models&#x22;" icon="triangle-exclamation">
    The script keeps your other providers in `models.json` as they are. If one of them is invalid, pi skips the whole file, Concentrate included, and the script shows pi's error. Fix or remove the provider it names, then re-run the script. The script saves a backup (`models.json.backup.*`) next to the file each time it runs. If you edit `models.json` by hand later, `pi --list-models` shows the same error.
  </Accordion>
</AccordionGroup>
