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

# Zed custom model setup: API Key and Base URL

> Add BetterToken as an OpenAI-compatible provider in Zed, configure the Base URL, API Key, and model, and keep the key in the system keychain.

Add an OpenAI-compatible provider in Zed **Agent Settings**, then enter the BetterToken API Key, Base URL, and Model ID. Zed stores keys saved through this screen in the system keychain instead of `settings.json`.

## Key settings

| Field    | Value                       |
| -------- | --------------------------- |
| Provider | `BetterToken`               |
| API Key  | `YOUR_API_KEY`              |
| Base URL | `https://bettertoken.ai/v1` |
| Model    | `YOUR_MODEL_ID`             |

## Prerequisites

* Install the current version of [Zed](https://zed.dev/docs)
* <a href={"https://bettertoken.ai/register"}>Create a BetterToken API Key</a>
* Copy `YOUR_MODEL_ID` from the <a href={"https://bettertoken.ai/pricing"}>model plaza</a>

## Install

Install or update to the current version from the [Zed website](https://zed.dev). Start Zed, then use the steps below to open Agent settings.

## Manual setup

<Steps>
  <Step title="Add an OpenAI-compatible provider">
    Click **Add Provider**, choose **OpenAI Compatible**, and enter `BetterToken` as the Provider Name.
  </Step>

  <Step title="Enter the connection settings">
    | Field    | Value                       |
    | -------- | --------------------------- |
    | API URL  | `https://bettertoken.ai/v1` |
    | API Key  | `YOUR_API_KEY`              |
    | Model ID | `YOUR_MODEL_ID`             |

    Enter only the Base URL. Zed constructs the Chat Completions endpoint.
  </Step>

  <Step title="Save the API Key">
    Save the provider in Zed settings. Zed stores the API Key in the local system keychain and does not write it to `settings.json`.
  </Step>

  <Step title="Select the model">
    Open the Agent Panel model picker and select `YOUR_MODEL_ID` under `BetterToken`.
  </Step>
</Steps>

<Warning>
  Do not place `YOUR_API_KEY` in `settings.json`, a project file, or a Git repository.
</Warning>

### Optional: declare the provider and model in `settings.json`

When you need file-managed model declarations, run `zed: open settings file`. Keep only the provider, `api_url`, and model metadata in the file:

```json theme={null}
{
  "language_models": {
    "openai_compatible": {
      "BetterToken": {
        "api_url": "https://bettertoken.ai/v1",
        "available_models": [
          {
            "name": "YOUR_MODEL_ID",
            "display_name": "YOUR_MODEL_ID",
            "max_tokens": 128000
          }
        ]
      }
    }
  }
}
```

Zed requires `max_tokens` as the model context-window declaration. Adjust it to the selected model. Enter the API Key in **Agent Settings** so the system keychain stores it.

## Verify the connection

1. Select `BetterToken / YOUR_MODEL_ID` in the Agent Panel.
2. Send a short test message.
3. A normal response without authentication or model errors confirms the setup.

Fully quit and restart Zed after changing provider or model settings.

## Switch models

Choose another BetterToken model in the Agent Panel model picker. To add a Model ID, copy the current value from the <a href={"https://bettertoken.ai/pricing"}>model plaza</a>, then update the provider settings or `available_models`.

## Common errors

| Error                   | Fix                                                                                     |
| ----------------------- | --------------------------------------------------------------------------------------- |
| `401` or `Unauthorized` | Re-enter the BetterToken API Key in Agent Settings and remove surrounding spaces.       |
| `404`                   | Use `https://bettertoken.ai/v1` as the API URL; do not append `/chat/completions`.      |
| `model not found`       | Copy `YOUR_MODEL_ID` again from the model plaza.                                        |
| Settings do not apply   | Save the provider, fully quit Zed, and reopen it.                                       |
| Zed uses an old key     | Remove any provider environment variable that overrides the keychain, then restart Zed. |

## Advanced setup

### Supported providers

| Provider | Status        |
| -------- | ------------- |
| Claude   | Not supported |
| GPT      | Manual setup  |
| Kimi     | Manual setup  |
| GLM      | Manual setup  |

<Note>Statuses apply to the BetterToken setup documented on this page.</Note>

<Accordion title="What the setup methods mean">
  * **Manual setup**: enter the API Key, Base URL, and Model.
  * **Not supported**: no verified direct setup is currently available.
</Accordion>

## Technical details

<Accordion title="Keychain, settings file, and endpoint">
  Zed calls BetterToken through an OpenAI-compatible provider. The settings screen stores the key in the system keychain; `settings.json` contains only the provider, `api_url`, and model declaration. Use `https://bettertoken.ai/v1` as the Base URL and let Zed append the Chat Completions path.
</Accordion>

### Related FAQ

* [OpenAI-compatible vs. Anthropic-compatible APIs](/en/faq/concepts/openai-compatible-vs-anthropic-compatible)
* [MCP vs API Key and Base URL](/en/faq/concepts/mcp-vs-api-key-base-url)
* [What are model\_provider, base\_url, and wire\_api?](/en/faq/codex/model-provider-base-url-wire-api)
* [Configure an OpenAI-compatible API in Cline](/en/faq/cline/openai-compatible-api)
