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

> Configure Router in supported OpenAI-compatible Chat Completions tools.

<Badge color="blue">Beta</Badge>

Request a Router API key through the [Contact Us form](https://form.typeform.com/to/vZnBDhzs) before configuration. See the [Router overview](/router/overview) for the quickstart, [Models](/router/models) for key-specific model discovery, 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>
  Router is not confidential. Do not send sensitive data. During the beta,
  Router supports Chat Completions only. A tool that requires the Responses API cannot
  connect yet.
</Warning>

## Choose the correct path

| Requirement                                 | Use                                                   |
| ------------------------------------------- | ----------------------------------------------------- |
| Sensitive prompts, files, or regulated data | [Confidential API](/confidential-proxy)               |
| Broader current chat-model catalog          | Router                                                |
| OpenAI-compatible Chat Completions client   | Either path, with different credentials and endpoints |
| Anthropic Messages or Responses API client  | Router is not currently compatible                    |

The Router key is separate from the Confidential API key. Do not substitute `PREM_API_KEY` for `PREM_ROUTER_API_KEY` or reuse Confidential Proxy KEK settings with Router.

## Add 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                                                  | `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 Router API key in a GUI; use `PREM_ROUTER_API_KEY` only when the tool supports environment variables |
| Model (`model`, `modelId`, `apiModelId`, or `openAiModelId`)   | Use an exact model ID returned by `GET /v1/models` for the same API key                                         |
| Streaming                                                      | On or automatic                                                                                                 |
| Responses API                                                  | Off                                                                                                             |
| Organization or project                                        | Leave blank                                                                                                     |

Before you configure a model, call authenticated `GET /v1/models` with the
same API key. See [Models](/router/models) for the command. 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>
  Streaming requirements can differ by API key. If a model returned by `GET
      /v1/models` includes `"streaming_required": true`, enable streaming or leave
  it on automatic. 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": "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, use `prem/<model-id>` with an exact ID returned by `GET
/v1/models` for the same API key.

If the response contains either additional model, you can add the matching
entries to the `models` object:

```json theme={"system"}
{
  "deepseek-v4-flash": {
    "name": "DeepSeek V4 Flash"
  },
  "qwen-3.8-max": {
    "name": "Qwen 3.8 Max"
  }
}
```

Add only the entries returned for the active key.

## OpenClaw

Add a separate Router provider to `~/.openclaw/openclaw.json`. Keep the confidential provider under a different name if you use both:

```json theme={"system"}
{
  "models": {
    "mode": "merge",
    "providers": {
      "prem-router": {
        "baseUrl": "https://router.prem.io/v1",
        "apiKey": "${PREM_ROUTER_API_KEY}",
        "api": "openai-completions",
        "models": [
          {
            "id": "kimi-k3",
            "name": "Kimi K3 through Router",
            "reasoning": true,
            "input": ["text"],
            "contextWindow": 1000000,
            "maxTokens": 8192
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "prem-router/kimi-k3"
      }
    }
  }
}
```

The example uses `kimi-k3`. Confirm that the model appears in `GET /v1/models`
for the active key. If you select another returned model, update both the model
`id` and `agents.defaults.model.primary`. Set `contextWindow` from that model's
returned `context_length`.

Run `openclaw config validate` before starting an agent. Router does not provide enclave confidentiality for the model request, and OpenClaw's local tools remain outside the confidential runtime.

## Hermes Agent

Add a named Router provider to `~/.hermes/config.yaml`:

```yaml theme={"system"}
providers:
  prem-router:
    api: https://router.prem.io/v1
    key_env: PREM_ROUTER_API_KEY
    transport: chat_completions
    default_model: kimi-k3
    models:
      kimi-k3:
        context_length: 1000000

model:
  default: kimi-k3
  provider: custom:prem-router
  context_length: 1000000
```

The example uses `kimi-k3`. Confirm that the model appears in `GET /v1/models`
for the active key. If you select another returned model, update
`default_model`, both model IDs, and both context-length values.

Run `hermes config check`, then use `hermes --oneshot "Reply with exactly: router ok"` for the first request.

## Goose

Set Goose's built-in OpenAI provider to the Router endpoint:

```bash theme={"system"}
export GOOSE_PROVIDER="openai"
export GOOSE_MODEL="kimi-k3"
export OPENAI_API_KEY="$PREM_ROUTER_API_KEY"
export OPENAI_HOST="https://router.prem.io"
export OPENAI_BASE_PATH="v1/chat/completions"
```

The example uses `kimi-k3`. Confirm that the model appears in `GET /v1/models`
for the active key. Otherwise, set `GOOSE_MODEL` to an exact returned model ID.

Run a bounded request:

```bash theme={"system"}
GOOSE_MODE=chat goose run \
  --no-session \
  --text "Reply with exactly: router ok"
```

## 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 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` only with an exact ID returned by `GET /v1/models` for the
same API key.

If the response contains either additional model, you can add the matching
entries to the `models` array:

```json theme={"system"}
[
  {
    "id": "deepseek-v4-flash",
    "name": "DeepSeek V4 Flash"
  },
  {
    "id": "qwen-3.8-max",
    "name": "Qwen 3.8 Max"
  }
]
```

Add only the entries returned for the active key.

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