OpenClaw Installation & API Setup

Install OpenClaw, add a TokenHub model provider, and connect the OpenClaw Gateway to a compatible model.

What is OpenClaw?

OpenClaw is an open-source personal agent that connects messaging apps, browsers, local tools, models, and skills for ongoing workflows.

Use this OpenClaw installation and API setup guide to keep provider credentials separate from your agent configuration, select a default model, and validate requests before adding OpenClaw skills or enabling production channels. OpenClaw can run through a Gateway, Docker container, background service, or local terminal, and each environment may load credentials differently. Keep channel settings separate from provider settings, test the default model before enabling skills, and confirm long-running tool loops before connecting production messaging channels.

OpenClaw can route model requests through TokenHub's OpenAI compatible API gateway. Keep the official installation flow, then replace only the API key, Base URL, and model ID.

The TokenHub endpoint used by this guide is https://us-api.tokenhub.com/v1/chat/completions.

When to use it

Start in a small repository or test project. First ask the tool to read files, explain code, or produce a plan; only then enable edits, terminal commands, or agent automation.

Install or open the tool

Follow the official OpenClaw documentation to install or open the tool. If menus or command names differ, prefer the current official documentation.

For CLI tools, confirm the executable works before adding TokenHub credentials:

openclaw --version

Prepare TokenHub credentials

Create a TokenHub API key and choose a model from the TokenHub model list that fits this tool.

export TOKENHUB_API_KEY="sk-..."

Keep the key in your local shell, IDE secret storage, or the secure API key field of the tool. Do not commit it to the repository.

Configure TokenHub persistently

Use the tool configuration file or settings page first. This avoids the common problem where a terminal sees the environment variable but the IDE, plugin, or new window does not.

Provider values

Use the official custom provider guide for the current models.providers schema and OpenAI-compatible adapter behavior.

FieldValue
Provider IDtokenhub
Base URLhttps://us-api.tokenhub.com/v1
API KeyThe value of TOKENHUB_API_KEY
API adapteropenai-completions
Model referencetokenhub/gpt-4.1

Settings file locations

FieldValue
Gateway environment~/.openclaw/.env
Main config~/.openclaw/openclaw.json

Store the key where the managed Gateway can read it:

TOKENHUB_API_KEY=your-local-tokenhub-key

Add the custom provider to ~/.openclaw/openclaw.json:

{
  models: {
    mode: 'merge',
    providers: {
      tokenhub: {
        baseUrl: '__API_BASE_URL__/v1',
        apiKey: '${TOKENHUB_API_KEY}',
        api: 'openai-completions',
        models: [
          {
            id: 'gpt-4.1',
            name: 'TokenHub / gpt-4.1',
            reasoning: false,
            input: ['text'],
            contextWindow: 128000,
            maxTokens: 8192,
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: {
        primary: 'tokenhub/gpt-4.1',
      },
    },
  },
}

Replace the example model metadata with the actual limits and capabilities of the TokenHub model you selected. Keep the catalog id bare, then add the provider prefix only when selecting it as tokenhub/gpt-4.1.

Restart the Gateway and verify the custom provider:

openclaw gateway restart
openclaw models list --provider tokenhub
openclaw models set "tokenhub/gpt-4.1"

The API key remains in ~/.openclaw/.env so launchd, systemd, Docker, and other managed Gateway processes can read it.

If the tool separates chat, edit, apply, and fast models, use the same TokenHub model for the first test. Split models later by cost, latency, and reasoning strength.

Temporary environment variables for debugging

Use temporary variables only to confirm the key, network, and model name. After validation, move the same values into the persistent configuration above.

export TOKENHUB_API_KEY="sk-..."

Verify the connection

Test with a read-only prompt first, confirming that the model can read context without changing files. Then test edits, Apply, or agent tasks.

Read the project README and summarize it in three sentences. Do not modify any files.

After a successful prompt, check TokenHub request logs for model name, endpoint, token usage, and billing group.

Troubleshooting

SymptomFix
401 or authentication failureConfirm TOKENHUB_API_KEY is valid and saved in the same terminal, IDE, or client profile.
404 or model not foundUse a model ID that exists in your TokenHub workspace and matches the selected protocol.
Wrong endpointKeep the Base URL exactly as shown. OpenAI-compatible tools usually need /v1; Claude-compatible tools usually do not.
Request timeoutCheck network access to https://us-api.tokenhub.com, proxy settings, and workspace allowlists.
Tool uses another modelRecheck every chat, edit, apply, fast, and autocomplete model slot.

Choose a compatible OpenClaw model

WorkloadModel choiceWhy it fits
Complex coding tasksA tool-capable reasoning modelUse a model with reliable tool use, streaming, and the context length your workflow needs.
Daily implementationA balanced coding modelPrioritize reliable edits and useful latency for normal coding loops.
Background and subagent workA fast, lower-cost modelUse this for iterations, summaries, and simpler work only after validating tool use.
Browse TokenHub models and compatibility

OpenClaw installation and API FAQ

Why does OpenClaw Gateway return 401 when my terminal has an API key?

The Gateway may be started by launchd, systemd, or Docker and will not inherit the current terminal variables. Store the key in ~/.openclaw/.env and restart the Gateway.

When does the model name need the tokenhub/ prefix?

Use the bare model ID in models.providers.tokenhub.models and tokenhub/<model-id> in agents.defaults.model.primary.

Will adding TokenHub overwrite existing message channels?

No. Merge the provider fields into the existing openclaw.json and keep models.mode = "merge". Do not replace the whole configuration file.

Why can OpenClaw Gateway or Docker not read my API key?

Background services and containers may not inherit variables from the current shell. Store TOKENHUB_API_KEY in the environment file actually loaded by that process, then restart the Gateway or container.

How do I troubleshoot an OpenClaw LLM request timeout?

Confirm that TokenHub received the request, then check model availability, context size, tool-loop length, network access, and client timeout settings. Compare a short request with the failing long task.

References

This setup is based on TokenHub and official documentation, last verified on 2026-09-04.