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

# Coding agents

> Call Model APIs from Pi, Droid, or OpenCode. Connect Claude Code, Codex CLI, or Pi with Baseten Switch.

Connect [Pi](https://pi.dev), [Droid](https://docs.factory.ai/cli/getting-started/overview), or [OpenCode](https://opencode.ai) directly to the OpenAI-compatible [Model APIs](/inference/model-apis/overview) endpoint with `BASETEN_API_KEY`.

Use [Baseten Switch](/reference/cli/baseten-switch) to route requests from Claude Code or Codex CLI to Model APIs. Switch can also install Pi's direct Baseten provider, compare Baseten spend with estimated costs from Anthropic or OpenAI, and route requests back to those providers.

For Cline, Roo Code, LangChain, and other tools, see [Integrations](/inference/integrations). To let an agent manage your Baseten workspace and search these docs, see [Connect your coding agent](/agent-setup).

<CardGroup cols={3}>
  <Card title="Agent harnesses" icon="terminal" href="#agent-harnesses">
    Call Model APIs from Pi, Droid, or OpenCode with `BASETEN_API_KEY`.
  </Card>

  <Card title="Baseten Switch" icon="shuffle" href="#baseten-switch">
    Connect Claude Code, Codex CLI, or Pi.
  </Card>

  <Card title="Switch CLI" icon="book" href="/reference/cli/baseten-switch">
    Command reference for `baseten-switch`.
  </Card>
</CardGroup>

## Agent harnesses

Pi, Droid, and OpenCode call the OpenAI-compatible Model APIs endpoint with `BASETEN_API_KEY`.

Baseten pins requests with a recognized session ID to the same replica to increase KV cache hits. Claude Code, Codex, and OpenCode include recognized session IDs, so they require no additional configuration. To pin requests from other harnesses, see [Cached input tokens](/inference/model-apis/pricing-and-limits#cached-input-tokens).

Create a [personal API key](/organization/api-keys#create-an-api-key), export it as `BASETEN_API_KEY`, then configure your harness. This inference key is separate from the management key used to [connect your coding agent](/agent-setup). The examples use `zai-org/GLM-5.2`; replace it with any [supported model](/inference/model-apis/overview#supported-models).

<CodeGroup>
  ```bash macOS/Linux theme={"system"}
  export BASETEN_API_KEY="paste-your-api-key-here"
  ```

  ```powershell Windows theme={"system"}
  setx BASETEN_API_KEY "paste-your-api-key-here"
  ```
</CodeGroup>

<Tabs>
  <Tab title="Pi">
    [Pi](https://pi.dev) includes a Baseten provider. Use the built-in provider for the shortest setup, or add a configuration file to pin the endpoint and model list. To load the Model APIs catalog into Pi, use [Baseten Switch](#baseten-switch).

    After you set `BASETEN_API_KEY`, choose a setup method.

    <Tabs>
      <Tab title="Built-in provider">
        **To call Model APIs from Pi**:

        ```sh theme={"system"}
        pi --provider baseten --model zai-org/GLM-5.2
        ```

        **To store the key in `auth.json`**:

        1. Run `/login` in Pi.
        2. Select Baseten and store the key in `~/.pi/agent/auth.json`.

        Credentials in `auth.json` take priority over the environment variable. Set `key` to an API key or `"$BASETEN_API_KEY"`. Pi stores agent configuration in `~/.pi/agent` by default. Set `PI_CODING_AGENT_DIR` to use another directory.
      </Tab>

      <Tab title="Config file">
        **To pin the Model APIs endpoint**:

        1. Add the Baseten provider to `~/.pi/agent/models.json`. This merges into Pi's built-in Baseten provider:

           ```json ~/.pi/agent/models.json theme={"system"}
           {
             "providers": {
               "baseten": {
                 "baseUrl": "https://inference.baseten.co/v1",
                 "api": "openai-completions",
                 "apiKey": "$BASETEN_API_KEY",
                 "models": [
                   { "id": "zai-org/GLM-5.2" }
                 ]
               }
             }
           }
           ```

        2. Call the pinned model from Pi:

           ```sh theme={"system"}
           pi --provider baseten --model zai-org/GLM-5.2
           ```

        Add more slugs under `models` from the [supported list](/inference/model-apis/overview#supported-models).
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="Droid">
    [Droid](https://docs.factory.ai/cli/getting-started/overview) does not include a Baseten model catalog. After you set `BASETEN_API_KEY`, configure a Model APIs model.

    **To configure Model APIs in Droid**:

    1. Add a supported model slug under `customModels` in `~/.factory/settings.json`. Droid reads `${BASETEN_API_KEY}` from the environment:

       ```json ~/.factory/settings.json theme={"system"}
       {
         "customModels": [
           {
             "model": "zai-org/GLM-5.2",
             "displayName": "GLM 5.2 [Baseten]",
             "baseUrl": "https://inference.baseten.co/v1",
             "apiKey": "${BASETEN_API_KEY}",
             "provider": "generic-chat-completion-api"
           }
         ]
       }
       ```

    2. Run `/model` in Droid.

    3. Select the custom model.

    Set `provider` to `generic-chat-completion-api` so Droid sends OpenAI Chat Completions requests.
  </Tab>

  <Tab title="OpenCode">
    [OpenCode](https://opencode.ai/docs/providers) includes a Baseten provider. After you set `BASETEN_API_KEY`, choose a setup method.

    <Tabs>
      <Tab title="Built-in provider">
        **To connect OpenCode to Baseten**:

        1. Start OpenCode.
        2. Run `/connect`.
        3. Search for Baseten and paste the API key if OpenCode prompts for it.
        4. Run `/models` and select a slug.

        **To sign in from the CLI**:

        ```sh theme={"system"}
        opencode auth login
        ```

        OpenCode also loads provider keys from the environment and from a project `.env` file on startup.
      </Tab>

      <Tab title="Config file">
        **To pin the Model APIs endpoint**:

        1. Add `opencode.json` to your project, or add it at `~/.config/opencode/opencode.json` for a global configuration. Set the Model APIs base URL and model list:

           ```json opencode.json theme={"system"}
           {
             "$schema": "https://opencode.ai/config.json",
             "provider": {
               "baseten": {
                 "npm": "@ai-sdk/openai-compatible",
                 "name": "Baseten",
                 "options": {
                   "baseURL": "https://inference.baseten.co/v1",
                   "apiKey": "{env:BASETEN_API_KEY}"
                 },
                 "models": {
                   "zai-org/GLM-5.2": {
                     "name": "GLM 5.2"
                   }
                 }
               }
             }
           }
           ```

        2. Run `/models` and select a slug.

        `@ai-sdk/openai-compatible` sends Chat Completions requests. Add more slugs under `models` from the [supported list](/inference/model-apis/overview#supported-models).
      </Tab>
    </Tabs>
  </Tab>
</Tabs>

## Baseten Switch

<Note>
  Baseten Switch is in beta. Its interfaces, configuration, and behavior can change between releases.
</Note>

Baseten Switch is a local gateway for Claude Code and Codex CLI. It maps model families to [Model APIs](/inference/model-apis/overview) slugs, compares Baseten spend with estimated costs from Anthropic or OpenAI, and can route requests back to those providers. The same CLI installs Pi's direct Baseten provider without starting the gateway. Switch requires macOS 13 or newer on Apple Silicon or Intel. For a complete command reference, see the [Baseten Switch CLI](/reference/cli/baseten-switch).

**To install Baseten Switch**:

1. Trust Baseten's Homebrew tap:

   ```sh theme={"system"}
   brew trust basetenlabs/baseten
   ```

2. Install the formula:

   ```sh theme={"system"}
   brew install basetenlabs/baseten/baseten-switch
   ```

The formula installs Baseten Switch and its [Baseten CLI](/reference/cli/baseten/auth) dependency. Switch uses the current Baseten CLI profile and supports both browser OAuth and API-key authentication.

**To allow Baseten Switch on macOS**:

macOS might block the beta build because it uses an ad hoc signature and is not notarized. To allow the app:

1. Try to open Baseten Switch once so macOS registers the block.
2. Open **System Settings > Privacy & Security** and scroll to **Security**.
3. Select **Open Anyway** next to Baseten Switch.

A managed Mac might prevent this override.

## Connect a coding harness

`baseten-switch up --install` starts the gateway and installs the menu bar app. Use the app to toggle routing, map models, and view spend. Pi uses a direct provider installed by Switch and does not send requests through the gateway.

<Tabs>
  <Tab title="Claude Code">
    **To route Claude Code through Baseten**:

    1. Initialize the configuration and sign in when prompted:

       ```sh theme={"system"}
       baseten-switch setup
       ```

    2. Start the gateway and install the menu bar app:

       ```sh theme={"system"}
       baseten-switch up --install
       ```

    3. Point new Claude Code sessions at the gateway:

       ```sh theme={"system"}
       baseten-switch claude on
       ```

    4. Restart Claude Code.

    5. Verify the request path:

       ```sh theme={"system"}
       baseten-switch doctor --probe
       ```
  </Tab>

  <Tab title="Codex CLI">
    Install [Codex CLI](https://github.com/openai/codex) first. Switch creates a managed `baseten` profile and leaves `~/.codex/config.toml` unchanged.

    **To route Codex CLI through Baseten**:

    1. Initialize the configuration and sign in when prompted:

       ```sh theme={"system"}
       baseten-switch setup
       ```

    2. Start the gateway and install the menu bar app:

       ```sh theme={"system"}
       baseten-switch up --install
       ```

    3. Create the managed profile. Approve the prompt if one appears:

       ```sh theme={"system"}
       baseten-switch codex on
       ```

    4. Set the Baseten model that serves the profile:

       ```sh theme={"system"}
       baseten-switch codex route zai-org/GLM-5.2
       ```

    5. Start Codex with the profile:

       ```sh theme={"system"}
       codex --profile baseten
       ```

    Don't use Codex's `-m` flag to pick the Baseten model. It overrides the profile and breaks routing.
  </Tab>

  <Tab title="Pi">
    [Pi](https://pi.dev) connects directly to Model APIs instead of using the gateway. To configure the endpoint manually, see [Agent harnesses](#agent-harnesses).

    **To install Pi's Baseten provider**:

    1. Export a [personal API key](/organization/api-keys#create-an-api-key) as `BASETEN_API_KEY`.

    2. Install the provider with the Model APIs catalog:

       ```sh theme={"system"}
       baseten-switch pi install
       ```

    3. Run Pi against a Model APIs slug:

       ```sh theme={"system"}
       pi --provider baseten --model zai-org/GLM-5.2
       ```
  </Tab>
</Tabs>

## Next steps

<CardGroup cols={2}>
  <Card title="Connect your coding agent" icon="bot" href="/agent-setup">
    Install the Baseten skill and MCP servers so your agent can manage your Baseten workspace and search these docs.
  </Card>

  <Card title="Integrations" icon="link" href="/inference/integrations">
    Call Model APIs from Cline, Roo Code, LangChain, and other tools.
  </Card>

  <Card title="Model APIs pricing" icon="tag" href="https://www.baseten.co/pricing">
    See rates for hosted models.
  </Card>

  <Card title="Baseten Switch CLI" icon="book" href="/reference/cli/baseten-switch">
    Commands for routing, models, spend, and health.
  </Card>

  <Card title="Baseten Switch README" icon="github" href="https://github.com/basetenlabs/baseten-switch">
    Find upgrade, uninstall, and configuration instructions.
  </Card>
</CardGroup>
