Skip to content
Sign Up Free
Work and task execution

OpenClaw Setup: API Key, Base URL, and Custom Models

Configure OpenClaw models.providers, a BetterToken API Key, Base URL, OpenAI Responses or Chat Completions models, and validate the Gateway connection.

Connect OpenClaw with your BetterToken API Key, Base URL https://bettertoken.ai/v1, and your chosen Model ID. Copy the exact Model ID from the model plaza.

Key settings

FieldValue
API KeyBetterToken API Key
Base URLhttps://bettertoken.ai/v1
ModelYOUR_MODEL_ID

Prerequisites

Sign up and get a BetterToken API Key

Already have an account? Sign in, top up, then create a key in the console.

Install

macOS / Linux

Terminal window
curl -fsSL https://openclaw.ai/install.sh | bash

Windows

Terminal window
iwr -useb https://openclaw.ai/install.ps1 | iex

Command-line setup

The BetterToken Automatic setup script writes the OpenClaw configuration. It requires Node.js. If you do not pass an API Key or Model ID as an argument, the script prompts you for them.

macOS / Linux

Terminal window
curl -fsSL "https://bettertoken.ai/install-openclaw-provider.sh" | bash

Windows

Terminal window
iwr "https://bettertoken.ai/install-openclaw-provider.ps1" -OutFile "$env:TEMP\install-openclaw-provider.ps1"; powershell -ExecutionPolicy Bypass -File "$env:TEMP\install-openclaw-provider.ps1"

If you omit the model, the script lists the available text models. You can select more than one. The command you copy from the key’s Setup dialog in the workspace already includes the API Key and selected model. To skip the list and specify a model directly:

  • macOS / Linux: Replace the final bash in the command with bash -s -- --model YOUR_MODEL_ID.
  • Windows: Add -Model YOUR_MODEL_ID to the end of the command.
What the script changes and how to restore your settings
  • Configuration changes. The script runs openclaw onboard --non-interactive in custom API Key mode for each selected model. It adds BetterToken to models.providers, sets the default model to your selection, and runs openclaw config validate.
  • API selection. The script uses openai-responses for GPT, anthropic-messages for Claude, and openai-completions for other models.
  • Provider ID. The script uses bettertoken if all selected models use the same API. When they use different APIs, it uses bettertoken-responses, bettertoken-messages, and bettertoken-chat for the respective APIs. To verify the connection, use the full model reference the script prints at the end.
  • Context window. The script sets at least 256000 for GPT models and at most 128000 for other models. To use the same value for all models, set BETTERTOKEN_OPENCLAW_CONTEXT_WINDOW before running the script.
  • Credential storage. The script stores your API Key as plain text in the configuration. To use SecretRef or an environment variable, follow the manual setup below to replace it.
  • Backup and restore. Before writing, the script makes a backup in bettertoken-backups/ under the OpenClaw configuration directory. To restore, replace openclaw.json with the backup.

Next step. Run the validation and Gateway restart commands in Verify the connection. The script also prints these commands at the end.

Manual setup

Configure OpenClaw

Copy the exact Model ID from the model plaza.

The examples use an API Key placeholder for clarity. For a saved configuration, OpenClaw recommends a SecretRef or environment-variable substitution for models.providers.bettertoken.apiKey; follow the official credential guidance instead of storing a real Key in a shared file.

Responses API

{
"models": {
"mode": "merge",
"providers": {
"bettertoken": {
"baseUrl": "https://bettertoken.ai/v1",
"apiKey": "YOUR_API_KEY",
"api": "openai-responses",
"models": [
{
"id": "YOUR_MODEL_ID",
"name": "YOUR_MODEL_ID"
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "bettertoken/YOUR_MODEL_ID"
}
}
}
}

Chat Completions

{
"models": {
"mode": "merge",
"providers": {
"bettertoken": {
"baseUrl": "https://bettertoken.ai/v1",
"apiKey": "YOUR_API_KEY",
"api": "openai-completions",
"models": [
{
"id": "YOUR_MODEL_ID",
"name": "YOUR_MODEL_ID"
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "bettertoken/YOUR_MODEL_ID"
}
}
}
}

For both APIs, set baseUrl to https://bettertoken.ai/v1. OpenClaw appends the path automatically. It calls /v1/responses for openai-responses and /v1/chat/completions for openai-completions.

Verify the connection

Run:

Terminal window
openclaw config validate
openclaw gateway restart
openclaw models list
openclaw models status

The setup is active when validation passes, the Gateway restarts, and bettertoken/YOUR_MODEL_ID appears in the model list and status. If an existing session still uses an old model, start a new session and check again.

Switch models

Add the new model to models.providers.bettertoken.models, then change agents.defaults.model.primary to bettertoken/YOUR_MODEL_ID. Save, validate, and restart the Gateway.

Common errors

ErrorFix
config validate failsCheck JSON commas, quotes, and brackets.
401Copy apiKey again and remove spaces.
404Set baseUrl to https://bettertoken.ai/v1 without adding /responses or /chat/completions. Check that api matches the API you selected.
Model missingConfirm it exists in both the provider model list and agents.defaults.model.primary.
Existing session uses the old modelRun openclaw gateway restart and create a new session.

Advanced setup

Optional: manage the provider with CC Switch

To manage providers for several tools in one place, see OpenClaw setup in CC Switch.

Technical details

Responses and Chat Completions

For both APIs, set baseUrl to https://bettertoken.ai/v1. OpenClaw appends the path automatically. It calls /v1/responses for openai-responses and /v1/chat/completions for openai-completions.