New to OpenClaw plugins? Read Getting Started
first for package structure and manifest setup.
Walkthrough
Package and manifest
Step 1: Package and manifest
setup.providers[].envVars lets OpenClaw detect credentials without
loading your plugin runtime. Add providerAuthAliases when a provider
variant should reuse another provider id’s auth. modelSupport is
optional and lets OpenClaw auto-load your provider plugin from shorthand
model ids like acme-large before runtime hooks exist. openclaw.compat
and openclaw.build in package.json are required for ClawHub
publishing (openclaw.compat.pluginApi and openclaw.build.openclawVersion
are the two required fields; minGatewayVersion falls back to
openclaw.install.minHostVersion when omitted).Register the provider
A minimal text provider needs an Use
id, label, auth, and catalog.
catalog is the provider-owned runtime/config hook; it can call live
vendor APIs and returns models.providers entries.index.ts
registerModelCatalogProvider is the newer control-plane catalog surface
for list/help/picker UI, covering text, voice, image_generation,
video_generation, and music_generation rows. Keep vendor endpoint
calls and response mapping in the plugin; OpenClaw owns the shared row
shape, source labels, and help rendering.That is a working provider. Users can now run
openclaw onboard --acme-ai-api-key <key> and select
acme-ai/acme-large as their model.Live model discovery
If your provider exposes a/models-style API, keep the provider-specific
endpoint and row projection in your plugin and use
openclaw/plugin-sdk/provider-catalog-live-runtime for the shared fetch
lifecycle. The helper gives you guarded HTTP fetches, provider-auth headers,
structured HTTP errors, TTL caching, and static fallback behavior without
putting provider policy in OpenClaw core.Use buildLiveModelProviderConfig when the live API only tells you which
provider-owned static catalog rows are currently available:index.ts
getCachedLiveProviderModelRows when the provider API returns richer
metadata and the plugin needs to project rows into OpenClaw model
definitions itself:index.ts
run should stay auth-gated and return null when no usable credential is
available. Keep an offline staticRun or static fallback so setup, docs,
tests, and picker surfaces do not depend on live network access. Use a TTL
appropriate for model-list freshness, avoid request-time filesystem polling,
and pass a provider-specific readRows / readModelId only when the
upstream response is not an OpenAI-compatible { data: [{ id, object }] }
shape.If the upstream provider uses different control tokens than OpenClaw, add a
small bidirectional text transform instead of replacing the stream path:input rewrites the final system prompt and text message content before
transport. output rewrites assistant text deltas and final text before
OpenClaw parses its own control markers or channel delivery.For bundled providers that only register one text provider with API-key
auth plus a single catalog-backed runtime, prefer the narrower
defineSingleProviderPluginEntry(...) helper:buildProvider is the live catalog path used when OpenClaw can resolve real
provider auth. It may perform provider-specific discovery. Use
buildStaticProvider only for offline rows that are safe to show before auth
is configured; it must not require credentials or make network requests.
OpenClaw’s models list --all display currently executes static catalogs
only for bundled provider plugins, with an empty config, empty env, and no
agent/workspace paths.If your auth flow also needs to patch 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.The live discovery examples above cover /models-style provider APIs. Keep
that discovery inside catalog.run, gated on usable auth, and keep
staticRun network-free for offline catalog generation.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:
Available stream families today:
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 | Bundled examples |
|---|---|---|
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 | moonshot, ollama, xai, zai |
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 | amazon-bedrock |
native-anthropic-by-model | Same Claude-by-model policy as anthropic-by-model, plus tool-call-id sanitation and native Anthropic tool-use id preservation for transports that must keep vendor-native ids | anthropic-vertex, clawrouter |
google-gemini | Native Gemini replay policy plus bootstrap replay sanitation. The shared family keeps the text-output Gemini CLI on tagged reasoning; the direct google provider overrides resolveReasoningOutputMode to native because Gemini API thinking arrives as native thought parts. | google, google-gemini-cli |
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 | openrouter, kilocode, opencode, opencode-go |
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 | minimax |
| Family | What it wires in | Bundled examples |
|---|---|---|
google-thinking | Gemini thinking payload normalization on the shared stream path | google, google-gemini-cli |
kilocode-thinking | Kilo reasoning wrapper on the shared proxy stream path, with kilo/auto and unsupported proxy reasoning ids skipping injected thinking | kilocode |
moonshot-thinking | Moonshot binary native-thinking payload mapping from config + /think level | moonshot |
minimax-fast-mode | MiniMax fast-mode model rewrite on the shared stream path | minimax, minimax-portal |
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 | openai |
openrouter-thinking | OpenRouter reasoning wrapper for proxy routes, with unsupported-model/auto skips handled centrally | openrouter |
tool-stream-default-on | Default-on tool_stream wrapper for providers like Z.AI that want tool streaming unless explicitly disabled | zai |
SDK seams powering the family builders
SDK seams powering the family builders
Each family builder is composed from lower-level public helpers exported from the same package, which you can reach for when a provider needs to go off the common pattern:
openclaw/plugin-sdk/provider-model-shared-ProviderReplayFamily,buildProviderReplayFamilyHooks(...), and the raw replay builders (buildOpenAICompatibleReplayPolicy,buildAnthropicReplayPolicyForModel,buildGoogleGeminiReplayPolicy,buildHybridAnthropicOrOpenAIReplayPolicy). Also exports Gemini replay helpers (sanitizeGoogleGeminiReplayHistory,resolveTaggedReasoningOutputMode) and endpoint/model helpers (resolveProviderEndpoint,normalizeProviderId,normalizeGooglePreviewModelId).openclaw/plugin-sdk/provider-stream-ProviderStreamFamily,buildProviderStreamFamilyHooks(...),composeProviderStreamWrappers(...), plus the shared OpenAI/Codex wrappers (createOpenAIAttributionHeadersWrapper,createOpenAIFastModeWrapper,createOpenAIServiceTierWrapper,createOpenAIResponsesContextManagementWrapper,createCodexNativeWebSearchWrapper), DeepSeek V4 OpenAI-compatible wrapper (createDeepSeekV4OpenAICompatibleThinkingWrapper), Anthropic Messages thinking prefill cleanup (createAnthropicThinkingPrefillPayloadWrapper), plain-text tool-call compat (createPlainTextToolCallCompatWrapper), and shared proxy/provider wrappers (createOpenRouterWrapper,createToolStreamWrapper,createMinimaxFastModeWrapper).openclaw/plugin-sdk/provider-stream-shared- lightweight payload and event wrappers for hot provider paths, includingcreateOpenAICompatibleCompletionsThinkingOffWrapper,createPayloadPatchStreamWrapper,createPlainTextToolCallCompatWrapper,normalizeOpenAICompatibleReasoningPayload(...), andsetQwenChatTemplateThinking(...).openclaw/plugin-sdk/provider-tools-ProviderToolCompatFamily,buildProviderToolCompatFamilyHooks("deepseek" | "gemini" | "openai"), and underlying provider schema helpers.
native
reasoning output so OpenClaw consumes native thought parts without adding
<think> / <final> prompt directives. Text-only Gemini CLI-style
backends that parse a final JSON/text response can keep the shared
google-gemini tagged contract.Some stream helpers stay provider-local on purpose. @openclaw/anthropic-provider keeps wrapAnthropicProviderStream, resolveAnthropicBetas, resolveAnthropicFastMode, resolveAnthropicServiceTier, and the lower-level Anthropic wrapper builders in its own public api.ts / contract-api.ts seam because they encode Claude OAuth beta handling and context1m gating. The xAI plugin similarly keeps native xAI Responses shaping in its own wrapStreamFn (/fast aliases, default tool_stream, unsupported strict-tool cleanup, xAI-specific reasoning-payload removal).The same package-root pattern also backs @openclaw/openai-provider (provider builders, default-model helpers, realtime provider builders) and @openclaw/openrouter-provider (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:
Common provider hooks
Common provider hooks
OpenClaw calls hooks in roughly this order for model/provider plugins.
Most providers only use 2-3. This is not the full
Runtime fallback notes:
ProviderPlugin
contract - see Internals: Provider Runtime
Hooks for the
complete, currently-accurate hook list and fallback notes.
Compatibility-only provider fields that OpenClaw no longer calls, such as
ProviderPlugin.capabilities and suppressBuiltInModel, are not listed
here.| Hook | When to use |
|---|---|
catalog | Model catalog or base URL defaults |
applyConfigDefaults | Provider-owned global defaults during config materialization |
normalizeModelId | Legacy/preview model-id alias cleanup before lookup |
normalizeTransport | Provider-family api / baseUrl cleanup before generic model assembly |
normalizeConfig | Normalize models.providers.<id> config |
applyNativeStreamingUsageCompat | Native streaming-usage compat rewrites for config providers |
resolveConfigApiKey | Provider-owned env-marker auth resolution |
resolveSyntheticAuth | Local/self-hosted or config-backed synthetic auth |
resolveExternalAuthProfiles | Overlay provider-owned external auth profiles for CLI/app-managed credentials |
shouldDeferSyntheticProfileAuth | Lower synthetic stored-profile placeholders behind env/config auth |
resolveDynamicModel | Accept arbitrary upstream model IDs |
prepareDynamicModel | Async metadata fetch before resolving |
normalizeResolvedModel | Transport rewrites before the runner |
normalizeToolSchemas | Provider-owned tool-schema cleanup before registration |
inspectToolSchemas | Provider-owned tool-schema diagnostics |
resolveReasoningOutputMode | Tagged vs native reasoning-output contract |
prepareExtraParams | Default request params |
createStreamFn | Fully custom StreamFn transport |
wrapStreamFn | Custom headers/body wrappers on the normal stream path |
resolveTransportTurnState | Native per-turn headers/metadata |
resolveWebSocketSessionPolicy | Native WS session headers/cool-down |
formatApiKey | Custom runtime token shape |
refreshOAuth | Custom OAuth refresh |
buildAuthDoctorHint | Auth repair guidance |
matchesContextOverflowError | Provider-owned overflow detection |
classifyFailoverReason | Provider-owned rate-limit/overload classification |
isCacheTtlEligible | Prompt cache TTL gating |
buildMissingAuthMessage | Custom missing-auth hint |
augmentModelCatalog | Synthetic forward-compat rows (deprecated - prefer registerModelCatalogProvider) |
resolveThinkingProfile | Model-specific /think option set |
isBinaryThinking | Binary thinking on/off compatibility (deprecated - prefer resolveThinkingProfile) |
supportsXHighThinking | xhigh reasoning support compatibility (deprecated - prefer resolveThinkingProfile) |
resolveDefaultThinkingLevel | Default /think policy compatibility (deprecated - prefer resolveThinkingProfile) |
isModernModelRef | Live/smoke model matching |
prepareRuntimeAuth | Token exchange before inference |
resolveUsageAuth | Custom usage credential parsing |
fetchUsageSnapshot | Custom usage endpoint |
createEmbeddingProvider | Provider-owned embedding adapter for memory/search |
buildReplayPolicy | Custom transcript replay/compaction policy |
sanitizeReplayHistory | Provider-specific replay rewrites after generic cleanup |
validateReplayTurns | Strict replay-turn validation before the embedded runner |
onModelSelected | Post-selection callback (e.g. telemetry) |
normalizeConfigresolves one owning plugin per provider id (bundled providers first, then the matched runtime plugin) and calls only that hook - there is no scan across other providers. Google’s ownnormalizeConfighook is what normalizesgoogle/google-vertex/google-antigravityconfig entries; it is not a separate core fallback.resolveConfigApiKeyuses the provider hook when exposed. Amazon Bedrock keeps AWS env-marker resolution in its provider plugin; runtime auth itself still uses the AWS SDK default chain when configured withauth: "aws-sdk".resolveThinkingProfile(ctx)receives the selectedprovider,modelId, optional mergedreasoningcatalog hint, and optional merged modelcompatfacts. Usecompatonly to select the provider’s thinking UI/profile.resolveSystemPromptContributionlets a provider inject cache-aware system-prompt guidance for a model family. Prefer it over the legacy plugin-widebefore_prompt_buildhook when the behavior belongs to one provider/model family and should preserve the stable/dynamic cache split.
Add extra capabilities (optional)
Step 5: Add extra capabilities
A provider plugin can register embeddings, 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 - the recommended pattern for company plugins (one plugin per vendor). See Internals: Capability Ownership.Register each capability insideregister(api) alongside your existing
api.registerProvider(...) call. Pick only the tabs you need:- Speech (TTS)
- Realtime transcription
- Realtime voice
- Media understanding
- Embeddings
- Image and video generation
- Web fetch and search
assertOkOrThrowProviderError(...) for provider HTTP failures so
plugins share capped error-body reads, JSON error parsing, and
request-id suffixes.Test
Step 6: Test
src/provider.test.ts
Publish to ClawHub
Provider plugins publish the same way as any other external code plugin:clawhub skill publish <path> is a different command for publishing a skill
folder, not a plugin package - do not use it here.
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