---
title: "Pi Coding Agent SDK (gateway)"
description: "Route the model calls of agents built on the Pi Coding Agent SDK through the Respan gateway."
---

Build agents on [pi](https://pi.dev)'s harness and send their model calls through the Respan gateway. Add Respan as a provider in a `models.json`, then pick its models when you create a session.

<Accordion title="Trace pi agents">
This page covers gateway routing. To also capture runs, tool calls, and threads from inside the agent, see [Pi Coding Agent SDK (tracing)](/docs/integrations/pi-sdk).
</Accordion>

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the Pi Coding Agent SDK.
Follow https://www.respan.ai/docs/integrations/gateway/pi-sdk.md
```

## Setup

<Steps>
<Step title="Install the SDK">

```bash
npm install @earendil-works/pi-coding-agent
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

</Step>

<Step title="Add Respan as a provider">

Create `models.json` in your project:

```json
{
  "providers": {
    "respan": {
      "baseUrl": "https://gateway.respan.ai",
      "api": "openai-completions",
      "apiKey": "$RESPAN_API_KEY",
      "models": [{ "id": "gpt-5.5" }, { "id": "claude-sonnet-4-5" }]
    }
  }
}
```

</Step>

<Step title="Create a session">

```typescript
import { createAgentSession, ModelRuntime } from "@earendil-works/pi-coding-agent";

const modelRuntime = await ModelRuntime.create({ modelsPath: "./models.json" });
const model = modelRuntime.getModel("respan", "gpt-5.5");

const { session } = await createAgentSession({ model, modelRuntime });
await session.prompt("Say hello in one sentence.");
session.dispose();
```

</Step>
</Steps>

## Switch models

Add any ID from [respan.ai/models](https://www.respan.ai/models) to `models`, then select it with `modelRuntime.getModel("respan", "<id>")`.
