> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch16-model-providers-and-failover/16.3-model-catalog-and-configuration.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 16.3 Model Catalog and Configuration

> **Generated by**: Claude Opus 4.6 (initial draft) / Claude Opus 5 (`v2026.3.9` revision) **Token usage**: Input \~400,000 tokens, Output \~32,000 tokens (Chapter total) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

OpenClaw needs to know the capability parameters of each model — context window size, whether it supports reasoning, what types of input it accepts. This information comes from the **Model Catalog** and **Model Configuration File** (models.json), which together define the complete landscape of available models in the system.

## 16.3.1 Model Catalog (`src/agents/model-catalog.ts`)

The model catalog is a list of all available models discovered by the system at runtime. It is dynamically loaded through the Pi Agent SDK's `ModelRegistry`.

### Catalog Entry Type

```typescript
// src/agents/model-catalog.ts
export type ModelCatalogEntry = {
  id: string;                        // Model ID (e.g., "claude-sonnet-4-20250514")
  name: string;                      // Display name
  provider: string;                  // Provider identifier
  contextWindow?: number;            // Context window size (number of tokens)
  reasoning?: boolean;               // Whether reasoning/thinking mode is supported
  input?: Array<"text" | "image">;   // Supported input types
};
```

### Catalog Loading

```typescript
// src/agents/model-catalog.ts (simplified)
export async function loadModelCatalog(params?: {
  config?: OpenClawConfig;
  useCache?: boolean;
}): Promise<ModelCatalogEntry[]> {
  // Use Promise caching to avoid repeated loading
  if (modelCatalogPromise && params?.useCache !== false) {
    return modelCatalogPromise;
  }

  modelCatalogPromise = (async () => {
    const cfg = params?.config ?? loadConfig();
    // Ensure models.json exists
    await ensureOpenClawModelsJson(cfg);

    // Load model registry through Pi SDK
    const piSdk = await import("./pi-model-discovery.js");
    const agentDir = resolveOpenClawAgentDir();
    const authStorage = new piSdk.AuthStorage(join(agentDir, "auth.json"));
    const registry = new piSdk.ModelRegistry(authStorage, join(agentDir, "models.json"));

    // Convert to ModelCatalogEntry
    const entries = registry.getAll();
    return entries.map((entry) => ({
      id: entry.id,
      name: entry.name ?? entry.id,
      provider: entry.provider,
      contextWindow: entry.contextWindow,
      reasoning: entry.reasoning,
      input: entry.input,
    })).sort((a, b) => a.provider.localeCompare(b.provider) || a.name.localeCompare(b.name));
  })();

  return modelCatalogPromise;
}
```

Catalog loading has several important characteristics:

1. **Promise Caching** — Uses a module-level variable `modelCatalogPromise` to cache the loading result, loading only once during the entire process lifetime (unless explicitly refreshed)
2. **Dynamic Import** — Pi SDK is loaded dynamically via `import()`, avoiding introducing large dependencies when not needed
3. **Error Isolation** — Dynamic imports are placed inside `try/catch` to prevent temporary failures (such as `node_modules` being replaced during `pnpm install`) from permanently polluting the cache with a rejected Promise

## 16.3.2 Model Scanning: OpenRouter Free Model Detection

OpenClaw supports accessing hundreds of third-party models through OpenRouter. The system can automatically scan for available free models on OpenRouter and add them to the model catalog.

The model scanning flow:

1. Call OpenRouter's model list API
2. Filter for free models (pricing is 0)
3. Extract model parameters (context window, input types, etc.)
4. Merge results into local model configuration

This allows users to use free models on OpenRouter without manual configuration, lowering the barrier to entry.

## 16.3.3 Model Configuration File (`models.json`) and Provider Configuration

One data source for the model catalog is the `models.json` file in the Agent directory. This file defines the model list and connection parameters for each provider.

### Configuration Merge Strategy

OpenClaw's model configuration supports two merge modes:

```typescript
// src/agents/models-config.ts
const DEFAULT_MODE: NonNullable<ModelsConfig["mode"]> = "merge";
```

* **merge (default)** — User configuration is merged with built-in provider configuration, allowing users to add new models or override parameters of existing models
* **replace** — User configuration completely replaces built-in configuration

### Provider Configuration Merge

```typescript
// src/agents/models-config.ts (simplified)
function mergeProviderModels(implicit: ProviderConfig, explicit: ProviderConfig): ProviderConfig {
  const implicitModels = implicit.models ?? [];
  const explicitModels = explicit.models ?? [];

  // User-configured models take priority
  const seen = new Set(explicitModels.map((m) => m.id));
  const mergedModels = [
    ...explicitModels,
    ...implicitModels.filter((m) => !seen.has(m.id)),
  ];

  return { ...implicit, ...explicit, models: mergedModels };
}
```

The merge rule is "user first" — if both user and built-in configurations define the same model ID, the user's definition is used. This allows users to override parameters for specific models (such as custom base URL or context window size).

### Implicit Providers

Some providers can be used without explicit user configuration. The system automatically discovers these providers through `resolveImplicitProviders`:

```typescript
// src/agents/models-config.providers.ts (conceptual)
export function resolveImplicitProviders(cfg: OpenClawConfig): Record<string, ProviderConfig> {
  const providers: Record<string, ProviderConfig> = {};

  // If AWS credentials are detected, automatically add Bedrock provider
  const bedrock = resolveImplicitBedrockProvider(cfg);
  if (bedrock) providers["bedrock"] = bedrock;

  // If Copilot Token is detected, automatically add Copilot provider
  const copilot = resolveImplicitCopilotProvider(cfg);
  if (copilot) providers["github-copilot"] = copilot;

  return providers;
}
```

### Ensuring models.json Exists

Each time an Agent starts, the system ensures the `models.json` file exists and is up-to-date:

```typescript
// src/agents/models-config.ts (simplified)
export async function ensureOpenClawModelsJson(cfg?: OpenClawConfig, agentDir?: string) {
  const resolved = agentDir ?? resolveOpenClawAgentDir();
  const filePath = path.join(resolved, "models.json");

  // Merge implicit providers and user configuration
  const implicit = resolveImplicitProviders(cfg);
  const explicit = cfg?.models?.providers ?? {};
  const mode = cfg?.models?.mode ?? "merge";

  const providers = mode === "merge"
    ? mergeProviders({ implicit, explicit })
    : explicit;

  // Write models.json
  await fs.writeFile(filePath, JSON.stringify({ providers }, null, 2));
}
```

## 16.3.4 Synthetic Models and Special Providers

In addition to mainstream LLM providers (Anthropic, OpenAI, Google), OpenClaw supports various special providers and synthetic models.

### Special Provider List

| Provider       | API Type             | Characteristics                        |
| -------------- | -------------------- | -------------------------------------- |
| Venice         | OpenAI Compatible    | Privacy-first AI inference             |
| Chutes         | OpenAI Compatible    | Open source model hosting              |
| Z.AI           | OpenAI Compatible    | Does not support developer role        |
| OpenRouter     | OpenAI Compatible    | Unified gateway for hundreds of models |
| Bedrock        | AWS SDK              | Authenticated via AWS credentials      |
| GitHub Copilot | Proprietary Protocol | Two-stage Token authentication         |
| Qwen Portal    | Proprietary API      | Alibaba Cloud Tongyi Qianwen           |

### Provider ID Normalization

As described in Section 16.1, `normalizeProviderId` handles various provider name variants:

```
"z.ai" / "z-ai"      → "zai"
"opencode-zen"        → "opencode"
"qwen"                → "qwen-portal"
"kimi-code"           → "kimi-coding"
```

### Synthetic Models

Some "models" are actually wrappers or combinations of other models. For example:

* **Claude CLI** — Not an API model, but executed through Anthropic's command-line tool, using independent processes and stdio communication
* **Codex CLI** — OpenAI's command-line programming assistant, similar to Claude CLI's execution mode

These "CLI models" are detected through `isCliProvider` and follow a completely different execution path (`runCliAgent` rather than `runEmbeddedPiAgent`).

***

## Section Summary

1. **Model Catalog** is dynamically loaded through Pi SDK's `ModelRegistry`, containing context window, reasoning capability, and input type information for each model. The catalog uses Promise caching to avoid repeated loading.
2. **Model Scanning** can automatically discover free models on OpenRouter, reducing user configuration burden.
3. **models.json** configuration file supports two merge modes: merge and replace. User configuration can extend or override built-in provider definitions. Implicit providers (Bedrock, Copilot) can be automatically discovered.
4. **Synthetic models and special providers** are transparently integrated into the unified model selection and failover framework through provider ID normalization and API type detection.
