Building Provider Plugins
This guide walks through building a provider plugin that adds a model provider (LLM) to OpenClaw. By the end you will have a provider with a model catalog, API key auth, and dynamic model resolution.If you have not built any OpenClaw plugin before, read
Getting Started first for the basic package
structure and manifest setup.
Walkthrough
Package and manifest
providerAuthEnvVars so OpenClaw can detect
credentials without loading your plugin runtime. modelSupport is optional
and lets OpenClaw auto-load your provider plugin from shorthand model ids
like acme-large before runtime hooks exist. If you publish the
provider on ClawHub, those openclaw.compat and openclaw.build fields
are required in package.json.Register the provider
A minimal provider needs an That is a working provider. Users can now
If your auth flow also needs to patch
id, label, auth, and catalog:index.ts
openclaw onboard --acme-ai-api-key <key> and select
acme-ai/acme-large as their model.For bundled providers that only register one text provider with API-key
auth plus a single catalog-backed runtime, prefer the narrower
defineSingleProviderPluginEntry(...) helper:models.providers.*, aliases, and
the agent default model during onboarding, use the preset helpers from
openclaw/plugin-sdk/provider-onboard. The narrowest helpers are
createDefaultModelPresetAppliers(...),
createDefaultModelsPresetAppliers(...), and
createModelCatalogPresetAppliers(...).When a provider’s native endpoint supports streamed usage blocks on the
normal openai-completions transport, prefer the shared catalog helpers in
openclaw/plugin-sdk/provider-catalog-shared instead of hardcoding
provider-id checks. supportsNativeStreamingUsageCompat(...) and
applyProviderNativeStreamingUsageCompat(...) detect support from the
endpoint capability map, so native Moonshot/DashScope-style endpoints still
opt in even when a plugin is using a custom provider id.Add dynamic model resolution
If your provider accepts arbitrary model IDs (like a proxy or router),
add If resolving requires a network call, use
resolveDynamicModel:prepareDynamicModel for async
warm-up — resolveDynamicModel runs again after it completes.Add runtime hooks (as needed)
Most providers only need Available replay families today:
Real bundled examples:
Real bundled examples:
catalog + resolveDynamicModel. Add hooks
incrementally as your provider requires them.Shared helper builders now cover the most common replay/tool-compat
families, so plugins usually do not need to hand-wire each hook one by one:| Family | What it wires in |
|---|---|
openai-compatible | Shared OpenAI-style replay policy for OpenAI-compatible transports, including tool-call-id sanitation, assistant-first ordering fixes, and generic Gemini-turn validation where the transport needs it |
anthropic-by-model | Claude-aware replay policy chosen by modelId, so Anthropic-message transports only get Claude-specific thinking-block cleanup when the resolved model is actually a Claude id |
google-gemini | Native Gemini replay policy plus bootstrap replay sanitation and tagged reasoning-output mode |
passthrough-gemini | Gemini thought-signature sanitation for Gemini models running through OpenAI-compatible proxy transports; does not enable native Gemini replay validation or bootstrap rewrites |
hybrid-anthropic-openai | Hybrid policy for providers that mix Anthropic-message and OpenAI-compatible model surfaces in one plugin; optional Claude-only thinking-block dropping stays scoped to the Anthropic side |
googleandgoogle-gemini-cli:google-geminiopenrouter,kilocode,opencode, andopencode-go:passthrough-geminiamazon-bedrockandanthropic-vertex:anthropic-by-modelminimax:hybrid-anthropic-openaimoonshot,ollama,xai, andzai:openai-compatible
| Family | What it wires in |
|---|---|
google-thinking | Gemini thinking payload normalization on the shared stream path |
kilocode-thinking | Kilo reasoning wrapper on the shared proxy stream path, with kilo/auto and unsupported proxy reasoning ids skipping injected thinking |
moonshot-thinking | Moonshot binary native-thinking payload mapping from config + /think level |
minimax-fast-mode | MiniMax fast-mode model rewrite on the shared stream path |
openai-responses-defaults | Shared native OpenAI/Codex Responses wrappers: attribution headers, /fast/serviceTier, text verbosity, native Codex web search, reasoning-compat payload shaping, and Responses context management |
openrouter-thinking | OpenRouter reasoning wrapper for proxy routes, with unsupported-model/auto skips handled centrally |
tool-stream-default-on | Default-on tool_stream wrapper for providers like Z.AI that want tool streaming unless explicitly disabled |
googleandgoogle-gemini-cli:google-thinkingkilocode:kilocode-thinkingmoonshot:moonshot-thinkingminimaxandminimax-portal:minimax-fast-modeopenaiandopenai-codex:openai-responses-defaultsopenrouter:openrouter-thinkingzai:tool-stream-default-on
openclaw/plugin-sdk/provider-model-shared also exports the replay-family
enum plus the shared helpers those families are built from. Common public
exports include:ProviderReplayFamilybuildProviderReplayFamilyHooks(...)- shared replay builders such as
buildOpenAICompatibleReplayPolicy(...),buildAnthropicReplayPolicyForModel(...),buildGoogleGeminiReplayPolicy(...), andbuildHybridAnthropicOrOpenAIReplayPolicy(...) - Gemini replay helpers such as
sanitizeGoogleGeminiReplayHistory(...)andresolveTaggedReasoningOutputMode() - endpoint/model helpers such as
resolveProviderEndpoint(...),normalizeProviderId(...),normalizeGooglePreviewModelId(...), andnormalizeNativeXaiModelId(...)
openclaw/plugin-sdk/provider-stream exposes both the family builder and
the public wrapper helpers those families reuse. Common public exports
include:ProviderStreamFamilybuildProviderStreamFamilyHooks(...)composeProviderStreamWrappers(...)- shared OpenAI/Codex wrappers such as
createOpenAIAttributionHeadersWrapper(...),createOpenAIFastModeWrapper(...),createOpenAIServiceTierWrapper(...),createOpenAIResponsesContextManagementWrapper(...), andcreateCodexNativeWebSearchWrapper(...) - shared proxy/provider wrappers such as
createOpenRouterWrapper(...),createToolStreamWrapper(...), andcreateMinimaxFastModeWrapper(...)
@openclaw/anthropic-provider exports
wrapAnthropicProviderStream, resolveAnthropicBetas,
resolveAnthropicFastMode, resolveAnthropicServiceTier, and the
lower-level Anthropic wrapper builders from its public api.ts /
contract-api.ts seam. Those helpers remain Anthropic-specific because
they also encode Claude OAuth beta handling and context1m gating.Other bundled providers also keep transport-specific wrappers local when
the behavior is not shared cleanly across families. Current example: the
bundled xAI plugin keeps native xAI Responses shaping in its own
wrapStreamFn, including /fast alias rewrites, default tool_stream,
unsupported strict-tool cleanup, and xAI-specific reasoning-payload
removal.openclaw/plugin-sdk/provider-tools currently exposes one shared
tool-schema family plus shared schema/compat helpers:ProviderToolCompatFamilydocuments the shared family inventory today.buildProviderToolCompatFamilyHooks("gemini")wires Gemini schema cleanup + diagnostics for providers that need Gemini-safe tool schemas.normalizeGeminiToolSchemas(...)andinspectGeminiToolSchemas(...)are the underlying public Gemini schema helpers.resolveXaiModelCompatPatch()returns the bundled xAI compat patch:toolSchemaProfile: "xai", unsupported schema keywords, nativeweb_searchsupport, and HTML-entity tool-call argument decoding.applyXaiModelCompat(model)applies that same xAI compat patch to a resolved model before it reaches the runner.
normalizeResolvedModel plus
contributeResolvedModelCompat to keep that compat metadata owned by the
provider instead of hardcoding xAI rules in core.The same package-root pattern also backs other bundled providers:@openclaw/openai-provider:api.tsexports provider builders, default-model helpers, and realtime provider builders@openclaw/openrouter-provider:api.tsexports the provider builder plus onboarding/config helpers
- Token exchange
- Custom headers
- Native transport identity
- Usage and billing
For providers that need a token exchange before each inference call:
All available provider hooks
All available provider hooks
OpenClaw calls hooks in this order. Most providers only use 2-3:
Runtime fallback notes:
| # | Hook | When to use |
|---|---|---|
| 1 | catalog | Model catalog or base URL defaults |
| 2 | applyConfigDefaults | Provider-owned global defaults during config materialization |
| 3 | normalizeModelId | Legacy/preview model-id alias cleanup before lookup |
| 4 | normalizeTransport | Provider-family api / baseUrl cleanup before generic model assembly |
| 5 | normalizeConfig | Normalize models.providers.<id> config |
| 6 | applyNativeStreamingUsageCompat | Native streaming-usage compat rewrites for config providers |
| 7 | resolveConfigApiKey | Provider-owned env-marker auth resolution |
| 8 | resolveSyntheticAuth | Local/self-hosted or config-backed synthetic auth |
| 9 | shouldDeferSyntheticProfileAuth | Lower synthetic stored-profile placeholders behind env/config auth |
| 10 | resolveDynamicModel | Accept arbitrary upstream model IDs |
| 11 | prepareDynamicModel | Async metadata fetch before resolving |
| 12 | normalizeResolvedModel | Transport rewrites before the runner |
-
normalizeConfigchecks the matched provider first, then other hook-capable provider plugins until one actually changes the config. If no provider hook rewrites a supported Google-family config entry, the bundled Google config normalizer still applies. -
resolveConfigApiKeyuses the provider hook when exposed. The bundledamazon-bedrockpath also has a built-in AWS env-marker resolver here, even though Bedrock runtime auth itself still uses the AWS SDK default chain. | 13 |contributeResolvedModelCompat| Compat flags for vendor models behind another compatible transport | | 14 |capabilities| Legacy static capability bag; compatibility only | | 15 |normalizeToolSchemas| Provider-owned tool-schema cleanup before registration | | 16 |inspectToolSchemas| Provider-owned tool-schema diagnostics | | 17 |resolveReasoningOutputMode| Tagged vs native reasoning-output contract | | 18 |prepareExtraParams| Default request params | | 19 |createStreamFn| Fully custom StreamFn transport | | 20 |wrapStreamFn| Custom headers/body wrappers on the normal stream path | | 21 |resolveTransportTurnState| Native per-turn headers/metadata | | 22 |resolveWebSocketSessionPolicy| Native WS session headers/cool-down | | 23 |formatApiKey| Custom runtime token shape | | 24 |refreshOAuth| Custom OAuth refresh | | 25 |buildAuthDoctorHint| Auth repair guidance | | 26 |matchesContextOverflowError| Provider-owned overflow detection | | 27 |classifyFailoverReason| Provider-owned rate-limit/overload classification | | 28 |isCacheTtlEligible| Prompt cache TTL gating | | 29 |buildMissingAuthMessage| Custom missing-auth hint | | 30 |suppressBuiltInModel| Hide stale upstream rows | | 31 |augmentModelCatalog| Synthetic forward-compat rows | | 32 |isBinaryThinking| Binary thinking on/off | | 33 |supportsXHighThinking|xhighreasoning support | | 34 |resolveDefaultThinkingLevel| Default/thinkpolicy | | 35 |isModernModelRef| Live/smoke model matching | | 36 |prepareRuntimeAuth| Token exchange before inference | | 37 |resolveUsageAuth| Custom usage credential parsing | | 38 |fetchUsageSnapshot| Custom usage endpoint | | 39 |createEmbeddingProvider| Provider-owned embedding adapter for memory/search | | 40 |buildReplayPolicy| Custom transcript replay/compaction policy | | 41 |sanitizeReplayHistory| Provider-specific replay rewrites after generic cleanup | | 42 |validateReplayTurns| Strict replay-turn validation before the embedded runner | | 43 |onModelSelected| Post-selection callback (e.g. telemetry) | For detailed descriptions and real-world examples, see Internals: Provider Runtime Hooks.
Add extra capabilities (optional)
A provider plugin can register speech, realtime transcription, realtime
voice, media understanding, image generation, video generation, web fetch,
and web search alongside text inference:OpenClaw classifies this as a hybrid-capability plugin. This is the
recommended pattern for company plugins (one plugin per vendor). See
Internals: Capability Ownership.
Publish to ClawHub
Provider plugins publish the same way as any other external code plugin:clawhub package publish.
File structure
Catalog order reference
catalog.order controls when your catalog merges relative to built-in
providers:
| Order | When | Use case |
|---|---|---|
simple | First pass | Plain API-key providers |
profile | After simple | Providers gated on auth profiles |
paired | After profile | Synthesize multiple related entries |
late | Last pass | Override existing providers (wins on collision) |
Next steps
- Channel Plugins — if your plugin also provides a channel
- SDK Runtime —
api.runtimehelpers (TTS, search, subagent) - SDK Overview — full subpath import reference
- Plugin Internals — hook details and bundled examples