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

# OpenClaw

> Connect AnyAPI as a custom provider in OpenClaw for multi-model AI agent workflows

# OpenClaw

[OpenClaw](https://github.com/openclaw/openclaw) is an AI coding agent with support for custom OpenAI-compatible providers, fallback chains, and messaging gateway mode (Discord, Slack, Telegram, etc.).

<Info>
  AnyAPI is not a bundled provider in OpenClaw. You wire it in as a **custom OpenAI-compatible provider** under `models.providers`. Once registered, OpenClaw addresses models as `anyapi/<vendor>/<model>` (your provider ID prefix + the upstream model ID).
</Info>

<Info>
  OpenClaw uses **JSON5** at `~/.openclaw/openclaw.json` — unquoted keys, trailing commas, and `//` comments are all valid.
</Info>

## Quick Start

The fastest path is the non-interactive onboarding wizard:

```bash theme={"system"}
ANYAPI_API_KEY='your-key-here' openclaw onboard --non-interactive \
  --auth-choice custom-api-key \
  --custom-base-url "https://api.anyapi.ai/v1" \
  --custom-model-id "openai/gpt-4o" \
  --secret-input-mode ref \
  --custom-compatibility openai \
  --accept-risk
```

This registers a custom provider with `baseUrl: https://api.anyapi.ai/v1`, stores the API key as an env reference, and sets `openai/gpt-4o` as the default model.

Then start OpenClaw:

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

<Info>
  Prefer interactive setup? Run `openclaw onboard` without flags to walk through provider, URL, key, and model selection step by step.
</Info>

## Manual Configuration

Edit `~/.openclaw/openclaw.json` directly for full control:

```json5 theme={"system"}
{
  env: {
    ANYAPI_API_KEY: "your-key-here",
  },
  models: {
    providers: {
      anyapi: {
        baseUrl: "https://api.anyapi.ai/v1",
        apiKey: {
          source: "env",
          provider: "default",
          id: "ANYAPI_API_KEY",
        },
        api: "openai-completions",
        models: [
          { id: "openai/gpt-4o" },
          { id: "openai/gpt-4o-mini" },
          { id: "anthropic/claude-sonnet-4.6" },
          { id: "google/gemini-2.5-pro" },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: {
        primary: "anyapi/openai/gpt-4o",
        fallbacks: [
          "anyapi/anthropic/claude-sonnet-4.6",
          "anyapi/openai/gpt-4o-mini",
        ],
      },
    },
  },
}
```

Restart OpenClaw for changes to take effect:

```bash theme={"system"}
openclaw gateway restart   # if running as gateway daemon
```

## Model Reference Format

OpenClaw composes model refs as `<provider-id>/<upstream-model-id>`. With provider ID `anyapi`:

* `anyapi/openai/gpt-4o` — correct
* `anyapi/anthropic/claude-sonnet-4.6` — correct
* `openai/gpt-4o` — won't route through the `anyapi` provider
* `gpt-4o` — missing vendor prefix, AnyAPI returns HTTP 400

The `id` field inside `models.providers.anyapi.models[]` is the **upstream** ID sent to AnyAPI (e.g. `openai/gpt-4o`). The `anyapi/` prefix is added by OpenClaw based on your provider ID.

Browse all available models at [anyapi.ai/ai-models](https://anyapi.ai/ai-models) or query the API:

```bash theme={"system"}
curl -sS -H "Authorization: Bearer $ANYAPI_API_KEY" \
  https://api.anyapi.ai/v1/models | jq -r '.data[].id'
```

## Configuration Examples

<Tabs>
  <Tab title="GPT-4o">
    ```json5 theme={"system"}
    {
      models: {
        providers: {
          anyapi: {
            baseUrl: "https://api.anyapi.ai/v1",
            apiKey: { source: "env", provider: "default", id: "ANYAPI_API_KEY" },
            models: [{ id: "openai/gpt-4o" }],
          },
        },
      },
      agents: {
        defaults: {
          model: { primary: "anyapi/openai/gpt-4o" },
        },
      },
    }
    ```
  </Tab>

  <Tab title="Claude Sonnet">
    ```json5 theme={"system"}
    {
      models: {
        providers: {
          anyapi: {
            baseUrl: "https://api.anyapi.ai/v1",
            apiKey: { source: "env", provider: "default", id: "ANYAPI_API_KEY" },
            models: [{ id: "anthropic/claude-sonnet-4.6" }],
          },
        },
      },
      agents: {
        defaults: {
          model: { primary: "anyapi/anthropic/claude-sonnet-4.6" },
        },
      },
    }
    ```
  </Tab>

  <Tab title="Multi-model with fallbacks">
    ```json5 theme={"system"}
    {
      models: {
        providers: {
          anyapi: {
            baseUrl: "https://api.anyapi.ai/v1",
            apiKey: { source: "env", provider: "default", id: "ANYAPI_API_KEY" },
            models: [
              { id: "openai/gpt-4o" },
              { id: "anthropic/claude-sonnet-4.6" },
              { id: "openai/gpt-4o-mini" },
            ],
          },
        },
      },
      agents: {
        defaults: {
          model: {
            primary: "anyapi/openai/gpt-4o",
            fallbacks: [
              "anyapi/anthropic/claude-sonnet-4.6",
              "anyapi/openai/gpt-4o-mini",
            ],
            timeoutMs: 120000,
          },
        },
      },
    }
    ```
  </Tab>
</Tabs>

## Advanced Configuration

<AccordionGroup>
  <Accordion title="Per-model parameters">
    Set per-model defaults via `agents.defaults.models`:

    ```json5 theme={"system"}
    {
      agents: {
        defaults: {
          models: {
            "anyapi/openai/gpt-4o": {
              params: {
                temperature: 0.7,
                max_tokens: 4096,
              },
            },
            "anyapi/openai/o3": {
              params: {
                max_completion_tokens: 8192,  // o-series uses max_completion_tokens
              },
            },
          },
        },
      },
    }
    ```
  </Accordion>

  <Accordion title="Model metadata (context window, image input)">
    Enrich model entries to enable image inputs and set context windows:

    ```json5 theme={"system"}
    models: [
      {
        id: "openai/gpt-4o",
        name: "GPT-4o (via AnyAPI)",
        input: ["text", "image"],
        contextWindow: 128000,
        maxTokens: 16384,
      },
      {
        id: "google/gemini-2.5-pro",
        input: ["text", "image"],
        contextWindow: 1000000,
        reasoning: true,
      },
    ]
    ```

    OpenClaw won't infer image capability for custom providers automatically — declare it explicitly.
  </Accordion>

  <Accordion title="Custom headers">
    Add request headers for tracking:

    ```json5 theme={"system"}
    anyapi: {
      baseUrl: "https://api.anyapi.ai/v1",
      apiKey: { source: "env", provider: "default", id: "ANYAPI_API_KEY" },
      headers: {
        "X-My-App": "my-app-v1",
      },
      models: [{ id: "openai/gpt-4o" }],
    }
    ```
  </Accordion>

  <Accordion title="Auth profiles">
    For multi-account setups, OpenClaw supports auth profiles. Store a key in OS keychain:

    ```bash theme={"system"}
    openclaw models auth add --provider anyapi
    ```
  </Accordion>
</AccordionGroup>

## CLI Reference

```bash theme={"system"}
# Onboarding
openclaw onboard                          # interactive setup
openclaw onboard --non-interactive ...    # scripted setup

# Model management
openclaw models list                      # list configured models
openclaw models set anyapi/openai/gpt-4o  # set default model

# Config
openclaw config validate                  # validate config
openclaw config get models.providers.anyapi.baseUrl
openclaw config set agents.defaults.model.primary "anyapi/openai/gpt-4o"

# Gateway
openclaw gateway status
openclaw gateway restart
openclaw gateway logs
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Provider not found / config validation fails">
    OpenClaw rejects unknown keys. Use the canonical field names:

    * `baseUrl` (camelCase, not `baseURL`)
    * `apiKey` (object or `${VAR}` template, not `apiKeyEnvVar`)

    Validate with `openclaw config validate`.
  </Accordion>

  <Accordion title="No API key for provider 'anyapi'">
    The `apiKey` reference doesn't resolve.

    1. Confirm the env var is set: `echo $ANYAPI_API_KEY`
    2. Confirm the `apiKey` block points to it:
       ```json5 theme={"system"}
       apiKey: { source: "env", provider: "default", id: "ANYAPI_API_KEY" }
       ```
    3. Restart OpenClaw — env changes don't apply to a running daemon.
  </Accordion>

  <Accordion title="Authentication failed (HTTP 401)">
    Your key is invalid, expired, or revoked.

    1. Validate the key at [dash.anyapi.ai](https://dash.anyapi.ai)
    2. Test directly:
       ```bash theme={"system"}
       curl https://api.anyapi.ai/v1/chat/completions \
         -H "Content-Type: application/json" \
         -H "Authorization: Bearer $ANYAPI_API_KEY" \
         -d '{"model":"openai/gpt-4o-mini","messages":[{"role":"user","content":"test"}],"max_tokens":10}'
       ```
  </Accordion>

  <Accordion title="Model not found / Bad Request (HTTP 400)">
    The model ID is unknown or missing the vendor prefix.

    1. List the catalog: `curl -H "Authorization: Bearer $ANYAPI_API_KEY" https://api.anyapi.ai/v1/models`
    2. Use `vendor/model` form (e.g. `openai/gpt-4o`, not bare `gpt-4o`)
    3. Confirm the model is listed under `models.providers.anyapi.models[]` in your config
  </Accordion>

  <Accordion title="Base URL errors">
    Set `baseUrl` to exactly `https://api.anyapi.ai/v1` — no trailing slash, no `/chat/completions` suffix (OpenClaw appends that).
  </Accordion>

  <Accordion title="Rate limiting (HTTP 429)">
    Check usage at [dash.anyapi.ai](https://dash.anyapi.ai), upgrade your plan, or add fallbacks to spread load.
  </Accordion>
</AccordionGroup>

## Best Practices

1. **Store keys as env refs, not plaintext** — prefer `secret-input-mode ref` during onboarding
2. **Configure fallbacks** across different vendors for cross-provider resilience
3. **Set `timeoutMs` for slow models** — reasoning models like `openai/o3` can take minutes
4. **Pin model capability metadata** — declare `input: ["text", "image"]` explicitly for vision models
5. **Always use `vendor/model` format** — bare names return HTTP 400
6. **Monitor usage** at [dash.anyapi.ai](https://dash.anyapi.ai)

## Support

* **AnyAPI Dashboard**: [dash.anyapi.ai](https://dash.anyapi.ai)
* **AnyAPI Discord**: [Discord community](https://discord.gg/rJgyzGynHw)
* **AnyAPI Email**: [support@anyapi.ai](mailto:support@anyapi.ai)
* **OpenClaw Issues**: [github.com/openclaw/openclaw/issues](https://github.com/openclaw/openclaw/issues)
