> ## 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.

This page points a coding harness at Model APIs. To let an agent operate your Baseten workspace and search these docs, see [Connect your coding agent](/agent-setup). For Cline, Roo Code, LangChain, and other tools, see [Integrations](/inference/integrations).

Point [Pi](https://pi.dev), [Droid](https://docs.factory.ai/cli/getting-started/overview), or [OpenCode](https://opencode.ai) at [Model APIs](/inference/model-apis/overview) models such as `zai-org/GLM-5.2` and `moonshotai/Kimi-K3`. Those harnesses call the OpenAI-compatible endpoint with `BASETEN_API_KEY`. You keep the harness and workflow you already have.

[Baseten Switch](/reference/cli/baseten-switch) is a local gateway for Claude Code and Codex CLI.
It routes those harnesses to Model APIs, charts spend against a native-provider estimate, and can send a request back to Anthropic or OpenAI.
The same CLI installs Pi's direct Baseten provider without starting the gateway.
You can run Switch alongside a harness that calls Model APIs directly.

<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

These harnesses call the OpenAI-compatible Model APIs endpoint with `BASETEN_API_KEY`.

Create a [personal API key](/organization/api-keys#create-an-api-key), export it as `BASETEN_API_KEY`, then configure the harness. This is an inference key, not the management key used to [connect your coding agent](/agent-setup). Swap in any [supported model](/inference/model-apis/overview#supported-models).

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

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

<Tabs>
  <Tab title="Pi">
    [Pi](https://pi.dev) has a built-in Baseten provider. Configure it here when you already have `BASETEN_API_KEY` and want to pin the endpoint yourself. To load the visible Model APIs catalog into Pi, use [Baseten Switch](#baseten-switch) instead.

    After you set `BASETEN_API_KEY`, pick a path.

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

        ```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`.

        Auth-file credentials take priority over the environment variable. The `key` field can be a literal or `"$BASETEN_API_KEY"`. Pi's agent directory defaults to `~/.pi/agent`. Set `PI_CODING_AGENT_DIR` to override it.
      </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. Run Pi against the pinned model:

           ```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). To load the catalog into Pi with the Switch CLI, see [Baseten Switch](#baseten-switch).
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="Droid">
    [Droid](https://docs.factory.ai/cli/getting-started/overview) has no built-in Baseten catalog. After you set `BASETEN_API_KEY`, add Model APIs as a custom model.

    **To add Model APIs to Droid**:

    1. Add a Model APIs slug under `customModels` in `~/.factory/settings.json`. Droid substitutes `${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.

    Use `provider: "generic-chat-completion-api"` so Droid sends OpenAI Chat Completions requests.
  </Tab>

  <Tab title="OpenCode">
    [OpenCode](https://opencode.ai/docs/providers) lists Baseten as a provider. After you set `BASETEN_API_KEY`, pick a path.

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

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

        **To store the credential 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 a project `opencode.json` (or `~/.config/opencode/opencode.json`) that sets the Model APIs base URL and a 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, charts Baseten spend against a native-provider estimate, and can send a request back to Anthropic or OpenAI. The same CLI installs Pi's direct Baseten provider without starting the gateway. It requires macOS 13 or newer on Apple Silicon or Intel. For every command, 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 fully qualified formula name adds the tap and installs both Baseten Switch and its [Baseten CLI](/reference/cli/baseten/auth) dependency. Switch authenticates with the current Baseten CLI profile, and both browser OAuth and API-key profiles work.

**To allow Baseten Switch on macOS**:

The beta build uses an ad hoc signature and isn't notarized yet, so you might need to allow the app the first time you open it:

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 can prohibit this override.

## Connect a coding harness

After `baseten-switch up --install`, use the menu bar app to toggle routing, map models, and view spend. Pi uses a direct provider that Switch installs, without starting the gateway. For every Switch command, see the [Baseten Switch CLI](/reference/cli/baseten-switch).

<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 writes a managed `baseten` profile and does not modify `~/.codex/config.toml`.

    **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, approving 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) uses a direct Baseten provider instead of the gateway. To pin the endpoint yourself, 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. Add the provider from the visible 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 operate 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 and compare spend.
  </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">
    Upgrade, uninstall, and configuration fields for Baseten Switch.
  </Card>
</CardGroup>
