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

# Custom Providers and Coding Tools

> Add Prem Router as a custom OpenAI-compatible provider in OpenCode, Pi, and other tools.

Request a Prem Router API key through the [Contact Us form](https://form.typeform.com/to/vZnBDhzs) before configuration. See the [Prem Router overview](/router/overview) for the quickstart and [API capabilities](/router/capabilities) for tool calling and structured output.

Set your API key before you start a coding tool:

```bash theme={"system"}
export PREM_ROUTER_API_KEY="your-api-key"
```

<Warning>
  Prem Router is not confidential. Do not send sensitive data. Prem Router beta
  supports Chat Completions only. A tool that requires the Responses API cannot
  connect yet.
</Warning>

## Add Prem Router as a custom provider

In your tool, choose **Add provider**, then select **Custom**, **OpenAI-compatible**, or **OpenAI Chat Completions**. Enter these values:

| Field                                                          | Value                                                                                                                |
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| Provider name                                                  | `Prem Router`                                                                                                        |
| Provider or API type                                           | OpenAI-compatible Chat Completions                                                                                   |
| Base URL (`baseURL`, `baseUrl`, `apiBase`, or `openAiBaseUrl`) | `https://router.prem.io/v1`                                                                                          |
| Full endpoint                                                  | `https://router.prem.io/v1/chat/completions` only when the tool explicitly asks for a complete endpoint URL          |
| API key (`apiKey`, `openAiApiKey`, or Bearer token)            | Paste your Prem Router API key in a GUI; use `PREM_ROUTER_API_KEY` only when the tool supports environment variables |
| Model (`model`, `modelId`, `apiModelId`, or `openAiModelId`)   | Start with `kimi-k3`, or choose an [available model](/router/overview#available-models)                              |
| Streaming                                                      | On or automatic                                                                                                      |
| Responses API                                                  | Off                                                                                                                  |
| Organization or project                                        | Leave blank                                                                                                          |

When the field is named **Base URL** or **API base**, do not append `/chat/completions`. The final request URL should contain `/v1` exactly once. Enter `kimi-k3` without a provider prefix; `prem/kimi-k3` is only the OpenCode model selector. Select Chat Completions rather than the Responses API.

No custom headers are required when the tool has a dedicated API key field. If it only accepts custom headers, add `Authorization: Bearer <your-api-key>`. Do not enter the literal text `$PREM_ROUTER_API_KEY` in a GUI unless that tool documents environment-variable expansion.

<Note>
  `qwen-3.7-max`, `qwen-3.7-plus`, and `qwen-3.6-plus` require streaming.
  Enable streaming or leave it on automatic when using these models. OpenCode
  and Pi support streamed model responses.
</Note>

Test the custom provider outside your tool with the same connection settings:

```bash theme={"system"}
curl --silent --show-error https://router.prem.io/v1/chat/completions \
  --header "Authorization: Bearer $PREM_ROUTER_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "model": "kimi-k3",
    "messages": [
      {"role": "user", "content": "Reply with exactly: router ok"}
    ]
  }'
```

A successful response includes `"model":"kimi-k3"` and an assistant message.

## OpenCode

Create `opencode.json` in your project root:

```json theme={"system"}
{
  "$schema": "https://opencode.ai/config.json",
  "model": "prem/kimi-k3",
  "provider": {
    "prem": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Prem Router",
      "options": {
        "baseURL": "https://router.prem.io/v1",
        "apiKey": "{env:PREM_ROUTER_API_KEY}"
      },
      "models": {
        "kimi-k3": {
          "name": "Kimi K3"
        },
        "qwen-3.7-max": {
          "name": "Qwen 3.7 Max"
        },
        "qwen-3.7-plus": {
          "name": "Qwen 3.7 Plus"
        },
        "qwen-3.6-plus": {
          "name": "Qwen 3.6 Plus"
        },
        "qwen-3.5-9b": {
          "name": "Qwen 3.5 9B"
        },
        "deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro"
        }
      }
    }
  }
}
```

Start OpenCode:

```bash theme={"system"}
opencode
```

OpenCode uses `prem/kimi-k3` as its default provider and model selector. To
switch models, replace it with `prem/<model-id>` using an ID from the
[available models](/router/overview#available-models) table.

## Pi

Add this provider to `~/.pi/agent/models.json`:

```json theme={"system"}
{
  "providers": {
    "prem": {
      "baseUrl": "https://router.prem.io/v1",
      "api": "openai-completions",
      "apiKey": "$PREM_ROUTER_API_KEY",
      "compat": {
        "supportsStore": false,
        "supportsDeveloperRole": false,
        "supportsStrictMode": false,
        "maxTokensField": "max_tokens"
      },
      "models": [
        {
          "id": "kimi-k3",
          "name": "Kimi K3"
        },
        {
          "id": "qwen-3.7-max",
          "name": "Qwen 3.7 Max"
        },
        {
          "id": "qwen-3.7-plus",
          "name": "Qwen 3.7 Plus"
        },
        {
          "id": "qwen-3.6-plus",
          "name": "Qwen 3.6 Plus"
        },
        {
          "id": "qwen-3.5-9b",
          "name": "Qwen 3.5 9B"
        },
        {
          "id": "deepseek-v4-pro",
          "name": "DeepSeek V4 Pro"
        }
      ]
    }
  }
}
```

Start Pi with Prem Router:

```bash theme={"system"}
pi --provider prem --model kimi-k3
```

Run a non-interactive test:

```bash theme={"system"}
pi -p --provider prem --model kimi-k3 \
  "Reply with exactly: router ok"
```

Replace `kimi-k3` with any ID from the [available models](/router/overview#available-models) table.

`supportsStrictMode` controls Pi function-tool metadata. It does not disable JSON Schema response formatting.

## Codex

Codex is not supported in the current Prem Router beta. Current Codex releases require the Responses API.

## Other custom-provider tools

Follow [Add Prem Router as a custom provider](#add-prem-router-as-a-custom-provider) and use the same base URL, API key, and model ID.

You can use the same settings with Cline, Roo Code, and Continue if they support a custom Chat Completions endpoint.
