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

# Use Pi Coding Agent with A2Agent for Lower-Cost Models

> Pi Coding Agent connects to a custom OpenAI-compatible endpoint. Point it at A2Agent to run DeepSeek, Kimi, GLM and Qwen through one key.

Pi is a terminal coding agent that supports custom providers and models through `~/.pi/agent/models.json`. By adding A2Agent as a custom provider, you can route Pi requests through A2Agent and select supported models from the `/model` picker.

## Prerequisites

* Pi Coding Agent installed — follow the [official Pi Quickstart](https://pi.dev/docs/latest/quickstart) if needed
* An A2Agent API key — sign up at [a2agent.me/register](https://a2agent.me/register) to get one
* A model ID listed on the [A2Agent Models page](https://a2agent.me/models)

## Setup

<Steps>
  <Step title="Create a custom A2Agent provider">
    Create or edit Pi’s custom model configuration:

    ```bash theme={null}
    mkdir -p ~/.pi/agent
    nano ~/.pi/agent/models.json
    ```

    Add the following configuration:

    ```bash theme={null}
    {
      "providers": {
        "a2agent": {
          "baseUrl": "https://api.a2agent.me/v1",
          "apiKey": "A2AGENT_API_KEY",
          "api": "openai-completions",
          "models": [
            {
              "id": "deepseek-v4-flash",
              "name": "DeepSeek V4 Flash"
            },
            {
              "id": "qwen3.7-plus",
              "name": "Qwen 3.7 Plus"
            }
          ]
        }
      }
    }
    ```

    The model IDs above are examples. Model availability may change, so use the exact IDs currently shown on the [A2Agent Models page](https://a2agent.me/models).
  </Step>

  <Step title="Start Pi and select an A2Agent model">
    Start Pi from the project directory:

    ```bash theme={null}
    cd /path/to/your/project
    pi
    ```

    Inside Pi, enter:

    ```bash theme={null}
    /model
    ```

    Select:

    ```bash theme={null}
    a2agent
    ```

    Then choose one of the configured models.
  </Step>

  <Step title="Run a test request">
    Start a new Pi session and enter:

    ```bash theme={null}
    Summarize this repository and explain how to run its checks.
    ```

    You can also run a one-shot request:

    ```bash theme={null}
    pi --provider a2agent --model deepseek-v4-pro -p "Say hello and identify the active model."
    ```

    If Pi returns a response, the A2Agent connection is working.
  </Step>
</Steps>

## Troubleshooting

<AccordionGroup>
  <Accordion title="401 Unauthorized">
    Pi reached A2Agent, but the API key was rejected.

    * Confirm that the key is a valid A2Agent API key.

    * Check for accidental spaces or line breaks.

    * Do not use an OpenAI API key for A2Agent.
  </Accordion>

  <Accordion title="Connection refused or could not resolve host">
    Confirm that the base URL is exactly:

    ```text theme={null}
    https://api.a2agent.me/v1
    ```

    Make sure:

    * the `/v1` path is included;
    * the URL does not contain `/models` or `/chat/completions`;
    * `api` is set to `openai-completions`; and
  </Accordion>

  <Accordion title="No A2Agent models appear in `/model`">
    Check the following:

    * the file is located at `~/.pi/agent/models.json`;

    * the JSON syntax is valid;

    * the Provider name is `a2agent`;

    * at least one model is listed under `models`;

    * the model ID is spelled correctly.Check the current list at:[A2Agent Models page](https://a2agent.me/models)
  </Accordion>

  <Accordion title="Model not found">
    The model ID must match an available A2Agent model exactly.

    Check the current list at:[A2Agent Models page](https://a2agent.me/models)

    Model IDs and availability may change over time. Update the `models` array with the current ID, then reopen `/model`.
  </Accordion>
</AccordionGroup>
